记得第一次用supervisor的时候,这supervisor还毫无名气…. 陆续用了他好几年,后来哥们自己搞了一个简易的supervisor,https://github.com/rfyiamcool/ArbiterHandler
废话不多说.
说说今天这事吧,本来是打算通过supervisord启动程序的时候, 出现 interrupted system call socket 的问题, 具体排查了下代码没有发现问题. 通过日志才得到是elasticsearch引起的问题. 因为起初怀疑是supervisor引起的问题,So把supervisor模块卸载了. 等哥哥我再次使用的使用,就出现下面的问题…
文章写的不是很严谨,欢迎来喷,另外该文后续有更新的,请到原文地址查看更新.
第一个问题:
unix:///var/run/supervisor.sock no such file
这个问题是因为yum版本的pip的版本不一致引起的,说白了rpm有bug. 我们尽量使用pypi里面的安装包,而不是rpm的包.
第二个问题:
起初在supervisord.conf配置了程序的名字,但是在ps aux里面看到的还是command的命令,最后通过官方的文档得知
process_name=transfer
process_name是启动的进程名字,这里的名字只是supervisor内部是别用,与你所启动程序的进程名无关,所以你ps ef看到的是command的命令.
第三个问题:
2015-12-21 18:10:09,688 CRIT Server ‘unix_http_server’ running without any HTTP authentication checking
2015-12-21 18:10:09,690 INFO daemonizing the supervisord process
2015-12-21 18:10:09,691 INFO supervisord started with pid 12822
2015-12-21 18:10:10,695 INFO spawned: ‘transfer’ with pid 12824
2015-12-21 18:10:10,704 INFO exited: transfer (exit status 127; not expected)
2015-12-21 18:10:11,707 INFO spawned: ‘transfer’ with pid 12825
2015-12-21 18:10:11,716 INFO exited: transfer (exit status 127; not expected)
2015-12-21 18:10:13,720 INFO spawned: ‘transfer’ with pid 12828
2015-12-21 18:10:13,730 INFO exited: transfer (exit status 127; not expected)
2015-12-21 18:10:16,736 INFO spawned: ‘transfer’ with pid 12829
2015-12-21 18:10:16,746 INFO exited: transfer (exit status 127; not expected)
2015-12-21 18:10:17,765 INFO gave up: transfer entered FATAL state, too many start retries too quickly
去掉supervisord.conf的directory=/home/ruifenygun/shop_master/shop_scripts配置行就可以了.
原因已经问老外了.
第四个问题:
有些场景会让我们操作supervisor,supervisord开放了管理的api,接口的模式python xmlrpclib api … …
import xmlrpclib server = xmlrpclib.Server('http://localhost:9001/RPC2') server.supervisor.getState() server.system.listMethods() server.system.methodHelp('supervisor.shutdown')
supervisor提供了主要两类的api接口,状态查询 Status and Control ,进程管理Process Control … …
我简单说下supervisor api的几个例子:
getProcessInfo(name)
getAllProcessInfo()
startAllProcesses(wait=True)
startProcessGroup(name, wait=True)
stopProcess(name, wait=True)
stopProcessGroup(name, wait=True)
stopAllProcesses(wait=True)
signalProcess(name, signal)
reloadConfig()
下面简单说下supervisor的安装配置流程 .
sudo yum -y remove supervisor sudo pip install supervisor #echo_supervisord_conf可以生成配置文件,大家可以参数这配置文件进行修改 echo_supervisord_conf > /etc/supervisord.conf #启动supervisord ,使用 -c 指定配置文件. sudo supervisord -c /etc/supervisord.conf sudo ln -s /usr/local/bin/supervisorctl /bin/supervisorctl sudo ln -s /usr/local/bin/supervisord /bin/supervisord sudo supervisorctl status
然后在/etc/supervisord.conf追加具体的程序管理.
[program:transfer] ;directory = /home/ruifenygun/shop_master/shop_scripts/ command = python /home/ruifengyun/shop_master/shop_scripts/transfer.py process_name = transfer autorestart = true autostart = true startsecs = 15 user = ruifengyun stdout_logfile_maxbytes = 100MB stdout_logfile = /home/ruifengyun/shop_master/shop_scripts/debug.log stderr_logfile = /home/ruifengyun/shop_master/shop_scripts/error.log
如果你是懒人,或则说你对supervisor有些熟悉,那么你可以直接基于下面的完整的进行修改.
使用/etc/inti.d/supervisord 管理该程序,可以通过这脚本启动,关闭,重启supervisord进程.
#!/bin/bash # supervisord This scripts turns supervisord on # chkconfig: - 95 04 # processname: supervisord # config: /etc/supervisord.conf # pidfile: /var/run/supervisord.pid # source function library . /etc/rc.d/init.d/functions RETVAL=0 start() { echo -n "Starting supervisord: " daemon /usr/local/bin/supervisord RETVAL=? echo [ RETVAL -eq 0 ] && touch /var/lock/subsys/supervisord } stop() { echo -n"Stopping supervisord: " killproc supervisord echo [ RETVAL -eq 0 ] && rm -f /var/lock/subsys/supervisord } restart() { stop start } case "1" in start) start ;; stop) stop ;; restart|force-reload|reload) restart ;; condrestart) [ -f /var/lock/subsys/supervisord ] && restart ;; status) status supervisord RETVAL=? ;; *) echo"Usage: 0 {start|stop|status|restart|reload|force-reload|condrestart}" exit 1 esac exitRETVAL
supervisord,初始启动Supervisord,启动、管理配置中设置的进程。
sudo supervisorctl status 查看素有spawn进程的状态
supervisorctl stop programxxx,停止某一个进程(programxxx),programxxx为[program:chatdemon]里配置的值,这个示例就是chatdemon。
supervisorctl start programxxx,启动某个进程
supervisorctl restart programxxx,重启某个进程
supervisorctl stop groupworker: ,重启所有属于名为groupworker这个分组的进程(start,restart同理)
supervisorctl stop all,停止全部进程,注:start、restart、stop都不会载入最新的配置文件。
supervisorctl reload,载入最新的配置文件,停止原有进程并按新的配置启动、管理所有进程。
supervisorctl update,根据最新的配置文件,启动新配置或有改动的进程,配置没有改动的进程不会受影响而重启
注意:显示用stop停止掉的进程,用reload或者update都不会自动重启。