Linux之supervisor进程管理工作
1. 安装配置supervisor工具
[iyunv@localhost /]# yum install python-setuptools -y 必须有这一步
[iyunv@localhost /]#easy_install supervisor
如果easy_install不好用,可以直接从官网下载
wget https://pypi.python.org/packages/80/37/964c0d53cbd328796b1aeb7abea4c0f7b0e8c7197ea9b0b9967b7d004def/supervisor-3.3.1.tar.gz
编译安装supervisor工具。
tar zxf supervisor-3.3.1.tar.gz
cd supervisor
python setup.py install
报错:
问题需要解决。
[iyunv@localhost /]#mkdir /etc/supervisor
[iyunv@localhost /]#echo_supervisord_conf > /etc/supervisor/supervisord.conf
修改supervisord.conf文件,将文件尾部的
[include]
files = conf.d/*.conf
2. 配置supervisor为系统服务
vim /lib/systemd/system/supervisord.service 。
supervisord开机自启动脚本(各版本系统):https://github.com/Supervisor/initscripts 。
# supervisord service for systemd (CentOS 7.0+)
# by ET-CS (https://github.com/ET-CS)
[Unit]
Description=Supervisor daemon
[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /usr/local/etc/supervisord.conf
ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown
ExecReload=/usr/bin/supervisorctl $OPTIONS reload
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
自启动脚本都能够添加到systemctl自启动服务。
systemctl enable supervisord.service
systemctl start/restart/stop supervisor.service
3. 配置子进程
创建/etc/supervisor/conf.d,在这个目录下,创建:
[root@devgo conf.d]# cat report.conf [program:report] command=/home/devgo/gohome/src/git.cmr.net.cn/cmr/report/cmd/report/report ; directory=/home/devgo/gohome/src/git.cmr.net.cn/cmr/report/cmd/report ; autorestart=true ; stderr_logfile=/var/log/report.err.log ; stdout_logfile=/var/log/report.out.log ; environment=ASPNETCORE_ENVIRONMENT=Production ; 进程环境变量 user=root ; 进程执行的用户身份 stopsignal=INT
4. 启动子进程
supervisorctl start report
5. 关闭子进程
supervisorctl stop report
6. 启动子进程的时候报错
supervisor: couldn't chdir to /application/mongodb/bin;: ENOENT
supervisor: child process was not spawnedp
注意:配置文件中的分号前面的空格,没有空格,就报这个错误。
7. supervisor backoff
supervisor只能监控前台运行程序,不能监控后台运行程序。否则就会有backoff。
8. CentOS6.5使用supervisor管理zookeeper
supervisor配置文件中,添加:
[include]
files = conf.d/*.ini
在/etc/supervisor/conf.d目录下,新建一个文件zookeeper.ini文件,内容如下:
[root@datanode2 conf.d]# cat zookeeper.ini
[program:zookeeper]
command=/usr/local/zookeeper-3.4.6/bin/zkServer.sh start-foreground
user=root
autostart=true
autorestart=true
startsecs=3
注意空格
9. CentOS6.5创建/etc/init.d/supervisor文件,内容如下:
#!/bin/bash
#
# supervisord This scripts turns supervisord on
#
# Author: Mike McGrath <mmcgrath@redhat.com> (based off yumupdatesd)
#
# chkconfig: - 95 04
#
# description: supervisor is a process control utility. It has a web based
# xmlrpc interface as well as a few other nifty features.
# processname: supervisord
# config: /etc/supervisor/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/bin/supervisord -c /etc/supervisor/supervisord.conf "
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
exit $RETVAL
chmod a+x /etc/init.d/supervisor
chkconfig --add supervisor
chkconfig --level 345 supervisor on
10. CentOS6.5开机启动supervisor
vi /etc/rc.local/
/etc/init.d/supervisor start
这种方式重启完不好使

浙公网安备 33010602011771号