Supervisor 使用及常用配置
参考链接
官网: http://supervisord.org/
参考: https://www.cnblogs.com/toutou/p/supervisor.html
https://www.jianshu.com/p/0b9054b33db3
安装
pip3.8 install supervisor
ln -s /usr/local/python3.8/bin/supervisord /usr/local/bin/supervisord
ln -s /usr/local/python3.8/bin/supervisorctl /usr/local/bin/supervisorctl
ln -s /usr/local/python3.8/bin/echo_supervisord_conf /usr/local/bin/echo_supervisord_conf
echo_supervisord_conf >/etc/supervisord.conf
编辑配置文件
vim /etc/supervisord.conf
1、修改supervisord日志目录
2、添加program,例如:
[program:grpc_python]
command=/data/dascmdb-venv/bin/python3.8 mysql_server.py ; the program (relative uses PATH, can take args)
directory=/data/hc/daascmdb/grpc_python/server/mysql ; directory to cwd to before exec (def no cwd)
autostart=false ; start at supervisord start (default: true)
startsecs=1 ; # of secs prog must stay up to be running (def. 1)
startretries=3 ; max # of serial start failures when starting (default 3)
autorestart=unexpected ; autorestart if exited after running (def: unexpected)
redirect_stderr=true ; redirect_stderr=true is not allowed for eventlisteners
stdout_logfile=/opt/logs/daascmdb/daascmdbops/grpc_python.log ; stdout log path, NONE for none; default AUTO
stdout_logfile_maxbytes=5MB ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=10 ; # of stdout logfile backups (0 means none, default 10)
常用命令
开启命令
supervisor的服务器端部分启动命令:
sudo unlink /var/run/supervisor.sock
supervisord -c /etc/supervisor/supervisord.conf
此时默认开启了所有服务
supervisor的客户端部分命令:
supervisorctl status 查看进程运行状态
supervisorctl start 进程名 启动进程
supervisorctl stop 进程名 关闭进程
supervisorctl restart 进程名 重启进程
supervisorctl update 重新载入配置文件
supervisorctl shutdown 关闭supervisord
supervisorctl clear 进程名 清空进程日志
supervisorctl 进入到交互模式下。使用help查看所有命令。
start stop restart + all 表示启动,关闭,重启所有进程。
关闭命令
supervisorctl stop all先关闭supervisor服务
之后再关闭supervisord服务
ps -ef | grep supervisord
kill -9 pid