Skip to content

Commit

Permalink
Added facility for stopping the bot and made it nicer to start
Browse files Browse the repository at this point in the history
  • Loading branch information
Jessamyn Smith committed Mar 10, 2012
1 parent efb9e00 commit 5fec631
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
7 changes: 1 addition & 6 deletions bot.py
Expand Up @@ -73,9 +73,4 @@ def run(self):
ssl.ClientContextFactory()) ssl.ClientContextFactory())
else: else:
reactor.connectTCP(settings.HOST, settings.PORT, factory) reactor.connectTCP(settings.HOST, settings.PORT, factory)
reactor.run() reactor.run()


if __name__ == '__main__':
bot = WSRSDaemon('./pid.pid')
bot.start()
30 changes: 30 additions & 0 deletions 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.