from:http://www.liaoxuefeng.com/article/0013738926914703df5e93589a14c19807f0e285194fe84000
Linux Background Process management tool: Supervisor
Liaoche/Programming/ 2011-4-5 13:09/read: 7211
Linux background process has several methods, such as Nohup,screen, but, if it is a service program, to reliably run in the background, we need to make it daemon, it is best to monitor the status of the process, at the end of the accident can automatically restart.
Supervisor is a set of common process management programs developed with Python that can turn a normal command-line process into a background daemon and monitor the status of the process, which can be restarted automatically when the exception exits.
Installing Supervisor
Debian/ubuntu can be installed directly via apt:
# apt-get install supervisor
Then, write a configuration file for our own development application and let supervisor manage it. Each process configuration file can be split separately, placed in the/etc/supervisor/conf.d/directory, with. conf as the extension, for example, app.conf defines a gunicorn process:
[program:app]command=/usr/bin/gunicorn -w 1 wsgiapp:applicationdirectory=/srv/wwwuser=www-data
Where the process app is defined in [Program:app], command is the commands, directory is the current directory of the process, and user is the identity of the process running.
Restart supervisor, let the configuration file take effect, and then run the command supervisorctl start the process:
start app
To stop a process:
# supervisorctl stop app
If you want to use a variable on the command line, you need to write a shell script yourself first:
#!/bin/sh/usr/bin/gunicorn -w `grep -c ^processor /proc/cpuinfo` wsgiapp:application
Then, add the X permission, and then point the command to the shell script.
Supervisor also has a number of options, the default AutoRestart is unexpected (exception exit), refer to Supervisor documentation for details.
Go Linux Background Process management tool: Supervisor