python測試開發django之使用supervisord?后臺啟動celery?服務(worker/beat)

目錄

前言

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# lsconf.d	supervisord.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.confroot@13107c465557:/code# supervisorctl shutdownShut 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

到此這篇關于python測試開發django之使用supervisord后臺啟動celery服務(worker/beat)得內容就介紹到這了,更多相關supervisord后臺啟動celery服務內容請搜索之家以前得內容或繼續瀏覽下面得相關內容希望大家以后多多支持之家!

聲明:所有內容來自互聯網搜索結果,不保證100%準確性,僅供參考。如若本站內容侵犯了原著者的合法權益,可聯系我們進行處理。
發表評論
更多 網友評論1 條評論)
暫無評論

返回頂部

主站蜘蛛池模板: 在线观看欧美国产| 日韩一级在线播放免费观看| 国产精品欧美在线不卡| 亚洲国产av无码专区亚洲av| 免费看男女下面日出水来| 日韩人妻一区二区三区免费| 国产一区二区三区欧美| 一级美国乱色毛片| 波多野结衣免费在线观看| 国产精品无码aⅴ嫩草| 久久精品人妻一区二区三区| 翁熄性放纵交换高清视频| 天天看片天天爽_免费播放| 亚洲国产精品综合久久网络 | 欧美日韩亚洲电影| 国产成人无码a区在线观看视频| 久9re热这里精品首页| 男人肌肌插女人肌肌| 国产精品成人久久久| 久久免费精品一区二区| 福利深夜小视频秒拍微拍| 国产精品无码久久综合| 久久亚洲国产精品123区| 粉色视频下载观看视频| 国产精品午夜电影| 丰满的奶水边做边喷| 波多野结衣欲乱| 国产小视频免费在线观看| 一本一本久久a久久精品综合麻豆| 欧美日韩视频在线第一区 | 色135综合网| 在线亚洲精品视频| 久久精品麻豆日日躁夜夜躁| 精品无码国产污污污免费 | 情人伊人久久综合亚洲| 亚洲永久精品ww47| 钻胯羞辱的视频vk| 大ji巴c死你h| 久久亚洲精品成人综合| 激情射精爆插热吻无码视频| 国产大学生粉嫩无套流白浆|