From 8575291412d87c4344e44079e33d2aeff9e417a3 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 6 Jul 2020 14:20:44 +0200 Subject: [ldap/systemctl] Wrapper script, systemd-ize ldadp handling --- scripts/systemctl | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 scripts/systemctl (limited to 'scripts/systemctl') 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 + -- cgit v1.2.3-55-g7522