Make pid file configurable

And some other fixups around starting the daemon:
* read config file before forking
* add '-d' option to avoid forking
* default pidfile to /var/run/elastic-recheck/elastic-recheck.pid
* add pidfile option to config file
* switch to python-daemon library (which is the version of the
  lib that the code was expecting anyway)
* use expanduser in the query file path (to match the rest of the
  paths)

Change-Id: I674778ef189cd216a80f74bd449cdc3b12b57a7d
This commit is contained in:
James E. Blair 2013-09-30 10:27:00 -07:00
parent f173f8b8b3
commit 338c2135b4
3 changed files with 20 additions and 9 deletions

View File

@ -42,6 +42,7 @@ import ConfigParser
import daemon
import irc.bot
import logging
import logging.config
import os
import sys
import threading
@ -167,9 +168,7 @@ class ChannelConfig(object):
self.events[event] = event_set
def _main():
config = ConfigParser.ConfigParser({'server_password': None})
config.read(sys.argv[1])
def _main(config):
setup_logging(config)
fp = config.get('ircbot', 'channel_config')
@ -199,14 +198,24 @@ def _main():
def main():
if len(sys.argv) != 2:
if len(sys.argv) < 2:
print "Usage: %s CONFIGFILE" % sys.argv[0]
sys.exit(1)
pid = pid_file_module.TimeoutPIDLockFile(
"/tmp/recheckwatchbot.pid", 10)
with daemon.DaemonContext(pidfile=pid):
_main()
config = ConfigParser.ConfigParser({'server_password': None})
config.read(sys.argv[1])
if config.has_option('ircbot', 'pidfile'):
pid_fn = os.path.expanduser(config.get('ircbot', 'pidfile'))
else:
pid_fn = '/var/run/elastic-recheck/elastic-recheck.pid'
if '-d' in sys.argv:
_main(config)
else:
pid = pid_file_module.TimeoutPIDLockFile(pid_fn, 10)
with daemon.DaemonContext(pidfile=pid):
_main(config)
def setup_logging(config):

View File

@ -22,6 +22,7 @@ import urllib2
import ConfigParser
import copy
import logging
import os
import sys
import time
import yaml
@ -268,6 +269,7 @@ def main():
user = config.get('gerrit', 'user', 'jogo')
host = config.get('gerrit', 'host', 'review.openstack.org')
queries = config.get('gerrit', 'query_file', 'queries.yaml')
queries = os.path.expanduser(queries)
key = config.get('gerrit', 'key')
classifier = Classifier(queries)
stream = Stream(user, host, key)

View File

@ -1,6 +1,6 @@
pyelasticsearch
gerritlib
daemon
python-daemon
irc
pyyaml
lockfile