From 815ac4309f549eec88989f81a0f9e436f7542747 Mon Sep 17 00:00:00 2001 From: Erik Heeren Date: Fri, 10 May 2013 13:13:58 +0200 Subject: [PATCH 1/3] Write PID file for supervisor compatibility --- __init__.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/__init__.py b/__init__.py index 5699583aa..249c1ae3b 100755 --- a/__init__.py +++ b/__init__.py @@ -10,11 +10,16 @@ import sys, os, time, threading, signal import bot -class Watcher(object): +class Watcher(object): # Cf. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496735 def __init__(self): self.child = os.fork() - if self.child != 0: + if self.child != 0: + f = open('/tmp/phenny.pid', 'w') + try: + f.write(str(self.child)) + finally: + f.close() self.watch() def watch(self): From 236c67cf28795a15541c7dbbd3c30278deb1b759 Mon Sep 17 00:00:00 2001 From: Erik Heeren Date: Fri, 10 May 2013 14:10:55 +0200 Subject: [PATCH 2/3] Update pidfile for multiple phenny instances --- __init__.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/__init__.py b/__init__.py index 249c1ae3b..48ca61328 100755 --- a/__init__.py +++ b/__init__.py @@ -12,10 +12,10 @@ class Watcher(object): # Cf. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496735 - def __init__(self): + def __init__(self, config_name='default'): self.child = os.fork() if self.child != 0: - f = open('/tmp/phenny.pid', 'w') + f = open('/tmp/phenny.%s.pid' % config_name, 'w') try: f.write(str(self.child)) finally: @@ -41,8 +41,9 @@ def connect(config): p = bot.Phenny(config) p.run(config.host, config.port) - try: Watcher() - except Exception, e: + config_name = os.path.basename(config.filename).split('.')[0] + try: Watcher(config_name) + except Exception, e: print >> sys.stderr, 'Warning:', e, '(in __init__.py)' while True: From 4214e81bac633876bc876de0ec94a908067c6386 Mon Sep 17 00:00:00 2001 From: Erik Heeren Date: Tue, 14 May 2013 14:56:25 +0200 Subject: [PATCH 3/3] Write pid file to phenny config dir instead of /tmp --- __init__.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/__init__.py b/__init__.py index 48ca61328..e6f2b7555 100755 --- a/__init__.py +++ b/__init__.py @@ -12,10 +12,12 @@ class Watcher(object): # Cf. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/496735 - def __init__(self, config_name='default'): + def __init__(self, config_file): + config_dir = os.path.dirname(config_file) + config_name = os.path.basename(config_file).split('.')[0] self.child = os.fork() if self.child != 0: - f = open('/tmp/phenny.%s.pid' % config_name, 'w') + f = open('%s/phenny.%s.pid' % (config_dir, config_name), 'w') try: f.write(str(self.child)) finally: @@ -41,8 +43,7 @@ def connect(config): p = bot.Phenny(config) p.run(config.host, config.port) - config_name = os.path.basename(config.filename).split('.')[0] - try: Watcher(config_name) + try: Watcher(config.filename) except Exception, e: print >> sys.stderr, 'Warning:', e, '(in __init__.py)'