Supervisor is a good option when the Linux service needs to run reliably, and after the service exit, it needs to be restarted automatically and can monitor the status of the process, supervisor is a process manager developed in Python. The following is the installation configuration process.
1. Installing Supervisor
Easy_install Supervisor Setuptool Installation method
Apt-get Install Supervisor Debian/ubuntu Installation method
Yum Install Supervisor Redhat/centos installation method
2. Generate the default configuration file
echo_supervisord_conf >/etc/supervisord.conf
3. Modify the/etc/supervisord.conf configuration file
If you need to access the Web control interface, the Inet_http_server section is modified to
[Inet_http_server]
port=0.0.0.0:9001
Username=username; Your user name
Password=password; Your password.
4. Modify the startup script-add Supervisord to system service
#!/bin/sh
#
# Supervisor is a client/server system
# allows its users to monitor and control a
# Number of processes on unix-like operating
# systems.
#
# Chkconfig:-64 36
# Description:supervisor Server
# Processname:supervisord
# Source init functions
. /etc/init.d/functions
Retval=0
Prog= "Supervisord"
Pidfile= "/tmp/supervisord.pid"
Lockfile= "/var/lock/subsys/supervisord"
Start ()
{
Echo-n $ "Starting $prog:"
Daemon--pidfile $pidfile supervisord-c/etc/supervisord.conf
Retval=$?
Echo
[$RETVAL-eq 0] && Touch ${lockfile}
}
Stop ()
{
Echo-n $ "Shutting down $prog:"
Killproc-p ${pidfile}/usr/bin/supervisord
Retval=$?
Echo
If [$RETVAL-eq 0]; Then
Rm-f ${lockfile} ${pidfile}
Fi
}
Case "$" in
Start
start;;
stop) stop;;
Status
Status $prog;;
Restart
Stop
start;;
*)
echo "Usage: $ {start|stop|restart|status}";;
Esac
5. Assign permissions to boot
chmod +x/etc/init.d/supervisord
Chkconfig Supervisord on
Service Supervisord Start
At present all Supervisor Basic is done, then I am now using httpd to be managed test whether it can be started and accessed and will not self-start after exit.
6. Modify/etc/supervisord.conf at the end to add the following content
[Program:apache]
Command=/usr/local/apache/bin/httpd-d FOREGROUND
Autostart=true
Autorestart=true
Startsecs=3
User=root
7. Reload the configuration file if 80 ports are accessible
Service Supervisord Restart
The log shows normal:
Crit Supervisor running as root (no user in config file)
INFO RPC interface ' supervisor ' initialized
INFO RPC interface ' supervisor ' initialized
Crit Server ' unix_http_server ' running without any HTTP authentication checking
INFO daemonizing the Supervisord process
INFO Supervisord started with PID 4510
INFO spawned: ' Apache ' with PID 4512
INFO Success:apache entered RUNNING state, process have stayed up for > than 3 seconds (startsecs)
8. Testing Services
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/7E/F2/wKioL1cN9Y-wYshUAAAeux1DFhc223.png "title=" 1.png " alt= "Wkiol1cn9y-wyshuaaaeux1dfhc223.png"/>
9.supervisor Web test is showing normal
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7E/F5/wKiom1cN9Pryb6wTAACY_aruMrc574.png "title=" 2.png " alt= "Wkiom1cn9pryb6wtaacy_arumrc574.png"/>
10. Turn off the httpd to see if it can be self-starting.
/usr/local/apache/bin/apachectl stop manually shut down httpd
Watch the log stop and start up again:
Exited:apache (exit status 0; expected)
INFO spawned: ' Apache ' with PID 4640
INFO Success:apache entered RUNNING state, process have stayed up for > than 3 seconds (startsecs)
Another way of configuring files (this approach is good for multiple services):
1. Modify the configuration file vim/etc/supervisord.conf
[include]
; files = Relative/directory/*.ini
Modified to:
[include]
; files = Relative/directory/*.ini
Files =/etc/supervisord.conf.d/*.conf
2. Create a managed service configuration file
mkdir/etc/supervisord.conf.d/
cd/etc/supervisord.conf.d/
Vim apache.conf
[Program:apache]
Command=/usr/local/apache/bin/httpd-d FOREGROUND
Autostart=true
Autorestart=true
Startsecs=3
User=root
3. Common Commands
Supervisorctl start Apache
Supervisorctl Stop Apache
Supervisorctl status Apache
This article is from the "Wind Bo Fei" blog, please be sure to keep this source http://gloryxin.blog.51cto.com/10134758/1763451
Linux Daemon Manager Supervisor Installation configuration (use HTTPD to monitor processes)