用supervisor控制celery时的脚本

简介:

注意启停的先后顺序及判断即可。

这样,在更改task之后,要重启就方便很多啦。。

复制代码
#!/bin/sh

supervisord_count=`ps -elf | grep celery | grep -v grep | wc -l`
if [ $supervisord_count -gt 0 ]; then
    ps aux|grep -v grep|grep supervisord|awk '{print $2}'|xargs kill -9
fi

celery_count=`ps -elf | grep celery | grep -v grep | wc -l`
if [ $celery_count -gt 0 ]; then
    ps aux|grep -v grep|grep celery|awk '{print $2}'|xargs kill -9
fi

/usr/bin/python /usr/local/python27/bin/supervisord -c /P/supervisord_prd.conf
sh /usr/local/nginx/sbin/uwsgi9090 reload
/usr/local/nginx/sbin/nginx -s reload

echo 'finished!'
复制代码

另给一个最基本的supervisor的设置:

复制代码
; Sample supervisor config file.
;
; For more information on the config file, please see:
; http://supervisord.org/configuration.html
;
; Notes:
;  - Shell expansion ("~" or "$HOME") is not supported.  Environment
;    variables can be expanded using this syntax: "%(ENV_HOME)s".
;  - Comments must have a leading space: "a=b ;comment" not "a=b;comment".

[supervisord]
logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB        ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10           ; (num of main logfile rotation backups;default 10)
loglevel=info                ; (log level;default info; others: debug,warn,trace)
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false               ; (start in foreground if true;default false)
minfds=1024                  ; (min. avail startup file descriptors;default 1024)
minprocs=200                 ; (min. avail process descriptors;default 200)
;umask=022                   ; (process file creation umask;default 022)
;user=chrism                 ; (default is current user, required if root)
;identifier=supervisor       ; (supervisord identifier, default is 'supervisor')
;directory=/tmp              ; (default is not to cd during start)
;nocleanup=true              ; (don't clean up tempfiles at start;default false)
;childlogdir=/tmp            ; ('AUTO' child log dir, default $TEMP)
;environment=KEY="value"     ; (key value pairs to add to environment)
;strip_ansi=false            ; (strip ansi escape codes in logs; def. false)

; 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:///tmp/supervisor.sock ; use a unix:// URL  for a unix socket

[program:celeryd]
command=/usr/local/python27/bin/celery worker -A XXXX -c 4   -l INFO -n celeryd@deploy
stdout_logfile=/var/log/celeryd.log
stderr_logfile=/var/log/celeryd.log
autostart=true
autorestart=true
startsecs=10
stopwaitsecs=600

;[program:celerybeat]
;command=/usr/local/python27/bin/celery worker -A XXXX -c 4   -B -n celerybeat@ping
;stdout_logfile=/var/log/celeryd.log
;stderr_logfile=/var/log/celeryd.log
;autostart=true
;autorestart=true
;startsecs=10
;stopwaitsecs=600
复制代码
目录
相关文章
|
JSON 数据格式 开发者
Postman模仿GET/POST请求进行接口的本地测试
接口是软件开发中常用的概念,是软件生产过程中比较核心的任务。对于接口开发者,调试接口是一件较为繁琐的事情,很多时候需要线上线下来回切换。在这里,我就跟大家介绍一个只需要在本地就可以调试接口的方法。
1003 0
|
NoSQL Redis UED
揭秘!Flask如何携手Celery,让异步任务处理不再是难题,打造极速响应的Web应用新纪元!
【8月更文挑战第31天】在Web开发中,Flask与Celery的结合为异步任务处理提供了强大支持。Flask作为轻量级Web框架,以其简洁灵活著称;而Celery则是一个分布式任务队列系统,擅长处理耗时任务。二者结合,Flask专注于处理Web请求,Celery则在后台异步执行复杂任务,如发送邮件或调用外部API。这种方式不仅提升了应用性能和响应速度,还优化了用户体验。下面的示例展示了如何在Flask应用中集成Celery以实现异步任务处理。
738 0
|
监控 安全 物联网
13位物联网卡与11位物联网卡有什么不同
物联网卡(IoT卡)的13位号码和11位号码之间存在一些关键差异。以下是针对这两者区别的详细操作步骤和解释:
|
前端开发 JavaScript 中间件
七、Flask蓝图使用之七
七、Flask蓝图使用之七
399 0
|
网络协议
Mac根据端口查询进程id的命令
这篇文章介绍了在Mac操作系统上如何使用两种命令来查询监听特定端口的进程ID。第一种方法是使用`netstat -anp tcp -v | grep 端口号`,例如`netstat -anp tcp -v | grep 80`,这将列出所有使用端口80的TCP连接及其相关信息。第二种方法是使用`lsof -P -n -i:端口号`,例如`lsof -P -n -i:8080`,这将显示使用指定端口的进程列表,包括进程ID、用户、文件描述符等信息。文章通过示例展示了如何使用这些命令,并提供了输出结果的截图。
1238 2
|
SQL 测试技术 API
SqlAlchemy 2.0 中文文档(二十五)(5)
SqlAlchemy 2.0 中文文档(二十五)
299 0
|
JSON API 数据库
Flask 实战:实现增改及分页查询的完整 Demo
使用 Flask 搭建的 RESTful API Demo,包含增、改用户信息和分页查询功能。利用 Flask-SQLAlchemy 处理数据库操作。环境准备:安装 Flask 和 Flask-SQLAlchemy。核心代码展示用户模型、增加用户、分页查询和更新用户信息的路由。注意点包括数据库配置、错误处理、JSON 数据处理、幂等性、安全性和编码问题。提供完整源码下载链接。
1246 2
|
SQL 关系型数据库 数据库
SqlAlchemy 2.0 中文文档(五)(4)
SqlAlchemy 2.0 中文文档(五)
582 0
|
监控 NoSQL 测试技术
python使用Flask,Redis和Celery的异步任务
python使用Flask,Redis和Celery的异步任务
|
存储 NoSQL 安全
分布式锁中-基于 Redis 的实现如何防重入
分布式锁中-基于 Redis 的实现如何防重入
582 0
分布式锁中-基于 Redis 的实现如何防重入