Commit cc4ec621 authored by ale's avatar ale

Improve command-line options for daemonization

Split functionality into --foreground/--debug/-syslog.
parent 7831efb0
......@@ -21,4 +21,4 @@ RUN apt-get -q update && \
COPY nospam/conf/update-surbl /usr/bin/update-surbl
COPY nospam/conf/docker-start.sh /usr/bin/nospamd
ENTRYPOINT ["/usr/bin/nospamd"]
ENTRYPOINT ["/usr/bin/nospamd", "--foreground"]
......@@ -100,7 +100,11 @@ def start(opts):
def main():
parser = optparse.OptionParser()
parser.add_option('-d', '--debug', dest='debug', action='store_true',
help='Log debug messages to stderr.')
help='Print debug messages.')
parser.add_option('--syslog', action='store_true',
help='Send log messages to syslog.')
parser.add_option('--foreground', action='store_true',
help='Do not fork into the background.')
parser.add_option('-c', '--config', dest='config',
default='/etc/nospam/config.yml',
help='Configuration file (default: /etc/nospam/config.yml).')
......@@ -113,20 +117,23 @@ def main():
if len(args) != 0:
parser.error('Too many arguments')
# Log to syslog, unless --debug is defined.
# Set up logging, according to command-line options.
logger = logging.getLogger()
if opts.debug:
logging.basicConfig()
logger.setLevel(logging.DEBUG)
else:
logger.setLevel(logging.INFO)
if opts.syslog:
handler = logging.handlers.SysLogHandler(address='/dev/log',
facility=3)
handler.setFormatter(logging.Formatter(
'nospam[%(process)d]: (%(module)s) %(levelname)s: %(message)s'))
logger.addHandler(handler)
logger.setLevel(logging.INFO)
else:
logging.basicConfig()
if opts.debug:
if opts.foreground:
start(opts)
else:
def do_start():
......
......@@ -60,6 +60,7 @@ def make_server(config):
app.blogspam = api.BlogSpamCompatibleAPI(app.nospam)
addr = ('0.0.0.0', int(config.get('port')))
app.logger.info("serving on %s", addr)
return pywsgi.WSGIServer(addr, app.wsgi_app)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment