-
Notifications
You must be signed in to change notification settings - Fork 13
/
service-commands
executable file
·83 lines (76 loc) · 1.72 KB
/
service-commands
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
me="service-commands"
mode=`basename $0`
if [ "$mode" = "$me" ] && [ -z "$*" ]; then
here=`dirname $0`
echo -n "Setting up handy service shortcuts in $here ... "
cd "$here"
for op in {,u}s{re,rl,st,t,sp,p,ta}; do
if ! [ -e $op ]; then
ln -s $me $op
echo -n " $op"
fi
done
echo
exit 0
fi
user=
case "$mode" in
u*)
user=--user
mode="${mode#u}"
;;
esac
case "$mode" in
sre)
op=restart ;;
srl)
op=reload ;;
st|sst)
op=start ;;
sp|ssp)
op=stop ;;
sta)
op=status ;;
*)
echo "$0: Unrecognised mode '$mode'"; exit 1 ;;
esac
service="$1"
if [ -n "$1" ]; then
shift
elif [ "$op" != status ]; then
echo >&2 "Missing service name; aborting"
exit 1
fi
if [ "`id -u`" != 0 ] && [ -z "$user" ]; then
# 'ave a go son
sudo=sudo
else
sudo=
fi
if which systemctl >&/dev/null; then
case $op in
status)
# For some moronic reason, systemctl --lines=N status doesn't
# work properly. I'm guessing it only shows lines since the
# service was
$sudo systemctl -n 0 --no-pager $user $op $service "$@"
if [[ -z $user ]]; then
unit_option=-u
else
unit_option=--user-unit
fi
echo
$sudo journalctl -n 10 --no-pager $user $unit_option $service "$@"
;;
*)
exec $sudo systemctl $user $op $service "$@"
;;
esac
elif [ -x /sbin/service ]; then
# legacy v1
exec $sudo /sbin/service "$service" $op "$@"
else
# legacy v2
exec $sudo /etc/init.d/"$service" $op "$@"
fi