Supervisor 在類UNIX系統上控制系統進程,實現對進程的管理
該工具有Python語言編寫,支持Python2.4及其以後版本,但不支持Python3
參考資料如下
安裝
- pip install supervisor
- easy_install supervisor
- apt-get install supervisor (配置文件在/etc/supervisor/目錄下)
- yum install supervisor (Centos)
啓動
supervisord -c /etc/supervisor/supervisord.conf
添加新的控制進程
在 /etc/supervisor/conf.d/目錄下,新建一個文件名爲*.conf的文件,表示新建一個需要控制的進程,裏面對該進程進行配置,簡單示例如下
[program:sendemail]
command=/usr/bin/php /mnt/hgfs/web/timinglove/yii gearman/protect #要執行的命令
directory=/mnt/hgfs/web/timinglove #命令執行的目錄
user=www-data #進程執行的用戶身份
autostart=true #是否自動啓動
autorestart=true #是否自動重啓
startsecs=1 #自動重啓間隔
stderr_logfile=/tmp/sendemail.log #標準錯誤日誌
stdout_logfile=/tmp/sendemail.log #標準輸出日誌
配置好以後,執行命令sudo supervisorctl shutdown && sudo supervisord -c /etc/supervisor/supervisor.conf
常用命令
supervisorctl shutdown #關閉所有任務
supervisorctl stop|start program_name
supervisorctl status #查看所有任務狀態