Supervisor使用問(wèn)題
之前介紹了Supervisor的特征,使用方式等基本內(nèi)容,當(dāng)時(shí)我也是剛使用,感覺流程比較順利,接著就需要寫個(gè)shell腳本將Supervisor的安裝、配置新建、啟動(dòng)關(guān)閉等內(nèi)容自動(dòng)化,遇到了一些使用問(wèn)題,這里記錄一下。
unix:///var/run/supervisor.sock no such file
在使用supervisor時(shí),需要注意,supervisor由兩個(gè)部分組成,通常啟動(dòng)服務(wù)端部分就可以了,即使用如下命令則可
supervisord -c /x1_game/fla843/src/supervisord.conf
不要與下面命令搞混了
supervisorctl -c /x1_game/fla843/src/supervisord.conf
該命令用于啟動(dòng)客戶端交互模式,在交互模式下可以直接使用下面的命令
> status ? ?# 查看程序狀態(tài)
> stop program_name ? # 關(guān)閉 program_name 程序
> start program_name ?# 啟動(dòng) program_name 程序
> restart program_name ? ?# 重啟 program_name 程序
> reread ? ?# 讀取有更新(增加)的配置文件,不會(huì)啟動(dòng)新添加的程序,也不會(huì)重啟任何程序
> reload ? ?# ?載入最新的配置文件,停止原有的進(jìn)程并按照新的配置啟動(dòng)
> update ? ?# 重啟配置文件修改過(guò)的程序,配置沒有改動(dòng)的進(jìn)程不會(huì)收到影響而重啟
但其實(shí)完全不必去使用,直接使用supervisorctl + 對(duì)應(yīng)的指令則可,如下:
$ supervisorctl status
$ supervisorctl stop program_name
$ supervisorctl start program_name
$ supervisorctl restart program_name
$ supervisorctl reread
$ supervisorctl reload
$ supervisorctl update
當(dāng)然出現(xiàn) unix:///var/run/supervisor.sock no such file的原因還有一個(gè)常見的原因就是沒有使用root權(quán)限運(yùn)行supervisorctl,造成這一現(xiàn)象,很可能是 /var目錄只有root才有相應(yīng)的寫權(quán)限,你可以使用 sudo supervisord-c xxx.conf的形式啟動(dòng)supervisord。
http://localhost:9001 refused connection
該錯(cuò)誤出現(xiàn)也是非常奇怪,本人第一次安裝使用supervisord時(shí),并沒有出現(xiàn)這個(gè)錯(cuò)誤,查詢了相關(guān)資料,說(shuō)3.0后supervisord就需要修改相應(yīng)的配置,以開啟相應(yīng)的端口,需要修改的配置內(nèi)容如下:
[inet_http_server]
port = 127.0.0.1:9001
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
然后將已經(jīng)開啟的supervisor直接kill掉,再次啟動(dòng),則不會(huì)出現(xiàn)這個(gè)錯(cuò)誤了
封裝多一層
工作需求,這種東西還是要通過(guò)shell封裝一層,更加方便使用
這里提供安裝、啟動(dòng)與關(guān)閉的腳本供于參考
安裝腳本inst.sh
#!/bin/sh
sudo pip install supervisor
服務(wù)啟動(dòng)腳本start.sh
#! /bin/bash
isrun(){
? ?psid=`ps aux | grep supervisord | grep -v grep | wc -l`
? ?echo ${psid}
? ?echo "$1"
? ?if [ ${psid} -gt "$1" ] ;then
? ? ? ?echo "supervisord is running!"
? ? ? ?exit 0
? ?fi
}
if [ "$1" ] ;then
? ?# if input parameter has supervisord
? ?result=$(echo $1 | grep "supervisord")
? ?if [[ "$result" != "" ]] ;then
? ? ? ?isrun 2
? ?else
? ? ? ?isrun 0
? ?fi
? ?# the config file path is specified
? ?supervisord -c "$1"
else
? ?isrun 0
? ?supervisord
fi
echo "supervisord start success"
使用supervisorctl工具
#! /bin/bash
psid=`ps aux | grep "superviosrd" | grep -v "grep" | wc -l`
if [ ${psid} -lt 1 ] ;then
? ? ? ?echo "superviosrd is not run, place start superviosrd first!"
? ? ? ?exit 0
? ?fi
supervisorctl "$1" "$2"
關(guān)閉supervisor服務(wù),這種關(guān)閉方式,會(huì)將這個(gè)服務(wù)都關(guān)閉
#! /bin/bash
psid=`ps aux | grep "supervisord" | grep -v "grep" | wc -l`
echo ${psid}
if [ ${psid} -eq 0 ] ;then
? ?echo "superviosrd is close!"
? ?exit 0
fi
# supervisor will close and all child process also will close
supervisorctl shutdown