Supervisor1. Introduction
Supervisor is a process management tool written in Python that makes it easy to start, restart, and close processes (not just the Python process). In addition to controlling a single process, you can start and close multiple processes at the same time, such as unfortunate server problems that cause all applications to be killed, and you can start all applications with supervisor at the same time instead of one by one.
2. Installation
The following two methods of installation are available:
3. Configuration
Build configuration file
# echosupervisordconf >/etc/supervisord.conf
Change the configuration file, here to Tomcat,ismsrvDebug as an example
# vim/etc/supervisord.conf
# program Configuration
[Program:tomcat]
directory =/opt/tomcatApp/bin; Startup directory of the program
Command = SH startup.sh; Start command, you can see the same as the command that is started manually on the command line
Autostart = true; It starts automatically when the Supervisord is started.
Startsecs = 10; No exception exits after 10 seconds of startup, as if it had started normally.
AutoRestart = true; Automatic restart after program exits unexpectedly
Startretries = 3; Startup failed auto Retry number, default is 3
user = root; With which user to start
redirectstderr = true; redirect stderr to stdout, default false
StdOutlogfilemaxbytes = 20MB; StdOut log file size, default 20MB
StdOutLogFilebackups = 20; StdOut number of log file backups
StdOutlogfile =/opt/supervisor-3.1.3/super.log; StdOut log file, be aware that it does not start properly when the specified directory does not exist, so you need to create the directory manually (Supervisord automatically creates the log file)
; environment = Pythonpath= $PYTHONPATH:/opt/mypy
Change the Tomcat configuration
Processes that use Supervisord monitoring management must start with Nodaemon, which is not a daemon daemon. The startup.sh script for Tomcat is daemon, so the configuration file needs to be changed.
# vim/opt/tomcat_app/bin/startup.sh
(change start to run)
Exec "$PRGDIR"/"$EXECUTABLE" Run "[email protected]"
4. Start
# supervisord-c/etc/supervisord.conf Start Supervisor
# Supervisorctl Status View state
# supervisorctl Reload Reload config file
# Supervisorctl Start Tomcat startup Project
# Supervisorctl Stop Tomcat Close Project
# supervisorctl Restart Tomcat Restart Project
5. Verification
# Ps-ef | grep Tomcat view, Tomcat not started
# Launch Supervisor # Ps-ef | When grep tomcat supervisor starts, Tomcat will also start
# Simulate kill Tomcat process.
# Ps-ef | grep Tomcat View will find that Tomcat is automatically pulled up and the process number has changed
6. Note
It is possible to write all the configuration items into the supervisord.conf file, but it is not recommended to do so, but to write different programs (groups) into different configuration files by using the Include method. We created a new directory/etc/supervisor/for these configuration files.
# vim/etc/supervisord.conf
[include]
Files =/etc/supervisor/*.conf
Create Profile Management program.
A configuration file requires at least one configuration of the [program:x] section to tell Supervisord that the process needs to be managed.
Supervisor Process Management Tools