supervisor 文档

supervisor 是用 Python 开发的一个 C/S 服务。是 Linux/Unix 系统下的进程管理工具。它可以很方便的监听、启动、停止、重启一个或多个进程。用Supervisor管理的进程,当一个进程意外被杀死,supervisort监听到进程死后,会自动将它重新拉起,很方便的做到进程自动恢复的功能,不再需要自己写shell脚本来控制。

安装

pip 方式

pip install supervisor

yum 方式

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum install supervisor -y

配置文件

pip 安装的需自行生成配置文件

echo_supervisord_conf > /etc/supervisord.conf

cat /etc/supervisord.conf

[unix_http_server]
file=/opt/supervisor.sock   ; supervisorctl 使用的 socket 文件
chmod=0700                 ; socket 文件权限
;chown=nobody:nogroup       ; socket file uid:gid owner
;username=user              ; default is no username (open server)
;password=123               ; default is no password (open server)

[inet_http_server]         ; web 管理界面,即在页面做重启、停止等操作
port=*:9001                ; 监听端口
username=admin             ; 用户
password=123               ; 密码

[supervisord]
logfile=/var/log/supervisord.log ; supervisor日志文件 $CWD/supervisord.log
logfile_maxbytes=50MB        ; 日志文件大小,默认 50MB
logfile_backups=1           ; 默认保留1个文件
loglevel=info                ; 日志级别,默认info; 其他格式: debug,warn,trace
pidfile=/var/run/supervisord.pid ; pid 文件
nodaemon=false               ; 是否在前台运行,默认false,以 daemon模式运行
minfds=1024                  ; 可以打开文件描述符的最小值
minprocs=200                 ; 可以打开进程数最小值
;umask=022                   ; process file creation umask; default 022
;user=chrism                 ; default is current user, required if root
;identifier=supervisor       ; supervisord identifier, default is 'supervisor'
;directory=/opt              ; default is not to cd during start
;nocleanup=true              ; don't clean up tempfiles at start; default false
;childlogdir=/opt            ; 'AUTO' child log dir, default $TEMP
;environment=KEY="value"     ; key value pairs to add to environment
;strip_ansi=false            ; strip ansi escape codes in logs; def. false


[supervisorctl]
serverurl=unix:///opt/supervisor.sock ; use a unix:// URL  for a unix socket
;serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket
;username=chris              ; should be same as in [*_http_server] if set
;password=123                ; should be same as in [*_http_server] if set
;prompt=mysupervisor         ; cmd line prompt (default "supervisor")
;history_file=~/.sc_history  ; use readline history if available


[include]
files = /etc/supervisord.d/*.conf ;子文件

管理tomcat配置文件

cat /etc/supervisord.d/cms.conf

[program:cms]
command=/home/work/tomcat/cms-102/apache-tomcat-7.0.88/bin/catalina.sh run
environment=JAVA_HOME="/usr/local/jdk/",JAVA_BIN="/usr/local/jdk/bin"
stdout_logfile=/home/work/tomcat/cms-102/apache-tomcat-7.0.88/logs/catalina.out
autostart=true
autorestart=true
startsecs=5
priority=1
stopasgroup=true
killasgroup=true

执行

# supervisord -c /etc/supervisord.conf
# supervisorctl 
cms                              RUNNING   pid 12328, uptime 5:59:22
free-wifi                        RUNNING   pid 10534, uptime 6:31:34
government-services              RUNNING   pid 10475, uptime 6:31:34
idcard                           RUNNING   pid 13469, uptime 4:01:20

# supervisorctl restart cms
# supervisorctl start cms
# supervisorctl stop cms
原文地址:https://www.cnblogs.com/fsckzy/p/10750459.html