diff options
| author | Guillaume Horel <guillaume.horel@gmail.com> | 2011-04-25 00:52:05 -0400 |
|---|---|---|
| committer | Guillaume Horel <guillaume.horel@gmail.com> | 2011-04-25 00:52:05 -0400 |
| commit | 5f2d5dbc45f1bb84c3f58078cb132e0992ec0994 (patch) | |
| tree | d6e7288cf8957a4a1a780f392b70a1880ff5d346 /server/alias.py | |
| parent | 31d5c3bc03fd50c076026c4954a1cdb5bcef40b0 (diff) | |
| download | alias-5f2d5dbc45f1bb84c3f58078cb132e0992ec0994.tar.gz | |
Some further daemon cleanups.
- alias logs should be properly redirected
- needs to redirect sleekxmpp somewhere
Diffstat (limited to 'server/alias.py')
| -rw-r--r-- | server/alias.py | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/server/alias.py b/server/alias.py index ae3d191..8d75ec2 100644 --- a/server/alias.py +++ b/server/alias.py @@ -1,10 +1,12 @@ #!/usr/bin/python2 import logging from argparse import ArgumentParser -from config import filename, config +from config import config import daemon import daemon.pidfile from server import ObjectComponent +import os.path +import sys if __name__ == '__main__': commandline = ArgumentParser(description = 'Connect the alias \ @@ -31,16 +33,12 @@ if __name__ == '__main__': help = 'run the server in the background', action = 'store_true') commandline.add_argument('--logfile', - help = 'location of the log file (default /var/log/${name}.log', - action = 'store_const') + help = 'location of the log file (default /var/log/${name}.log') commandline.add_argument('--pidfile', - help = 'location of the pid file (default /var/run/${name}.pid', - action = 'store_const') - + help = 'location of the pid file (default /var/run/${name}.pid') args = commandline.parse_args() if args.config is None: - logging.basicConfig(level = args.debug) config.name = args.name config.port = args.port config.secret = args.secret @@ -51,24 +49,31 @@ if __name__ == '__main__': config.pidfile = args.pidfile else: filename = args.config - logging.basicConfig(level = args.debug) config.read(filename) - - logger = logging.getLogger("DaemonLog") - logger.setLevel(logging.INFO) - formatter = logging.Formatter( -"%(asctime)s - %(name)s - %(levelname)s - %(message)s") + if config.logfile is None: + config.logfile = os.path.join('/var/log/', config.name + '.log') + if config.pidfile is None: + config.pidfile = os.path.join('/var/run/', config.name + '.pid') + + #set up the logger handler = logging.FileHandler(config.logfile) + formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") + handler.setFormatter(formatter) + + logger = logging.getLogger("alias") + logger.setLevel(args.debug) logger.addHandler(handler) + import pdb; pdb.set_trace() context = daemon.DaemonContext(detach_process = config.background, pidfile = daemon.pidfile.TimeoutPIDLockFile(config.pidfile,10), - files_preserve=[handler.stream]) + files_preserve=[handler.stream.fileno()], + stdout=sys.stdout, stderr=sys.stderr) with context: component = ObjectComponent(config.name, config.secret, config.host, config.port, config.root) - if component.connect(): - logging.info('Component {} connected'.format(component.boundjid)) + if component.connect(): + logger.info('Component {} connected'.format(component.boundjid)) component.process(False) else: - logging.error("Component {} couldn't connect".format(component.boundjid))
\ No newline at end of file + logger.error("Component {} couldn't connect".format(component.boundjid)) |
