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
![](https://www.aspxhome.com/images/zang.png)
![](https://www.aspxhome.com/images/jiucuo.png)
猜你喜欢
- 如果是在Oracle10g之前,删除一个表空间中的数据文件后,其文件在数据库数据字典中会仍然存在,除非你删除表空间,否则文件信息不会清除。但
- 开发背景是这样的:整个项目中使用很多台摩托罗拉的RFID读卡器,我要为这些读卡器写一个管理程序,判断是否有RFID标签进入或离开某个区域。用
- 一、创建和管理表 1、创建表语法 create table 表名(column datatype [default expr][,colum
- SQL Server数据库备份有两种方式,一种是使用BACKUP DATABASE将数据库文件备份出去,另外一种就是直接拷贝数据库文件mdf
- 如下所示:file = open('./abc.csv')csv.reader(file, delimiter=',
- 一. 引言在数据分析和可视化领域,数据的有效呈现是至关重要的。Python作为一种强大的编程语言,提供了多种数据可视化工具和库。其中,Plo
- 作者:peace.zhao 关于 游标 if,for 的例子 create or replace procedure peace_if is
- 一、人脸图像特征提取方法https://www.jb51.net/article/219446.htm二、对笑脸数据集genki4k进行训练
- 这将为我们的团队节省每天重复的数据处理时间......简介如果你目前在一个数据或商业智能团队工作,你的任务之一可能是制作一些每日、每周或每月
- 购物车程序要求如下图代码# --*--coding:utf-8--*--# Author: 村雨import pprintproductLi
- 内容摘要: 模拟网页下拉菜单中有几个比较关键的CSS属性:position、left、top、
- 在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致
- 一. torch.cat()函数解析1. 函数说明1.1 官网:torch.cat(),函数定义及参数说明如下图所示:1.2 函数功能函数将
- 之前说过要聊聊 干职业设计经理的活 的问题,貌似有些朋友对这个事情还挺关心的,我理解为一方面是掌握对付猎头时候的标准答案,一方面是
- 总经一下前段时间用于的jQuery方法:find及children。需要的朋友可以参考下。首先看看英文解释吧: children方法:fin
- 在遥感应用中,我们经常需要对某一景遥感影像中的全部像元的像素值进行平均值求取——这一操作很好实现,基
- 一、引入方式from itertools import cycle二、使用方法我们先来看看它的源码cycle它接收一个可迭代对象,可以将一个
- 一、wordcloud库是什么?Python的wordcloud库是一个用于生成词云的Python包。它可以将一段文本中出现频率高的单词按其
- ASP与MySQL的连接ASP和MySQL连接目前有两种方法:一种方法是使用MySQLX之类的组件,不过这种连接方法需要支付一定的费用;另外
- 往期学习:python数据类型: python数据结构:数据类型.python的输入输出: python数据结构之输入输出及控制和异常.py