forked from dimikot/dklab_realplexor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dklab_realplexor.init
executable file
·129 lines (118 loc) · 3.4 KB
/
dklab_realplexor.init
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
#!/bin/bash
# Start/stop the dklab_realplexor daemon.
#
# chkconfig: - 85 15
# description: Dklab Realplexor: Comet server which handles 1000000+ parallel browser connections.
# processname: dklab_realplexor.pl
# config: /etc/dklab_realplexor.conf
# pidfile: /var/run/dklab_realplexor_*.pid
#
### BEGIN INIT INFO
# Provides: dklab_realplexor
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 1
# Short-Description: Dklab Realplexor Comet Server.
# Description: Dklab Realplexor: Comet server which handles 1000000+ parallel browser connections.
### END INIT INFO
#
# If you store dklab_realplexor in a different location,
# it is recommended not to change CWD, but run:
#
# ln -s /path/to/your/dklab_realplexor /opt/dklab_realplexor
#
# If you want to change some variables, it is recommended
# to put these changes to /etc/default/YOUR_INIT_SCRIPT_NAME
# (typically /etc/default/dklab_realplexor). All variables
# defined there will override current script.
#
CWD="/opt/dklab_realplexor"
# Same as with additional config: better create symlink in /etc.
ADDCONFIG="/etc/dklab_realplexor.conf"
# Logging options. By default syslog is used, it allows easy log rotation.
# You may use $CONF variable to refer to the full config file path.
LOGTAG='realplexor/`basename $CONF`'
LOGPRI='local3.info'
# Prefix for PID file.
PIDPREFIX="/var/run/dklab_realplexor"
# Override settings if needed.
NAME=`basename $0`
if [ ${NAME:0:1} = "S" -o ${NAME:0:1} = "K" ]; then
NAME=${NAME:3}
fi
[ -f /etc/default/${NAME} ] && . /etc/default/${NAME}
[ -f /etc/sysconfig/${NAME} ] && . /etc/sysconfig/${NAME}
# Script to execute.
if [ -x $CWD/dklab_realplexor ]; then
BIN="$CWD/dklab_realplexor"
else
BIN="/usr/bin/perl $CWD/dklab_realplexor.pl"
fi
start () {
export CONF
for CONF in $ADDCONFIG; do
PIDFILE=${PIDPREFIX}_`basename $CONF`.pid
PID=`cat $PIDFILE 2>/dev/null`
if [ "$PID" != "" ] && kill -s 0 $PID 2>/dev/null; then
echo "dklab_realplexor for $CONF is already running"
else
rm -f $PIDFILE 2>/dev/null
cd $CWD && $BIN $CONF -p $PIDFILE 2>&1 | logger -p `eval "echo $LOGPRI"` -t `eval "echo $LOGTAG"` &
sleep 1
PID=`cat $PIDFILE 2>/dev/null`
if [ "$PID" != "" ]; then
echo "OK: $CONF"
else
echo "FAILED: $CONF; see logs"
fi
fi
done
}
stop () {
for CONF in $ADDCONFIG; do
PIDFILE=${PIDPREFIX}_`basename $CONF`.pid
PID=`cat $PIDFILE 2>/dev/null`
if [ "$PID" == "" ]; then
echo "dklab_realplexor for $CONF is not running (pid file is empty)"
else
kill $PID
echo "OK: $CONF"
fi
done
}
reload () {
for CONF in $ADDCONFIG; do
PIDFILE=${PIDPREFIX}_`basename $CONF`.pid
PID=`cat $PIDFILE 2>/dev/null`
if [ "$PID" == "" ]; then
echo "dklab_realplexor for $CONF is not running (pid file is empty)"
start
else
# Send SIGHUP to process group.
kill -s 1 $PID
echo "OK: $CONF"
fi
done
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 2
start
;;
reload)
reload
;;
*)
echo "Usage:"
echo " $0 {start|stop|restart|reload}"
exit 1
;;
esac