linux配置supervisor
安裝
pip install supervisor
生成配置文件
使用
echo_supervisord_conf > /etc/supervisord.conf
supervisord.ini配置文件修改
cd /etc/supervisord.conf
vim supervisord.conf
下面兩行是該配置文件的最后不用修改,這里說下意思,表示的是/etc這個文件夾下.ini文件就是要啟動的文件。
[include]
files = /etc/supervisor/*.ini
創建程序配置文件
下面就是需要運行的文件的配置,這個文件的位置是
/usr/local/etc/supervisor.d/spider.ini
command=/data/p2pSearch/start.sh
# 進程名
process_name=%(program_name)s
# 進程數
numprocs=1
# supervisor啟動的時候是否隨着同時啟動,默認True
autostart=true
# 當程序exit的時候,這個program不會自動重啟,默認unexpected
# 設置子進程掛掉后自動重啟的情況,有三個選項,false,unexpected和true。如果為false的時候,無論什么情況下,都不會被重新啟動,如果為unexpected,只有當進程的退出碼不在下面的exitcodes里面定義的
autorestart=true
# 這個選項是子進程啟動多少秒之后,此時狀態如果是running,則我們認為啟動成功了。默認值為1
startsecs=1
# 日志輸出
stderr_logfile=/data/p2pSearch/logs/p2papp_err.log
stdout_logfile=/data/p2pSearch/logs/p2papp_out.log
#把 stderr 重定向到 stdout,默認 false
redirect_stderr = false
#stdout 日志文件大小,默認 50MB
stdout_logfile_maxbytes = 1024MB
stderr_logfile_maxbytes = 1024MB
#stdout 日志文件備份數
stdout_logfile_backups = 10
stderr_logfile_backups = 10
因為用了virtualenv運行程序所以我用了一個shell腳本,並給定讀的權限
chmod 777 start.sh
start.sh內容如下
#! /bin/bash
cd /data/p2pSearch/
source p2p/bin/activate
python3 p2papp.py
運行
supervisord -c /etc/supervisord.conf
然后查看任務
supervisorctl
如果報錯
supervisorctl
error: <class 'socket.error'>, [Errno 13] Permission denied: file: /usr/lib64/python2.7/socket.py line: 224
查看
ps -ef |grep supervisor
然后殺掉進程
sudo pkill -f supervisord
查看任務
supervisorctl
重啟 可以看到任務狀態
[root@server supervisor]# supervisorctl
p2papp RUNNING pid 29931, uptime 0:00:09
表示成功了
