-
Notifications
You must be signed in to change notification settings - Fork 41
/
p25parrot.service
executable file
·106 lines (96 loc) · 2.94 KB
/
p25parrot.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
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
102
103
104
105
106
#!/bin/bash
#########################################################
# #
# P25Parrot Service Handler #
# #
# Written for Pi-Star (http://www.mw0mwz.co.uk/pi-star) #
# By Andy Taylor (MW0MWZ) #
# #
# Version 1.1 #
# #
#########################################################
# Service Config
DAEMON=P25Parrot
DAEMON_PATH=/usr/local/bin/
DAEMON_OPTS=42011
LOGDIR=/var/log/pi-star
PGREP=/usr/bin/pgrep
KILL=/bin/kill
SLEEP=/bin/sleep
USER=root
GROUP=mmdvm
ipVar=`hostname -I | cut -d' ' -f1`
# Pre-flight checks...
test -x ${DAEMON_PATH}${DAEMON} || exit 0
test -r $CONFIG || exit 0
# if dstarrepeater is configured or running, dont start this daemon!
! test -r /etc/dstar-radio.dstarrepeater || exit 0
if [ `sed -n '/^\[P25 Network\]/,/^\[/p' /etc/mmdvmhost | grep "^Enable" | awk -F '=' '{print $2}'` == 0 ]; then
if [ `sed -n '/^\[System Fusion\]/,/^\[/p' /etc/mmdvmhost | grep "^Enable" | awk -F '=' '{print $2}'` == 0 ]; then
exit 0;
elif [ -f '/etc/ysf2p25' ] && [ `sed -n '/^\[Enabled\]/,/^\[/p' /etc/ysf2p25 | grep "^Enable" | awk -F '=' '{print $2}'` == 0 ]; then
exit 0;
elif [ -f '/etc/ysf2p25' ] && [ `sed -n '/^\[Enabled\]/,/^\[/p' /etc/ysf2p25 | grep "^Enable" | awk -F '=' '{print $2}'` == 1 ]; then
test=pass
else
exit 0;
fi
fi
# Verify the logging directory exists, if not create it and setup the ownership / permissions
if [ ! -d $LOGDIR ]; then
mkdir -p $LOGDIR
chown ${USER}:${GROUP} $LOGDIR
chmod 775 $LOGDIR
fi
case "$1" in
start)
if [ `${PGREP} ${DAEMON}` ]; then
echo -e "$DAEMON is already running as PID "`$PGREP $DAEMON`
exit 0;
else
# Wait for an IP address
until [ "${ipVar}" != " " ]; do
sleep 10
ipVar=`hostname -I`
done
nice -n -5 ${DAEMON_PATH}${DAEMON} ${DAEMON_OPTS} &
echo -e "$DAEMON started as PID "`$PGREP $DAEMON`
exit 0;
fi
;;
stop)
if [ `${PGREP} ${DAEMON}` ]; then
echo -e "Killing $DAEMON PID "`$PGREP $DAEMON`
$KILL `${PGREP} ${DAEMON}`
exit 0;
else
echo -e "$DAEMON is not running"
exit 0;
fi
;;
restart)
if [ `$PGREP $DAEMON` ]; then
echo -e "Killing $DAEMON PID "`$PGREP $DAEMON`
$KILL `${PGREP} ${DAEMON}`
$SLEEP 3
nice -n -5 ${DAEMON_PATH}${DAEMON} ${DAEMON_OPTS}
echo -e "$DAEMON re-started as PID "`${PGREP} ${DAEMON}`
exit 0;
else
echo -e "$DAEMON is not running"
nice -n -5 ${DAEMON_PATH}${DAEMON} ${DAEMON_OPTS} &
echo -e "$DAEMON started as PID "`${PGREP} ${DAEMON}`
exit 0;
fi
;;
status)
if [ `${PGREP} ${DAEMON}` ]; then
echo -e "$DAEMON is running as PID "`${PGREP} ${DAEMON}`
else
echo -e "$DAEMON is not running"
fi
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 0
esac