咱們能夠使用echo_supervisord_conf命令獲得supervisor配置模板,打開終端執行以下Linux shell命令:shell
# echo_supervisord_conf > supervisord.conf
該命令輸出文件到當前目錄下(固然,你也能夠指定絕對路徑到具體位置),文件名爲supervisord.conf
修改supervisord.conf文件,在文件最後加入:spa
[program:celery.worker] ;指定運行目錄 directory=/home/你的項目名稱 ;運行目錄下執行命令 command=celery -A 你的項目名稱worker --loglevel info --logfile celery_worker.log ;啓動設置 numprocs=1 ;進程數 autostart=true ;當supervisor啓動時,程序將會自動啓動 autorestart=true ;自動重啓 ;中止信號,默認TERM ;中斷:INT (相似於Ctrl+C)(kill -INT pid),退出後會將寫文件或日誌(推薦) ;終止:TERM (kill -TERM pid) ;掛起:HUP (kill -HUP pid),注意與Ctrl+Z/kill -stop pid不一樣 ;從容中止:QUIT (kill -QUIT pid) stopsignal=INT ;輸出日誌 stdout_logfile=celery_worker.log stdout_logfile_maxbytes=10MB ;默認最大50M stdout_logfile_backups=10 ;日誌文件備份數,默認爲10 ;錯誤日誌 redirect_stderr=false ;爲true表示禁止監聽錯誤 stderr_logfile=celery_worker_err.log stderr_logfile_maxbytes=10MB stderr_logfile_backups=10
經常使用命令rest
# 啓動supervisor輸入以下命令,使用具體的配置文件執行: supervisord -c supervisord.conf # 關閉supervisor輸入以下命令: supervisorctl -c supervisord.conf shutdown # 重啓supervisor輸入以下命令: supervisorctl -c supervisord.conf reload # 檢測運行狀態: supervisorctl status