blob: 68ea3ef58b9a7ce4009868ef803599b40444faf6 (
plain) (
blame)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#!/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" = "start" || "$op" = "restart" ]] && 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
|