supervisor 使 celery后台运行

 

1.安装 supervisor
pip install supervisor 
2.创建supervisor配置文件,命令如下:
进入项目文件

echo_supervisord_conf > supervisord.conf
vim supervisord.conf
在末尾输入:
[program:celeryd]  # 进程的名字
command
=/opt/python/bin/celery worker -A worker --loglevel=info stdout_logfile=/django/celery/celeryd.log stderr_logfile=/django/celery/celeryd.log autostart=true autorestart=true startsecs=10 stopwaitsecs=600
[program: ProjectName]
command=dotnet ProjectName.dll ; 运行程序的命令
directory=/root/Publishing/PublishOutput/ ; 命令执行的目录
autorestart=true ; 程序意外退出是否自动重启
autostart=true ; 是否自动启动
stderr_logfile=/var/log/ProjectName.err.log ; 错误日志文件
stdout_logfile=/var/log/ProjectName.out.log ; 输出日志文件
environment=ASPNETCORE_ENVIRONMENT=Production ; 进程环境变量
user=root ; 进程执行的用户身份
stopsignal=INT
startsecs=1 ; 自动重启间隔 

在Django 目录下执行 

supervisord

supervisorctl 命令

在启动后台执行之后,可以使用supervisorctl命令查看后台的日志信息,以及重启服务。

$ supervisorctl tail celeryd # 查看最后的日志
$ supervisorctl tail -f celeryd # 持续
$ supervisorctl restart celeryd
$ supervisorctl status celeryd
$ supervisorctl start celeryd
$ supervisorctl stop celeryd
3.supervisorctl查看和停止supervisor的状态: 报错后可查看 /django/celery/celeryd.log
supervisorctl status # 查看状态 reread # 读取配置信息 update # 加载最新的进程 stop # 停止进程 start # 启动进程 reload # 重新加载配置
 
 
 
posted @ 2020-10-14 13:17  小学弟-  阅读(272)  评论(0编辑  收藏  举报