forked from AndyTaylorTweet/Pi-Star_Binaries_sbin
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpistar-watchdog.service
executable file
·75 lines (68 loc) · 2.43 KB
/
pistar-watchdog.service
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/bash
#########################################################
# #
# pistar-watchdog Service Handler #
# #
# Written for Pi-Star (http://www.mw0mwz.co.uk/pi-star) #
# By Andy Taylor (MW0MWZ) #
# #
# Version 1.0 #
# #
#########################################################
# Service Config
DAEMON=python
DAEMON_PATH=/usr/bin/
DAEMON_OPTS=/usr/local/sbin/pistar-watchdog
PGREP=/usr/bin/pgrep
KILL=/bin/kill
SLEEP=/bin/sleep
# Pre-flight checks...
test -x ${DAEMON_PATH}${DAEMON} || exit 1
test -x ${DAEMON_OPTS} || exit 1
case "$1" in
start)
if [ `${PGREP} -f "${DAEMON_PATH}${DAEMON} ${DAEMON_OPTS}"` ]; then
echo -e "pistar-watchdog is already running as PID "`${PGREP} -f "${DAEMON_PATH}${DAEMON} ${DAEMON_OPTS}"`
exit 1;
else
${DAEMON_PATH}${DAEMON} ${DAEMON_OPTS} &
echo -e "pistar-watchdog started as PID "`${PGREP} -f "${DAEMON_PATH}${DAEMON} ${DAEMON_OPTS}"`
exit 0;
fi
;;
stop)
if [ `${PGREP} -f "${DAEMON_PATH}${DAEMON} ${DAEMON_OPTS}"` ]; then
echo -e "Killing pistar-watchdog PID "`${PGREP} -f "${DAEMON_PATH}${DAEMON} ${DAEMON_OPTS}"`
$KILL `${PGREP} -f "${DAEMON_PATH}${DAEMON} ${DAEMON_OPTS}"`
exit 0;
else
echo -e "pistar-watchdog is not running"
exit 1;
fi
;;
restart)
if [ `${PGREP} -f "${DAEMON_PATH}${DAEMON} ${DAEMON_OPTS}"` ]; then
echo -e "Killing pistar-watchdog PID "`${PGREP} -f "${DAEMON_PATH}${DAEMON} ${DAEMON_OPTS}"`
$KILL `${PGREP} -f "${DAEMON_PATH}${DAEMON} ${DAEMON_OPTS}"`
$SLEEP 3
${DAEMON_PATH}${DAEMON} ${DAEMON_OPTS} &
echo -e "pistar-watchdog re-started as PID "`${PGREP} -f "${DAEMON_PATH}${DAEMON} ${DAEMON_OPTS}"`
exit 0;
else
echo -e "pistar-watchdog is not running"
${DAEMON_PATH}${DAEMON} ${DAEMON_OPTS} &
echo -e "pistar-watchdog is started as PID "`${PGREP} -f "${DAEMON_PATH}${DAEMON} ${DAEMON_OPTS}"`
exit 0;
fi
;;
status)
if [ `${PGREP} -f "${DAEMON_PATH}${DAEMON} ${DAEMON_OPTS}"` ]; then
echo -e "pistar-watchdog is running as PID "`${PGREP} -f "${DAEMON_PATH}${DAEMON} ${DAEMON_OPTS}"`
else
echo -e "pistar-watchdog is not running"
fi
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 1
esac