-
Notifications
You must be signed in to change notification settings - Fork 41
/
rc.mptsd
executable file
·163 lines (152 loc) · 3.36 KB
/
rc.mptsd
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/sh
# mptsd server control script
# Copyright (C) 2007-2011 Unix Solutions Ltd.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
#
PATH="/home/iptv:/bin:/sbin:/usr/bin:/usr/local/bin"
export PATH
cd $(dirname $0)
CONFIG="$(basename $0).conf"
if [ ! -r $CONFIG ]
then
echo "[ERROR] $CONFIG is not found."
exit 1
fi
. ./$CONFIG
istart() {
echo "[START] Starting $PRGNAME."
if [ ! -f "$SERVER" -o ! -x "$SERVER" ]
then
echo "[ERROR] $SERVER does not exist or it's not executable."
exit 1
fi
if [ -r "$PIDFILE" ]
then
fpid=$(cat "$PIDFILE" 2>/dev/null)
rpid=$(pidof $PRGNAME 2>/dev/null)
if [ -n "$rpid" -a "0$fpid" -eq "0$rpid" ]
then
echo "[ERROR] $PRGNAME is already running: (pid $rpid)"
exit 1
else
echo "[ERROR] $PIDFILE is stale, $PRGNAME is not running. Deleting it pid file."
rm $PIDFILE
fi
fi
echo "[CMD ] $SERVER $PARAMS"
cd $(dirname $SERVER)
$SERVER $PARAMS
if [ $? -eq 0 ]
then
echo "[OK ] $PRGNAME started."
else
echo "[ERROR] $PRGNAME not started."
fi
}
istop() {
echo "[STOP ] Stopping $PRGNAME."
killall $PRGNAME
if [ $? -eq 0 ]
then
echo -n "[WAIT ] Waiting"
echo -n "." && sleep .3
echo -n "." && sleep .3
echo -n "." && sleep .3
echo -n "." && sleep .2
echo "."
if [ -r "$PIDFILE" ]
then
RPID=$(pidof $PRGNAME 2>/dev/null)
if [ "0$RPID" -ne "0" ]
then
echo "[ERROR] $PRGNAME is still running: (pid $(cat $PIDFILE)). Kill -9ing it."
killall -9 $PRGNAME
fi
fi
echo "[OK ] $PRGNAME is stopped."
fi
}
icheck() {
if [ -r "$PIDFILE" ]
then
fpid=$(cat "$PIDFILE" 2>/dev/null)
rpid=$(pidof $PRGNAME 2>/dev/null)
if [ -n "$rpid" -a "0$fpid" -eq "0$rpid" ]
then
echo "[CHECK] $PRGNAME is already running: (pid $rpid)"
else
istart
fi
else
echo "[CHECK] Stop and start"
istop
istart
fi
}
istatus() {
rpid=$(pidof $PRGNAME 2>/dev/null)
echo "[STATUS] $PRGNAME pidfile pid: $(cat $PIDFILE 2>/dev/null)"
echo "[STATUS] $PRGNAME pidof pid: $rpid"
if [ -z "$rpid" ]
then
echo "[STATUS] $PRGNAME is not running."
else
if [ -n "$rpid" -a "0$(cat $PIDFILE 2>/dev/null)" -eq "0$rpid" ]
then
echo "[STATUS] $PRGNAME is running"
else
echo "[STATUS] $PRGNAME is running but no pid file exist: $PIDFILE"
fi
ps ax | grep "$PRGNAME -i" | grep -v grep
fi
}
ireconnect() {
echo "[RECONN] Sending SIGUSR1 to $PRGNAME causing reconnect"
kill -USR1 $(pidof $PRGNAME)
}
ireload() {
echo "[RECONN] Sending SIGHUP to $PRGNAME causing configuration reload"
kill -HUP $(pidof $PRGNAME)
}
case "$1" in
'start')
if [ "$2" != "" ]
then
sleep "$2"
fi
istart
;;
'stop')
istop
;;
'check')
icheck
;;
'status')
istatus
;;
'restart')
istop
istart
;;
'reload')
ireload
;;
'reconnect')
ireconnect
;;
*)
echo "Usage: `basename $0` start|stop|check|restart|reload|reconnect|status"
esac