From 5fec631a2af5743f91bc6e6a920e5d55dcc9ea12 Mon Sep 17 00:00:00 2001 From: Jessamyn Smith Date: Sat, 10 Mar 2012 10:32:51 -0800 Subject: [PATCH] Added facility for stopping the bot and made it nicer to start --- bot.py | 7 +------ wsrs_bot | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 6 deletions(-) create mode 100755 wsrs_bot diff --git a/bot.py b/bot.py index f43dfc3..28d955a 100644 --- a/bot.py +++ b/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() \ No newline at end of file + reactor.run() \ No newline at end of file diff --git a/wsrs_bot b/wsrs_bot new file mode 100755 index 0000000..d64d344 --- /dev/null +++ b/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) \ No newline at end of file