-
Notifications
You must be signed in to change notification settings - Fork 23
/
shock-server.sh
executable file
·75 lines (70 loc) · 1.38 KB
/
shock-server.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/sh -e
# Shock auto-start
#
# description: auto-starts Shock server
# processname: shock-server
# logfile: /var/log/shock/shock-server.log
# pidfile: /usr/local/shock/pidfile
# config: /usr/local/shock/shock-server.conf
NAME="shock-server"
LOG_FILE="/var/log/shock/${NAME}.log"
PID_FILE="/usr/local/shock/pidfile"
CONF_FILE="/usr/local/shock/${NAME}.conf"
start() {
echo -n "Starting $NAME... "
if [ -f $PID_FILE ]; then
echo "is already running!"
else
$NAME -conf $CONF_FILE > $LOG_FILE 2>&1 &
sleep 1
echo "(Done)"
fi
return 0
}
stop() {
echo -n "Stopping $NAME... "
if [ -f $PID_FILE ]; then
PIDN=`cat $PID_FILE`
kill $PIDN 2>&1
sleep 1
rm $PID_FILE
echo "(Done)"
else
echo "can not stop, it is not running!"
fi
return 0
}
status() {
if [ -f $PID_FILE ]; then
PIDN=`cat $PID_FILE`
PSTAT=`ps -p $PIDN | grep -v -w 'PID'`
if [ -z "$PSTAT" ]; then
echo "$NAME has pidfile ($PIDN) but is not running."
else
echo "$NAME is running with pid $PIDN."
fi
else
echo "$NAME is not running."
fi
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 5
start
;;
status)
status
;;
*)
echo "Usage: $0 (start | stop | restart | status)"
exit 1
;;
esac