Supervisor: Difference between revisions
From Wildsong
Jump to navigationJump to search
Brian Wilson (talk | contribs) Created page with "http://supervisord.org Q1. ''How do I set up a Python script so that I can easily start and stop it and monitor whether it's crashed?'' Q2. Can I start multiple instances of..." |
Brian Wilson (talk | contribs) mNo edit summary |
||
Line 19: | Line 19: | ||
sudo mkdir /etc/supervisor | sudo mkdir /etc/supervisor | ||
echo_supervisord_conf | sudo tee /etc/supervisor/supervisord.conf | echo_supervisord_conf | sudo tee /etc/supervisor/supervisord.conf | ||
/etc/defaults/supervisor: | |||
DAEMON_OPTS="-c /etc/supervisor/supervisord.conf" | |||
Change ip/port number | |||
=== Do nothing test script === | === Do nothing test script === |
Revision as of 21:33, 31 March 2014
Q1. How do I set up a Python script so that I can easily start and stop it and monitor whether it's crashed?
Q2. Can I start multiple instances of the same script each with a different configuration?
Q3. Is Supervisor the answer?
Installation
% sudo easy_install supervisor
is better than
% sudo apt-get install supervisor
Configuration
sudo mkdir /etc/supervisor echo_supervisord_conf | sudo tee /etc/supervisor/supervisord.conf
/etc/defaults/supervisor: DAEMON_OPTS="-c /etc/supervisor/supervisord.conf"
Change ip/port number
Do nothing test script
Here is a script that will log to the system log, and sleep for 10 minutes. It handles control-C exit.
#/usr/bin/python import time, logging, logging.handlers logging.basicConfig(level=logging.INFO) log = logging.getLogger(__name__) handler = logging.handlers.SysLogHandler(address='/dev/log') log.addHandler(handler) log.info("Start doing nothing.") forever = True try: while forever: log.info("MARK") time.sleep(60 * 10) except KeyboardInterrupt: log.info("Interrupt detected.") log.info("Completed successfully.") exit(0)