-
Notifications
You must be signed in to change notification settings - Fork 0
/
txhttprelay.sh
executable file
·68 lines (60 loc) · 1.3 KB
/
txhttprelay.sh
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
#!/bin/bash
### BEGIN INIT INFO
# Provides: txhttprelay
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts twistd daemon and loads txhttprelay
# Description: Starter for txhttprelay
### END INIT INFO
TAC="txhttprelay.tac"
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DAEMON="/usr/bin/twistd"
PIDFILE="$DIR/txhttprelay.pid"
DAEMON_OPTS="--pidfile=$PIDFILE -y $DIR/$TAC"
if [ ! -x $DAEMON ]; then
echo "ERROR: Can't execute $DAEMON."
exit 1
fi
start_service() {
echo -n " * Starting $TAC... "
start-stop-daemon -Sq -p $PIDFILE -x $DAEMON -- $DAEMON_OPTS
e=$?
if [ $e -eq 1 ]; then
echo "already running"
return
fi
if [ $e -eq 255 ]; then
echo "couldn't start"
return
fi
echo "done"
}
stop_service() {
echo -n " * Stopping $TAC... "
start-stop-daemon -Kq -R 10 -p $PIDFILE
e=$?
if [ $e -eq 1 ]; then
echo "not running"
return
fi
echo "done"
}
case "$1" in
start)
start_service
;;
stop)
stop_service
;;
restart)
stop_service
start_service
;;
*)
echo "Usage: $0 {start|stop|restart}" >&2
exit 1
;;
esac
exit 0