Supervisor

7 Notes
+ After installation and providing the config files...! (Nov. 21, 2014, 8:27 p.m.)

After installation, and providing the configuration files, run these commands: 1-supervisord (to start the daemon) 2-supervisorctrl reread 3-supervisorctrl update 4-supervisorctrl start <name_of_program (inside the config file, the first line)> or start all (to run all the programs).

+ Good Tutorial Websites (Nov. 19, 2014, 7:34 p.m.)

https://www.digitalocean.com/community/tutorials/how-to-install-and-manage-supervisor-on-ubuntu-and-debian-vps

+ One-Time Scripts (Nov. 19, 2014, 7:33 p.m.)

One-Time Scripts I've found that Supervisor also works great for running commonly used scripts that have multiple parameters or large log files. Be sure to set autostart and autorestart in the conf file to false, so your script doesn't end up running repeatedly. Examples MongoDB [program:mongod_member] command=/home/ubuntu/mongodb-linux-x86_64-2.0.6/bin/mongod --dbpath /mnt/mongo/ --replSet mongo5 --nojournal directory=/home/ubuntu stdout_logfile=/mnt/log/mongod.log redirect_stderr=true

+ Web Interface (Nov. 19, 2014, 7:32 p.m.)

Supervisor provides a really nifty web interface to monitor and restart your processes. Just update the following file, restart supervisor, and you'll see it on port 9001. Feel free to change the port and protect it using HTTP Auth or whatever you see fit. Add the following to /etc/supervisor/supervisord.conf [inet_http_server] port=*:9001

+ Using SupervisorCTL (Nov. 19, 2014, 7:27 p.m.)

SupervisorCTL is the tool you will use to manage everything in Supervisor. Start by running sudo supervisorctl and then typing reread. The reread command goes through the conf.d directory and loads any new program conf files. Once you see the new test_python program available, you can use the add command to load and start it (add test_python). The status command shows you all running processes, their PID and how long they've been running. Here is a short list of my commonly used supervisorctl commands and what they do. reread - Reload all program conf files from the conf.d directory. add [program_name] - Add a newly created conf file to Supervisor and start the process. status - Check the status of all programs currently managed by Supervisor. start [program_name] - Start the given program. Used often with one-time scripts. restart [program_name] - Restart the given program. tail -f [program_name] - Watch the log file in real-time (same as UNIX tail -f [filename]). help - List all available commands. Exit supervisorctl and check your log file (~/test_python_output.txt) to see that it is still running. If it isn't, you may have missed a step.

+ Introduction and Installation (Nov. 19, 2014, 7:23 p.m.)

http://reustle.io/blog/managing-long-running-processes-with-supervisor ------------------------------------------------------------ Supervisor is a great tool to start and manage long-running processes and the log files associated with them. It offers a lot of helpful features and is easy to get up and running. ------------------------------------------------------------ Install & Start Supervisor apt install supervisor OR pip install supervisor ------------------------------------------------------------ Our First Program Supervisor looks for configuration files in /etc/supervisor/conf.d/ and it is a good idea to keep a single conf file per process. To start, let's set up a simple long-running python script. Don't pay too much attention to the contents of the conf file, we'll go over that later. Create /etc/supervisor/conf.d/test_python.conf containing: [program:test_python] command=python -u test.py directory=/home/ubuntu stdout_logfile=/home/ubuntu/test_python_output.txt redirect_stderr=true ------------------------------------------------------------ Create ~/test.py containing: import time while True: print(time.ctime()) time.sleep(1) When creating the conf file, be sure to replace /home/ubuntu both times with the path to your home directory (~ isn't allowed). If you run test.py manually you'll see it prints out the time once per second. ------------------------------------------------------------