supervisor基本命令以及常见报错

一:基本命令

reread ;重新加载配置文件
update ;将配置文件里新增的子进程加入进程组,如果设置了autostart=true则会启动新新增的子进程
status ;查看所有进程状态
status ;查看指定进程状态
start all; 启动所有子进程
start ; 启动指定子进程
restart all; 重启所有子进程
restart ; 重启指定子进程
stop all; 停止所有子进程
stop ; 停止指定子进程
reload ;重启supervisord
add ; 添加子进程到进程组
reomve ; 从进程组移除子进程,需要先stop。注意:移除后,需要使用reread和update才能重新运行该进程

 

二:子程序相关配置

[program:capital-balance] :配置文件必须包括至少一个program,x是program名称,必须写上,不能为空
directory = /Library/WebServer/Documents/project ;执行子进程时supervisord暂时切换到该目录
command = /bin/bash -c ‘./yii 执行的命令’ ;包含一个命令,当这个program启动时执行
autostart = true
startsecs = 5
autorestart = true
startretries = 3;进程从STARING状态转换到RUNNING状态program所需要保持运行的时间(单位:秒)
user = user
process_name=%(program_name)s_%(process_num)002d ;当numprocs大于1是需要使用这个
numprocs=2
redirect_stderr = true;如果是true,则进程的stderr输出被发送回其stdout文件描述符上的supervisord
stdout_logfile_backups = 20;要保存的stdout_logfile备份的数量
stdout_logfile=/Library/WebServer/Documents/capital/backend/runtime/logs/supervisor/testPopQueue.log;将进程stdout输出到指定文件
stdout_logfile_maxbytes=10MB;stdout_logfile指定日志文件最大字节数,默认为50MB,可以加KB、MB或GB等单位
stderr_logfile=/Library/WebServer/Documents/capital/backend/runtime/logs/supervisor/testPopQueue-err.log
stderr_logfile_maxbytes=10MB

三:常见错误

1、Error: %(process_num) must be present within process_name when numprocs > 1 in section ‘program:capital-balance’ (file: ‘/usr/local/etc/supervisor.d/logstash.ini’)

For help, use /usr/local/bin/supervisord -h
;当numprocs为1时,process_name=%(program_name)s
;当numprocs>=2时,%(program_name)s_%(process_num)02d
process_name=%(program_name)s

2、直接运行 supervisorctl status 报:

Error: Server requires authentication
For help, use /usr/local/bin/supervisorctl -h
因为你设置访问账号密码,所以只能先supervisorctl进去,在status,其他命令也如此;

3、supervisord -c /usr/local/etc/supervisord.ini报:

Error: Another program is already listening on a port that one of our HTTP servers is configured to use. Shut this program down first before starting supervisord.
For help, use /usr/local/bin/supervisord -h
因为9001获取其他你设置的端口被占用了,你可以先lsof -i:9002 kill:pid再重新执行该命令就可以了;

4、启动脚本时报:

error: <class ‘socket.error’>, [Errno 2] No such file or directory: file: line: 1
这个可能有多种原因,可能是已经启动过了也可能是没权限,解决步骤如下:

    1. 先要确认是否已经启动过了:’ps -ef | grep supervisord’
    2. 如果有的话先kill掉
    3. 运行下面命令:
      sudo touch /var/run/supervisor.sock
      sudo chmod 777 /var/run/supervisor.sock
    4. 再尝试重新启动:supervisord -c /etc/supervisord.conf(如果没有文件找个别人的配置拷贝过来或者运行echo_supervisord_conf > /etc/supervisord.conf)
5、Error: .ini file does not include supervisorctl section
  1. 先确保supervisord.conf中有[supervisord],[supervisorctl]有这两个基本模块,还有[program:XXX]自己程序的配置(可以在supervisord.conf也可以在/etc/supervisor/*.ini中)
  2. 最关键的两个命令:chmod +x /usr/bin/supervisord
    chmod +x /usr/bin/supervisorctl
    chmod +x /etc/supervisord.conf主要是把把相关文件都授权了
  3. 把supervisord杀掉后再次启动supervisord
6、Exited too quickly (process log may have details)
    1. 先确认[program:XXX]中自己的程序的command=<启动命令>和 directory=<运行命令的路径>没有问题,python是不是用的自己要的环境的python(比如虚拟环境的),log文件的文件夹是不是已经创建(没创建的话supervisor没权限生成log文件),以及改log文件是不是授权给所有用户了(可参考前面的解决办法chmod +x aaaaa.log)
    2. 确保用上面的配置中的command在指定路径可以直接运行不会报错,这时候一般就不会有什么问题了。这时候tail你自己的log文件一般就能看到log信息,启动失败报错的信息也会在你的log文件中,照着解决后supervisorctl reload就好了。
    3. 如果上面的命令确保可以跑,但还是没法正常运行,也看不到自己程序的报错(不然你就能根据报错解决问题了),那么恭喜,你遇到了跟我一样的情况。我的解决办法很诡异,尝试把[program:XXX]中的名字换成了一个跟启动命令不一样的另一个名字(不要太短),reload之后居然就可以跑了。。。。嗯,很不合常理,但是对我来说确实管用了。

 

 

文章来源于:https://blog.csdn.net/qq_38234594/article/details/89923583

 

posted @ 2021-01-13 15:01  虞岩  阅读(1094)  评论(0编辑  收藏  举报