1.使用 pip 安装 supervisor

1
pip install supervisor

2.安装完成后创建主配置文件

1
2
3
sudo mkdir -p /etc/supervisor
sudo touch /etc/supervisor/supervisord.conf
echo_supervisord_conf > /etc/supervisor/supervisord.conf

3.创建子配置文件

创建子配置文件夹/etc/supervisor/conf.d
/etc/supervisor/conf.d文件夹下添加子配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[program:ss_server]
command= *** #需要守护的启动命令
stopsignal=QUIT
autostart=true
autorestart=true
startsecs=10
startretries=36
stdout_logfile=*** #log文件位置
stdout_logfile_backups=10
stdout_logfile_maxbytes=10MB
stderr_logfile=*** #error_log文件位置
stderr_logfile_maxbytes=10MB
stderr_logfile_backups=10
loglevel=infoa

4.启动 supervisor

1
supervisord -c /etc/supervisord.conf

5.设置开机启动 supervisor

/usr/lib/systemd/system中创建supervisord.service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# supervisord service for systemd (CentOS 7.0+)
# by ET-CS (https://github.com/ET-CS)
[Unit]
Description=Supervisor daemon
[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown
ExecReload=/usr/bin/supervisorctl $OPTIONS reload
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target

激活开机启动命令

1
systemctl enable supervisord.service

其他 supervisor 命令

1
2
3
4
5
6
7
8
9
10
11
12
# 查看程序状态
supervisorctl status
# 关闭程序
supervisorctl stop
# 启动程序
supervisorctl start
# 重启程序
supervisorctl restart
# 更新程序
supervisorctl reread
# 重启配置文件修改的程序
supervisorctl update