forked from etdey/gdl90
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gdl90_service_wrapper
79 lines (64 loc) · 1.5 KB
/
gdl90_service_wrapper
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
#!/bin/bash
#
# Systemd service wrapper for GDL90 recorder
#
#
NETWORK_DEV=wlan0
LISTEN_PORT=4000
ADSB_DIRECTORY=/root/adsb
LOG_DIRECTORY=${ADSB_DIRECTORY}/logs
RECORDER_SCRIPT=${ADSB_DIRECTORY}/gdl90_recorder.py
PYTHON=/usr/bin/python
# this path must match the PIDFile value in the systemd unit.service file
PID_FILE=/var/run/gdl90_recorder.pid
running_pid() {
if [ -f $PID_FILE ]; then
pid=`cat $PID_FILE` &> /dev/null
cat /proc/${pid}/cmdline | grep "$PYTHON" &> /dev/null
if [ $? -eq 0 ]; then
echo $pid
return 0
fi
fi
echo 0
}
do_start() {
pid=`running_pid`
if [ $pid -ne 0 ]; then
echo "ERROR: service appears to be running as PID $pid"
echo "To remove stale pid file: rm $PID_FILE"
return 1
fi
echo "Starting recorder on device $NETWORK_DEV port $LISTEN_PORT"
$PYTHON $RECORDER_SCRIPT --interface=$NETWORK_DEV --port=$LISTEN_PORT --logprefix=$LOG_DIRECTORY &
pid=$!
echo $pid > $PID_FILE
echo "Process running with PID $pid"
}
do_stop() {
pid=`running_pid`
if [ $pid -eq 0 ]; then
echo "INFO: did not find a running service to stop"
return 0
fi
kill $pid
rm $PID_FILE
}
case "$1" in
start)
do_start
[ $? -ne 0 ] && exit 1
;;
stop)
do_stop
;;
restart|reload)
do_stop
do_start
;;
*)
echo "Calling: $0 <start|stop|restart|reload>"
exit 1
;;
esac
exit 0