-
Notifications
You must be signed in to change notification settings - Fork 0
/
telcom
executable file
·90 lines (70 loc) · 2.18 KB
/
telcom
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
#!/bin/bash
### BEGIN INIT INFO
# Provides: telcom
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: OpenBSD Secure Shell server
### END INIT INFO
set -e
NAME=telcom
PIDFILE="/var/run/$NAME.pid"
DAEMON=/home/pi/telcom.py
cfg_opt="/home/pi/telcom.cfg"
PATH="$PATH:/sbin"
kill_all()
{
echo "kill_all called"
PIDS="`ps -Aelf | grep /home/pi/telcom.py | grep python | awk '{printf("%s\n", $4)}'`"
thisCount=0
for PID in $PIDS; do thisCount=$((thisCount+1)); done
if [ "$thisCount" -gt 1 ]; then
echo "too many instances running $PIDS"
for a in `ps -Aelf | grep telcom.py | grep python| awk '{printf("%s\n", $4)}'`; do kill -9 $a; done
echo "" > $PIDFILE;
fi
}
case "$1" in
start)
echo "Starting $DAEMON"
start-stop-daemon --start --make-pidfile --pidfile $PIDFILE --exec $DAEMON -- $cfg_opt >> /home/pi/telcom.err 2>&1 &
;;
stop)
echo "Stopping"
start-stop-daemon --stop --pidfile $PIDFILE || kill_all
;;
restart)
thePID=`ps -Aelf | grep /home/pi/telcom.py | grep python | awk '{printf("%s\n", $4)}'`
filePID="$(cat $PIDFILE)"
if [ "$thePID" == "" ]; then
echo "$NAME is not running";
elif [ "$thePID" == "$filePID" ]; then
echo "$NAME is running";
start-stop-daemon --stop --pidfile $PIDFILE
else
kill_all
echo "Stopping $thePID"
start-stop-daemon --stop --pidfile $PIDFILE || kill_all
fi
echo "Starting $DAEMON"
start-stop-daemon --start --make-pidfile --pidfile $PIDFILE --exec $DAEMON -- $cfg_opt >> /home/pi/telcom.err 2>&1 &
;;
soft-start)
thePID=`ps -Aelf | grep telcom.py | grep python | awk '{printf("%s\n", $4)}'`
filePID="$(cat $PIDFILE)"
if [ "$thePID" == "$filePID" ]; then
echo "running as PID $thePID";
elif [ "$thePID" == "" ]; then
echo "$NAME was not running starting";
start-stop-daemon --start --make-pidfile --pidfile $PIDFILE --exec $DAEMON -- $cfg_opt >> /home/pi/telcom.err 2>&1 &
else
echo $thePID
echo "$NAME was running as wrong pid restarting"
kill -9 $thePID;
kill_all
start-stop-daemon --start --make-pidfile --pidfile $PIDFILE --exec $DAEMON -- $cfg_opt >> /home/pi/telcom.err 2>&1 &
fi
;;
esac
exit 0