summaryrefslogtreecommitdiffstats
path: root/scripts/systemctl
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/systemctl')
-rwxr-xr-xscripts/systemctl59
1 files changed, 59 insertions, 0 deletions
diff --git a/scripts/systemctl b/scripts/systemctl
new file mode 100755
index 0000000..e3afe73
--- /dev/null
+++ b/scripts/systemctl
@@ -0,0 +1,59 @@
+#!/bin/bash
+
+op="$1"
+shift
+
+if [ $# -eq 0 ]; then
+ echo "No service name given" >&2
+ exit 1
+fi
+
+declare -A services
+
+services["dmsd"]="start stop restart"
+services["lighttpd"]="restart"
+services["taskmanager"]="restart"
+services["dnbd3-server"]="start stop restart"
+services["dnbd3-master-proxy"]="start stop restart"
+services["tftpd-hpa"]="start stop restart"
+services["ldadp@"]="start stop restart"
+
+one_ok=
+one_fail=
+cmpop="${op##*-}"
+for service in "$@"; do
+ ok=
+ [[ "$op" =~ ^(is-active|status|cat)$ ]] && ok=1
+ str="${service%.service}"
+ noa="${str%%@*}"
+ [[ "$noa" != "$str" ]] && str="${noa}@"
+ if [ -z "$ok" ] && [ -n "${services["$str"]}" ]; then
+ for verb in ${services["$str"]}; do
+ if [[ "$cmpop" == "$verb" ]]; then
+ ok=1
+ break
+ fi
+ done
+ fi
+ if [ -n "$ok" ]; then
+ if systemctl "$op" "$service"; then
+ one_ok=1
+ else
+ one_fail=1
+ [[ "$op" != "status" ]] && systemctl status "$service"
+ fi
+ else
+ echo "Operation '$op' not allowed on '$service'" >&2
+ one_fail=1
+ fi
+done
+
+
+if [ -n "$one_fail" ] && [ -n "$one_ok" ]; then
+ exit 1
+elif [ -n "$one_fail" ]; then
+ exit 2
+fi
+
+exit 0
+