背景:
由于某中间件只有单机环境,且发生过异常中断的情况,所以现在安装supervisor来监控并自动启动进程
安装:
1:easy_install 安装:
easy_install supervisor
2:pip 安装:
pip install supervisor
3:Debian / Ubuntu可以直接通过apt安装:
apt-get install supervisor
配置:
如果使用easy_install安装的话,/etc/supervisord.conf是不存在的,所以使用
echo_supervisord_conf > /etc/supervisord.conf
然后我们开始编辑该文件
vi /etc/supervisord.conf
这里由于我们只需要控制一个进程,所以直接在此文件中修改
在文件最后最后加上,这里以redis为例
[program:redisd]
command=/opt/redis-4.0.10/src/redis-server /opt/redis-4.0.10/redis.conf
stdout_logfile=/opt/redis-4.0.10/redis_supervisor.log
autostart=true
autorestart=true
startsecs=3
program:redisd表示用redisd来命名redis这个进程
command 启动命令
stdout_logfile 日志输出
autostart=true supervisor启动时该进程自动启动
autorestart=true 该进程挂掉后自动重启
startsecs=3 启动多少秒之后还是running认为是启动成功
如果需要管理的子进程很多,建议修改
[include]
files = /etc/supervisor/*.conf
然后我们就可以新建/etc/supervisor文件夹,在该文件夹下添加不同的.conf配置文件来管理不同的子进程
例:
vi /etcsupervisor/redisd.conf
[program:redisd]
command=/opt/redis-4.0.10/src/redis-server /opt/redis-4.0.10/redis.conf
stdout_logfile=/opt/redis-4.0.10/redis_supervisor.log
autostart=true
autorestart=true
startsecs=3
启动:
apt-get install 安装的supervisor直接可以通过 /etc/init.d/supervisor 运行:
/etc/init.d/supervisor start
通过easy_install 安装的supervisor运行supervisord 运行:
supervisord
子进程管理:
查看所有子进程的状态:
# supervisorctl status redisd RUNNING pid 4917, uptime 0:20:20
关闭、开启指定的子进程:
# supervisorctl stop redisd redisd: stopped # supervisorctl start redisd redisd: started
关闭、开启所有的子进程:
# supervisorctl stop all redisd: stopped # supervisorctl start all redisd: started