Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash -eu
function error_path {
>&2 echo "Error: you must be in either /data/domains/*/ or /system/*/ to execute these commands"
exit 1
}
function systemctl_param {
first_level_path=`pwd | cut -d'/' -f2`
second_level_path=`pwd | cut -d'/' -f3`
if [ "$first_level_path" == "system" ]; then
module=`pwd | cut -d'/' -f3`
if [ -n "$module" ]; then
echo s@$module
else
error_path
fi
elif [ "$first_level_path" == "data" ] && [ "$second_level_path" == "domains" ]; then
domain=`pwd | cut -d'/' -f4`
if [ -n "$domain" ]; then
echo u@$domain
else
error_path
fi
else
error_path
fi
}
case "$1" in
start|status|enable|disable|restart|stop)
if [ -n "$(systemctl_param)" ]; then
echo "systemctl $1 $(systemctl_param)"
systemctl $1 $(systemctl_param)
fi;;
journal)
if [ -n "$(systemctl_param)" ]; then
journalctl -fu $(systemctl_param)
fi;;
ps|exec|logs)
if [ -f ./env ]; then
env $(cat ./env | xargs) docker-compose $1 ${@:2}
else
docker-compose $1 ${@:2}
fi;;
update)
if [ "$(pwd)" == "/libre.sh" ]; then
git pull
cp /libre.sh/unit-files/* /etc/systemd/system && systemctl daemon-reload
cp /libre.sh/utils/* /opt/bin/
elif [ -n "$(systemctl_param)" ]; then
git pull
docker-compose pull
fi;;
provision)
provision ${@:2};;
stats)
docker stats $(docker ps|grep -v "NAMES"|awk '{ print $NF }'|tr "\n" " ");;
*)
echo "Usage:"
echo " - start|status|enable|disable|restart|stop: command sent to systemctl."
echo " - ps|exec|logs: command sent to docker compose."
echo " - update: to update the current folder."