summaryrefslogtreecommitdiffstats
path: root/scripts/systemctl
diff options
context:
space:
mode:
authorSimon Rettberg2020-07-06 14:20:44 +0200
committerSimon Rettberg2020-07-06 14:20:44 +0200
commit8575291412d87c4344e44079e33d2aeff9e417a3 (patch)
tree467fc52cbb2f3c30335264efab532bf411ce73b4 /scripts/systemctl
parent[scripts/mount-store] Run dir/perm init for unknown mounts too (diff)
downloadtmlite-bwlp-8575291412d87c4344e44079e33d2aeff9e417a3.tar.gz
tmlite-bwlp-8575291412d87c4344e44079e33d2aeff9e417a3.tar.xz
tmlite-bwlp-8575291412d87c4344e44079e33d2aeff9e417a3.zip
[ldap/systemctl] Wrapper script, systemd-ize ldadp handling
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
+