-
Notifications
You must be signed in to change notification settings - Fork 0
/
beacon
executable file
·101 lines (95 loc) · 2.73 KB
/
beacon
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#! /bin/sh
#
### BEGIN INIT INFO
# Provides: beacon
# Required-Start: $network
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: beacon
# Description: init script for the Shark Beacon
### END INIT INFO
# TODO: Error checking and well properly kill the process...
PATH=/sbin:/bin:/usr/sbin:/usr/bin
NAME=beacon
DESC="Shark Beacon"
WORKDIR=/opt/sharkbeacon
PIDFILE=$WORKDIR/$NAME.pid
DAEMON=$WORKDIR/launch.sh
USER=beacon
GROUP=beacon
test -x $DAEMON || exit 0
case "$1" in
start)
echo -n "Starting $DESC ..."
[ -d $PIDDIR ] || install -o $USER -d $PIDDIR
start-stop-daemon --start --quiet \
--pidfile $PIDFILE \
--make-pidfile \
--chuid $USER:$GROUP \
--chdir $WORKDIR \
--background \
--exec $DAEMON
case "$?" in
0|1) echo "Started" ;;
2) echo "Failed" ;;
esac
;;
stop)
echo -n "Stopping $DESC ..."
start-stop-daemon --stop --quiet \
--retry=TERM/30/KILL/5 \
--pidfile $PIDFILE \
--user $USER
case "$?" in
0|1) rm -f $PIDFILE
echo "Stopped"
;;
2) echo "Failed" ;;
esac
;;
status)
if start-stop-daemon --test --stop --quiet \
--pidfile $PIDFILE \
--user $USER
then
echo "$DESC is running."
exit 0
else
echo "$DESC is not running"
exit 3
fi
;;
restart)
echo -n "Restarting $DESC ..."
start-stop-daemon --stop --quiet \
--retry=TERM/30/KILL/5 \
--pidfile $PIDFILE \
--user $USER
case "$?" in
0|1)
[ -d $PIDDIR ] || install -o $USER -d $PIDDIR
rm -f $PIDFILE
start-stop-daemon --start --quiet \
--pidfile $PIDFILE \
--chuid $USER:$GROUP \
--chdir $WORKDIR \
--background \
--exec $DAEMON
case "$?" in
0) echo "Restarted" ;;
*) echo "Start Failed" ;;
esac
;;
*)
echo "Stop Failed"
;;
esac
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|status}" >&2
exit 3
;;
esac
exit 0