Eli's Blog

1. 安装

1
2
3
4
5
6
7
8
9
10
su - root
pip3 install supervisor

/usr/local/python37/bin/echo_supervisord_conf > /etc/supervisord.conf

#supervisord -c /etc/supervisord.conf

ln -s /usr/local/python37/bin/supervisord /usr/bin/supervisord

ln -s /usr/local/python37/bin/supervisorctl /usr/bin/supervisorctl

2. 修改配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
mkdir -p /etc/supervisord.conf.d

vi /etc/supervisord.conf

[unix_http_server]
;file=/tmp/supervisor.sock ; the path to the socket file
file=/var/run/supervisor.sock ;

[supervisord]
;logfile=/tmp/supervisord.log ; main log file; default $CWD/supervisord.log
logfile=/var/log/supervisord.log ;

;pidfile=/tmp/supervisord.pid ; supervisord pidfile; default supervisord.pid
pidfile=/var/run/supervisord.pid ;

[supervisorctl]
;serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket
serverurl=unix:///var/run/supervisor.sock ;

[include]
files = /etc/supervisord.conf.d/*.conf

3. 开机启动

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
vi /usr/lib/systemd/system/supervisord.service

[Unit]
Description=Supervisor daemon

[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf
ExecStop=/usr/bin/supervisorctl shutdown
ExecReload=/usr/bin/supervisorctl reload
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target

4. 系统管理

1
2
3
4
5
systemctl enable supervisord

systemctl start supervisord

ps -ef | grep supervisor

5. 新增配置

5.1 webhhok

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
vi /etc/supervisord.conf.d/webhook.conf 

[program:webhook]
user=utime
directory=/tmp/
command=webhookit -c /etc/webhook/config.py -p 18340
autostart=true
autorestart=true
startretries=10
exitcodes=0
stopsignal=KILL
stopwaitsecs=10
redirect_stderr=true
stdout_logfile=/var/log/webhook-out.log
stdout_logfile_maxbytes=100MB
stdout_logfile_backups=5
stderr_logfile=/var/log/webhook-error.log
stderr_logfile_maxbytes=100MB
stderr_logfile_backups=5

5.2 业务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
vi /etc/supervisord.conf.d/lp-service.conf

[program:lp-service]
command=/home/utime/.venv/py3/bin/gunicorn -b 127.0.0.1:20002 --worker-class eventlet -w 4 manage:app --access-logfile /tmp/lp-service-gunicorn.log
autostart=true
autorestart=true
directory=/home/utime/lp-service/
user=utime
stdout_logfile=/var/log/lp-service-stdout.log
stdout_logfile_maxbytes=100MB
stdout_logfile_backups=5
stderr_logfile=/var/log/lp-service-stderr.log
stderr_logfile_maxbytes=100MB
stderr_logfile_backups=5
environment=LP_ENV="development"

6. 启动

1
2
3
supervisorctl update

supervisorctl status