1.参考博客
2.具体操作步骤
1.下载模块
pip3 install supervisor
2.查看版本
pip3 list | grep su
3.建立软连接(可不用操作)
3.1这时候使用pip的安装方式其实并没有设置好supervisor的环境变量,还需要查看一下supervisor安装后的二进制可执行文件在哪里。
搜索在 / 目录下,前后模糊查询名称为 supervi 的文件,如下:
find / -name "*supervi*" -ls | grep python3 | grep bin
3.2将supervisorctl、echo_supervisord_conf 和 supervisord 添加软链到执行目录下/usr/bin
ln -s /usr/local/python3/bin/echo_supervisord_conf /usr/bin/echo_supervisord_conf
ln-s /usr/local/python3/bin/supervisord /usr/bin/supervisord
ln-s /usr/local/python3/bin/supervisorctl /usr/bin/supervisorctl
实际示例
4.配置启动文件
4.1进入django项目(如大luffy)
4.2配置文件编辑
1.我们可以使用echo_supervisord_conf命令得到supervisor配置模板,打开终端执行如下Linux shell命令:
echo_supervisord_conf>supervisord.conf2.该命令输出文件到当前目录下(当然,你也可以指定绝对路径到具体位置),文件名为supervisord.conf。
再使用vim命令打开该文件并编辑:
vim supervisord.conf
注意编辑文件时里面的内容不要清空
[program:celery.worker]
;指定运行目录
directory=/home/project/airapi
;运行目录下执行命令(注意要把虚拟环境带上)
command=/home/dev/.virtualenvs/aqivir/bin/celery worker -A celery_task -l info
;启动设置
numprocs=1;进程数
autostart=true ;当supervisor启动时,程序将会自动启动
autorestart=true ;自动重启
;停止信号,默认TERM
;中断:INT (类似于Ctrl+C)(kill -INT pid),退出后会将写文件或日志(推荐)
;终止:TERM (kill-TERM pid)
;挂起:HUP (kill-HUP pid),注意与Ctrl+Z/kill -stop pid不同
;从容停止:QUIT (kill-QUIT pid)
stopsignal=INT
;输出日志
stdout_logfile=/home/project/airapi/celery_task/celery_worker.log
stdout_logfile_maxbytes=10MB ;默认最大50M
stdout_logfile_backups=10;日志文件备份数,默认为10
;错误日志
redirect_stderr=false ;为true表示禁止监听错误
stderr_logfile=/home/project/airapi/celery_task/celery_worker.log
stderr_logfile_maxbytes=10MB
stderr_logfile_backups=10[program:celery.beat]
;指定运行目录
directory=/home/project/airapi
;运行目录下执行命令(虚拟环境)
command=/home/dev/.virtualenvs/aqivir/bin/celery beat -A celery_task -l info
;启动设置
numprocs=1;进程数
autostart=true ;当supervisor启动时,程序将会自动启动
autorestart=true ;自动重启
;停止信号
stopsignal=INT
5.启动(注意路径)
supervisord -c supervisord.conf
如果没有报错就没有问题
6.其他命令
1.关闭
supervisorctl-c supervisord.conf shutdown2.重启
supervisorctl-c supervisord.conf reload