-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserv
executable file
·54 lines (43 loc) · 1.01 KB
/
serv
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
#!/bin/bash
set -ueo pipefail
read -r -d '' USAGE << EOM || true
$(basename $0) SERVICE_NAME COMMAND
$(basename $0) is a light wrapper around systemctl
COMMAND is one of "start", "stop", "stat". Other commands are
passed through to systemctl
e.g. serv nginx stop
EOM
usage.sh "$USAGE" $@ && exit
[ $# -lt 1 ] && $0 --help && exit
name=${1?"Input service name"}
name="$name.service"
subcmd=${2:-stat}
case $subcmd in
"start")
# TODO: fix later
echo "starting $name with $subcmd"
sudo systemctl status $name
running=$?
if [ $running != 0 ]; then
echo "$name not running. will start"
sudo systemctl start $name > /dev/null
echo "started: $name"
else
echo "already running: $name"
fi
sleep 2
sudo systemctl status $name
exit ;;
"stop")
sudo systemctl stop $name
sudo systemctl status $name
exit ;;
stat*)
sudo systemctl status $name
exit ;;
*)
# pass command through to systemctl
sudo systemctl $subcmd $name
#echo "subcommand: $subcmd is invalid. exiting."
exit ;;
esac