-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathsystemd-wrapper.sh
executable file
·52 lines (44 loc) · 1.14 KB
/
systemd-wrapper.sh
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
#!/bin/bash
# wrapper for managing systemd services
usage() {
cat <<EOF
start | start a service
restart | reload unit configuration
stop | in the name of love
enable | start at boot
is-enabled | check status
status | current state
disable | do not load at boot
list | list all running services
fail | list failed services
reboot | restart
shut | poweroff
EOF
exit 0
}
(( $# >= 2 )) && {
[[ "$1" = @(*start|stop|*able) ]] &&
action="$1" || usage
shift
sudo systemctl --system daemon-reload
for arg in $* ;do
echo "${action}ing $arg ... "
sudo systemctl $action $arg
done
exit
}
(( $# <= 1 )) && {
case "$1" in
list) systemctl list-units ;;
fail*) systemctl --failed ;;
reboot) echo -n "reboot: [y/n]: "
while read -n1 answer; do
case $answer in
y|Y|Yes|YES|yes) systemctl reboot ;;
*) exit 0 ;;
esac;done
;;
shut*) systemctl poweroff ;;
*) usage
esac
}