python测试开发django之使用supervisord 后台启动celery 服务(worker/beat)
作者:上海-悠悠 发布时间:2023-10-14 05:55:53
前言
Supervisor(‘http://supervisord.org/’)是用Python开发的一个client/server服务,是Linux/Unix系统下的一个进程管理工具,不支持Windows系统。
它可以很方便的监听、启动、停止、重启一个或多个进程。
用Supervisor管理的进程,当一个进程意外被杀死,supervisort监听到进程死后,会自动将它重新拉起,很方便的做到进程自动恢复的功能,不再需要自己写shell脚本来控制。
环境准备
centos 安装 supervisord
yum install -y supervisord
debian 安装 supervisord
apt-get install -y supervisor
supervisord.conf
安装完成后在/etc/supervisor
目录下会有个配置文件 supervisord.conf
# cd /etc/supervisor
/etc/supervisor# ls
conf.dsupervisord.conf
cat 查看内容
# cat supervisord.conf
; supervisor config file
[unix_http_server]
file=/var/run/supervisor.sock ; (the path to the socket file)
chmod=0700 ; sockef file mode (default 0700)
[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/var/log/supervisor ; ('AUTO' child log dir, default $TEMP)
; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket
; The [include] section can just contain the "files" setting. This
; setting can list multiple files (separated by whitespace or
; newlines). It can also contain wildcards. The filenames are
; interpreted as relative to this file. Included files *cannot*
; include files themselves.
[include]
files = /etc/supervisor/conf.d/*.conf
在项目中我们需要用到此配置,可以在项目根目录导出一份
echo_supervisord_conf > ./supervisord.conf
文件内容编写
supervisord.conf文件内容编写, 前面内容不用改,直接接着在后面写
比如我需要后台启动celery的worker和beat服务
; Sample supervisor config file.
;
; For more information on the config file, please see:
; http://supervisord.org/configuration.html
; 前面文档省略,不用删,接着后面写
[program:celery-worker]
command=celery -A hrun2_web worker -l info ; 管理命令,supervisor不支持后台进程
process_name=%(program_name)s
#user=root ;进程启动用户
autostart=true ;是否随supervisor启动
autorestart=true ;是否在挂了之后重启,意外关闭后会重启,比如kill掉!
startretries=3 ;启动尝试次数
stderr_logfile=./celery_worker.log ;标准输出文件
stdout_logfile=./celery_worker.log ;标准输出文件
loglevel=info ;日志的级别
[program:celery-beat]
command=celery -A hrun2_web beat ; 管理命令,supervisor不支持后台进程
process_name=%(program_name)s
#user=root ;进程启动用户
autostart=true ;是否随supervisor启动
autorestart=true ;是否在挂了之后重启,意外关闭后会重启,比如kill掉!
startretries=3 ;启动尝试次数
stderr_logfile=./celery_beat.log ;标准输出文件
stdout_logfile=./celery_beat.log ;标准输出文件
loglevel=info ;日志的级别
启动服务
启动服务
supervisord -c /path/supervisord.conf
关闭服务
supervisorctl shutdown
运行过程,启动没问题,不显示任何内容,如果需要关闭用shutdown
root@13107c465557:/code# supervisord -c ./supervisord.conf
root@13107c465557:/code# supervisorctl shutdown
Shut down
查看启动的服务
supervisorctl status
执行结果如下
root@13107c465557:/code# supervisorctl status
celery-worker RUNNING pid 234, uptime 0:00:14
celery-beat RUNNING pid 235, uptime 0:00:14
说明启动了celery和celery-beat两个服务
查看日志
我们在配置里面指定了./celery_worker.log
文件保存运行日志,所以可以直接查看这个文件
tail -f celery_worker.log -n 30
运行就可以看到worker运行的日志了
参考教程 https://www.jb51.net/article/146238.htm
来源:https://blog.csdn.net/qq_27371025/article/details/125855200


猜你喜欢
- 上次版本如果在没有找到轮廓或轮廓的点集数很小无法拟合椭圆或在RANSAC中寻找最优解时会死循环中,优化后的代码import cv2impor
- 一次性验证码,英文是 One Time Password,简写为 OTP,又称动态密码或单次有效密码,是指计算机系统或其他数字设备上只能使用
- 支付宝支付正式环境:用营业执照,申请商户号,appid测试环境:沙箱环境:https://openhome.alipay.com/platf
- 在前面的文章中介绍了如何用Python读写Excel数据,今天再介绍一下如何用Python修改Excel数据。需要用到xlutils模块。下
- 遇到这样一个情况想将变量v转化为[]string类型var v interface{}a := []interface{}{"1&
- IE的特殊性 IE的DOM元素属性与Firefox, Opera, Safari有些不同。在IE中,我们可以给DOM添加任意自定
- 本文实例讲述了Python爬虫框架scrapy实现的文件下载功能。分享给大家供大家参考,具体如下:我们在写普通脚本的时候,从一个网站拿到一个
- 说明本例子利用TensorFlow搭建一个全连接神经网络,实现对MNIST手写数字的识别。先上代码from tensorflow.examp
- server:#coding=utf-8from BaseHTTPServer import BaseHTTPRequestHandleri
- 本文实例讲述了Python基于Pymssql模块实现连接SQL Server数据库的方法。分享给大家供大家参考,具体如下:数据库版本:SQL
- (1)OracleServiceSID 数据库服务,这个服务会自动地启动和停止数据库。如果安装了一个数据库,它的缺省启动类型为自动。服务进程
- 起因看到网上的像素图片,感觉蛮有趣的,就打算用python一些PIL类库写一个。实现思路把一张图片分成多个块,每个块的颜色都等于这个色块中颜
- 在前面的博文中,我们介绍了如何通过软件模拟实现共享磁盘(https://www.jb51.net/network/592807.html),
- execjs 使用有了selenium+Chrome Headless 加载页面为什么还要用execjs来运行js?selenium+Chr
- 1. Anaconda1.1 Anaconda简介Anaconda是一个开源的python发行版本,是现在比较流行的python数据科学平台
- 一、问题描述 SQL Plus WorkSheet是一个窗口图形界面的SQL语句编辑器,对于那些喜欢窗口界面而不喜欢字符界面的用户,该工具相
- 2003年以来,网页的平均尺寸已经增长3倍。从2003到2008,网页的平均尺寸从93.7K增至312K,增幅233%。同时,在这5年之内,
- 可以加入以下3个参数 –without-debug --with-client-ldflags=--all-static,--w
- 用户习惯大家都经常在提,习惯源于何出?回答可以是软件的用户习惯源于其不断使用过程中的印象积累。如果是这个软件刚诞生的时候呢?于是就得参考同类
- 字符串常用方法# 去掉左右空格'hello world'.strip() # 'hello world&