How to configure Python Script to run as a daemon
8,109
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
Related videos on Youtube
Author by
Ace
Updated on September 18, 2022Comments
-
Ace over 1 year
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?
-
Ace about 11 yearsDocumentation for supervisord for my distro (ubuntu) is full of holes, but with a bit of troubleshooting wasnt too hard to figure out. @EEAA , your solution was exactly the solution i was looking for, it works great! thank you for your help, i would upvote, but i do not have the reputation to do so.
-
EEAA about 11 years@Ace - excellent, glad to be of help.
-
Jan Xavier almost 9 yearsPerfect except I needed to add
start
to the command: command = /usr/bin/python /dati/bin/watcher.py start