Browse files

Added facility for stopping the bot and made it nicer to start

  • Loading branch information...
1 parent efb9e00 commit 5fec631a2af5743f91bc6e6a920e5d55dcc9ea12 Jessamyn Smith committed Mar 10, 2012
Showing with 31 additions and 6 deletions.
  1. +1 −6 bot.py
  2. +30 −0 wsrs_bot
View
7 bot.py
@@ -73,9 +73,4 @@ def run(self):
ssl.ClientContextFactory())
else:
reactor.connectTCP(settings.HOST, settings.PORT, factory)
- reactor.run()
-
-
-if __name__ == '__main__':
- bot = WSRSDaemon('./pid.pid')
- bot.start()
+ reactor.run()
View
30 wsrs_bot
@@ -0,0 +1,30 @@
+#!./bin/python
+
+import os
+import signal
+import sys
+from bot import WSRSDaemon
+
+class BotRunner(object):
+
+ PID_FILE = "./pid.pid"
+
+ def start(self):
+ bot = WSRSDaemon(self.PID_FILE)
+ bot.start()
+
+ def stop(self):
+ pid_file = open(self.PID_FILE)
+ pid = pid_file.read()
+ pid_file.close()
+ os.kill(int(pid), signal.SIGHUP)
+ os.remove(self.PID_FILE)
+
+if __name__ == '__main__':
+ command = sys.argv[1]
+ runner = BotRunner()
+ try:
+ method = getattr(runner, command)
+ method()
+ except AttributeError:
+ print "Unknown command '%s'; try start or stop" % (command)

0 comments on commit 5fec631

Please sign in to comment.