Scout24/succubus

Trying bottle based example

Opened this issue · 2 comments

esc commented

I am trying to use succubus in combination with bottle as follows:

#!/usr/bin/env python

import sys

import bottle
from bottle import route
from succubus import Daemon


@route('/')
def root():
    return 'hello succubus'


class MyDaemon(Daemon):
    def run(self):
        bottle.run(host='localhost', port=55555)


def main():
    daemon = MyDaemon(pid_file='any.pid')
    sys.exit(daemon.action())


if __name__ == '__main__':
    main()

Unfortunately the daemon doesn't start, I don't receive anything on the command line and the exit code of start is 0 even though the daemon doesn't start. Any ideas for debugging would be highly appreciated.

esc commented

The idea here is to use succubus + bottle to write simple mocks that can be used during cram tests.

esc commented

Here is how I made it work:

#!/usr/bin/env python

import sys
from logging.handlers import WatchedFileHandler

from bottle import Bottle, run
from succubus import Daemon
from requestlogger import WSGILogger, ApacheFormatter


app = Bottle()


@app.route('/')
def root():
    return 'hello succubus'


handlers = [WatchedFileHandler('succubus.log')]
app = WSGILogger(app, handlers, ApacheFormatter())


class MyDaemon(Daemon):
    def run(self):
        run(app, host='localhost', port=55555, quiet=True)


def main():
    daemon = MyDaemon(pid_file='succubus.pid')
    sys.exit(daemon.action())


if __name__ == '__main__':
    main()

The problem was, that bottle always logs to the console, i.e. stdout, which is troublesome, since that file is closed during daemonization...