This post is more a note for myself than anything else, but I wrote it here as it can also be useful for you. It explains how to daemonize a tornado application in three easy steps:
Install python-daemon
Add this import line at the beginning of my-app.py:
import daemon
- Add these 3 lines in the main() function, just before the
tornado.ioloop.IOLoop.instance().start()
:
log = open('tornado.' + str(port) + '.log', 'a+')
ctx = daemon.DaemonContext(stdout=log, stderr=log, working_directory='.')
ctx.open()
That's all folks.