安装supervisor
# ubuntu
apt-get install -y supervisor
# centos
yum install -y supervisor
# alpha
apk add supervisor
# 使用pip
pip install supervisor
# easy_install
easy_install supervisor
# 生成默认配置文件
echo_supervisord_conf > /etc/supervisor/supervisord.conf
# 修改/etc/supervisor/supervisord.conf
[include]
files = /etc/supervisor/conf.d/*.conf
子进程配置
# /etc/supervisor/conf.d/php.conf
[program: php]
command=php-fpm -y /user/local/etc/php/etc/fpm.confp; 被监控的进程路径
priority=1 ; 数字越高,优先级越高 默认值999
numprocs=1 ; 启动几个进程 默认值1
autostart=true ; 随着supervisord的启动而启动
startsecs=10 ; 启动10秒后没有异常退出,就表示进程正常启动了,默认为1秒
autorestart=true ; 程序退出后自动重启, 可选值:[unexpected,true,false],默认为unexpected,表示进程意外杀死后才重启
startretries=10 ; 启动失败时的最多重试次数 默认是3
exitcodes=0 ; 正常退出代码
stopsignal=KILL ; 用来杀死进程的信号
stopwaitsecs=10 ; 发送SIGKILL前的等待时间
redirect_stderr=true ; 重定向stderr到stdout
常用命令
supervisorctl status //查看所有进程的状态
supervisorctl stop php-fpm //停止php-fpm
supervisorctl start php-fpm //启动php-fpm
supervisorctl restart php-fpm //重启php-fpm
supervisorctl restart all //重启所有进程
supervisorctl update //配置文件修改后使用该命令加载新的配置
supervisorctl reload //重新启动配置中的所有程序