Nginx – How to configure Python Script to run as a daemon

daemonnginxUbuntu

I have a couple webservers sitting behind a loadbalancer, and i found "watcher.py" here: https://github.com/splitbrain/Watcher

I chose this script for several reasons: recursive through folders, lots of triggering options

Anyways, I will be using this to sync web content between load balanced servers. Is there a way to ensure that this script will run at bootup?

Best Answer

I've found the easiest way to handle applications like this is to install supervisord and then use that to start, monitor, and collect output from the your script.

Here's a sample supervisor config file:

[program:watcher]
command = /usr/bin/python /path/to/watcher.py
stdout_logfile = /var/log/watcher-stdout.log
stdout_logfile_maxbytes = 10MB
stdout_logfile_backups = 5
stderr_logfile = /var/log/watcher-stderr.log
stderr_logfile_maxbytes = 10MB
stderr_logfile_backups = 5