blob: aadf7641a39024ff4f683a006c5fc53ced38ca41 (
plain) (
tree)
|
|
#!/bin/bash
op="$1"
shift
if [ $# -eq 0 ]; then
echo "No service name given" >&2
exit 1
fi
declare -A services
declare -a args
if [[ "$op" == "journal" ]]; then
args=( journalctl "--no-hostname" "-n" "100" "-u" )
else
args=( systemctl "$op" )
fi
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|show|journal)$ ]] && 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 "${args[@]}" "$service"; then
one_ok=1
else
one_fail=1
[[ "$op" != "status" && "$op" != "journal" ]] && 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
|