supervisord 管理非daemon启动方式软件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了supervisord 管理非daemon启动方式软件相关的知识,希望对你有一定的参考价值。
1.安装 supervisord pip install supervisor
如果提示pip 不存在情况
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
2.配置supervisord 以及启动
mkdir -p /data/etc/supervisor/confs
cd /data/etc/supervisor/
在此配置supersord.conf 文件用来启动supervisord控制程序。
cat /data/etc/supervisor/supervisord.conf
[unix_http_server]
file = /var/run/supervisord.sock
chmod = 0777
chown= root:root ; 设置sock用户 如果想普通用户能访问则需要设置为普通用户
[inet_http_server]
port=127.0.0.1:9001
[supervisorctl]
serverurl = unix:///var/run/supervisord.sock
[supervisord]
logfile = /data/logs/supervisor/supervisord.log ;supervisord 运行日志
logfile_maxbytes = 50MB
logfile_backups = 20
loglevel = info
pidfile = /tmp/supervisor.pid
nodaemon = false
minfds = 1024
minprocs = 200
user = root ;启动supervisord 用户
childlogdir = /data/logs/supervisor/ ;设置主日志文件位置
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[include]
files = /data/etc/supervisor/confs/*.conf ;读取用户配置文件位置
到此supervisord主程序配置完成( 启动前删除 # 和中文说明)。使用
supervisord -c /data/etc/supervisor/supervisord.conf
命令就可以启动supervisord
3.添加非 daemon程序
进入 supervisord.conf 中配置的 files 目录 /dada/etc/supervisor/confs
cd /data/etc/supervisor/confs
cat first.conf
[program:tg_robot]
environment=PYTHONPATH="/data/app/tg_robot/src:$PYTHONPATH"
directory=/data/app/tg_robot/src/
command=/home/yunsm/.local/bin/gunicorn -c gunicorn_app.py app:app
autostart=true ; start at supervisord start (default: true)
autorestart=true ; retstart at unexpected quit (default: true)
startsecs=10 ; number of secs prog must stay running (def. 10)
startretries=3 ; max # of serial start failures (default 3)
user=yunsm ; setuid to this UNIX account to run the program
redirect_stderr=true
stdout_logfile=/data/logs/supervisor/tg_robot.log ; child log path, use NONE for none; default AUTO
stdout_logfile_maxbytes=20MB ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=20 ; # of logfile backups (default 10)
stopasgroup=true
killasgroup=true
还有一些类似mysql的特殊程序,supervisor 只能管关闭supervisor启动的子进程,类似mysql这样自己启动的子进程的程序就需要使用上 pidproxy 和pid文件文件了。下面举个mysql启动的例子
[program:mysql]
command=/usr/local/python27/bin/pidproxy /usr/local/mysql/var/localhost.localdomain.pid /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/var
autostart=true ; start at supervisord start (default: true)
autorestart=true ; retstart at unexpected quit (default: true)
startsecs=10 ; number of secs prog must stay running (def. 10)
startretries=3 ; max # of serial start failures (default 3)
user=root ; setuid to this UNIX account to run the program
redirect_stderr=true
stdout_logfile=/data/logs/supervisor/mysql.log ; child log path, use NONE for none; default AUTO
stdout_logfile_maxbytes=20MB ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=20 ; # of logfile backups (default 10)
stopasgroup=true
killasgroup=true
配置好了需要启动的进程之后,可以使用以下命令
supervisorctl update 加载supervisord 子程序
supervisorctl start mysql 使用supervisord 启动mysql
supervisorctl status 查看supervisord 启动程序状态
supervisorctl stop mysql 停止mysql
以上是关于supervisord 管理非daemon启动方式软件的主要内容,如果未能解决你的问题,请参考以下文章