Supervisor安装与使用
注:以Ubuntu为例,CentOS按照自身情况修改
-
安装
apt-get install supervisor # Ubuntu
yum install supervisor # CentOS
-
创建进程配置(CentOS目录名和文件后缀可能有变化)
cd /etc/supervisor/conf.d/
touch test.conf
-
配置详解
[program:test] #项目名(子进程名)
directory=/opt/bin #脚本目录
command= #执行脚本命令
autostart=true #随着supervisord的启动而启动
autorestart=true #自动重启
startsecs=1 #这个选项是子进程启动多少秒之后,此时状态如果是running,则我们认为启动成功了。默认值为1
user = test #脚本运行的用户身份
stderr_logfile=/tmp/python_test_stderr.log #错误日志
stdout_logfile=/tmp/python_test_stdout.log #日志
redirect_stderr = true #把stderr重定向到stdout,默认 false
stdout_logfile_maxbytes = 50M #stdout日志文件大小,默认 50MB
stdout_logfile_backups = 10 #stdout日志文件备份数
process_name=%(process_num)s #这个是进程名
numprocs=1 #启动进程的数目。当不为1时,就是进程池的概念,注意process_name的设置默认为1 。。非必须设置
-
Supervisor命令说明
supervisorctl status #查看所有进程的状态
supervisorctl stop test #停止test
supervisorctl start test #启动test
supervisorctl restart #重启test
supervisorctl update #配置文件修改后使用该命令加载新的配置
supervisorctl reload #重新启动配置中的所有程序