File tree Expand file tree Collapse file tree 2 files changed +45
-2
lines changed Expand file tree Collapse file tree 2 files changed +45
-2
lines changed Original file line number Diff line number Diff line change 3
3
from twisted .internet .protocol import ReconnectingClientFactory
4
4
from twisted .python import log
5
5
from twisted .internet .endpoints import clientFromString
6
+ from twisted .application import service
6
7
from signal import signal , SIGINT
7
8
import re
8
9
11
12
log .startLogging (sys .stdout )
12
13
13
14
__version__ = "0.2"
15
+ application = service .Application ("RelayBot" )
14
16
15
17
def main ():
16
18
host = "localhost"
@@ -38,7 +40,6 @@ def main():
38
40
reactor .connectTCP (host , port , factory , timeout )
39
41
40
42
reactor .callWhenRunning (signal , SIGINT , handler )
41
- reactor .run ()
42
43
43
44
class Communicator :
44
45
def __init__ (self ):
@@ -157,5 +158,6 @@ class FLIPFactory(RelayFactory):
157
158
def handler (signum , frame ):
158
159
reactor .stop ()
159
160
160
- if __name__ == "__main__" :
161
+ #Main if run as script, builtin for twistd.
162
+ if __name__ in ["__main__" , "__builtin__" ]:
161
163
main ()
Original file line number Diff line number Diff line change
1
+ #! /bin/bash
2
+ if [ " X` id -u` " = " X0" -a -z " $RUN_AS_USER " ]
3
+ then
4
+ echo " Do not run this script as root."
5
+ exit 1
6
+ fi
7
+
8
+ start () {
9
+ twistd --python=relaybot.py --logfile=relaybot.log --pidfile=relaybot.pid
10
+ }
11
+
12
+ stop () {
13
+ kill ` cat relaybot.pid`
14
+ }
15
+
16
+ case " $1 " in
17
+ ' start' )
18
+ start
19
+ ;;
20
+
21
+ ' stop' )
22
+ stop
23
+ ;;
24
+
25
+ ' restart' )
26
+ stop
27
+ start
28
+ ;;
29
+
30
+ ' status' )
31
+ tail -F relaybot.log
32
+ ;;
33
+
34
+ * )
35
+ echo " Usage: $0 { start | stop | restart | status }"
36
+ exit 1
37
+ ;;
38
+
39
+ esac
40
+
41
+ exit 0
You can’t perform that action at this time.
0 commit comments