概要
Supervisord是用Python实现的一款非常实用的进程管理工具,类似于monit
Monit和Supervisord的一个比较大的差异是Supervisord管理的进程必须由Supervisord来启动,Monit可以管理已经在运行的程序
Supervisord还要求管理的程序是非Daemon程序,Supervisord会帮你把它转成Daemon程序,因此如果用Supervisord来管理Nginx的话,必须在Nginx的配置文件里添加一行设置Daemon off让Nginx以非Daemon方式启动
安装
-
easy_install supervisor
-
pip install supervisor
-
推荐前两种
-
yum install epel-release -y && yum install supervisor -y
-
该方式安装版本较旧
-
apt-get install supervisor -y
-
dnf install supervisor -y
配置
1. easy_install及pip install安装后配置:
#查看配置文件
echo_supervisord_conf
#创建配置目录,生成配置文件
mkdir -p /etc/supervisor/
echo_supervisord_conf > /etc/supervisor/supervisord.conf
#修改supervisord.conf
echo -e '\n[include]\nfiles = /etc/supervisor/*.conf' >> /etc/supervisor/supervisord.conf
2. yum及dnf安装后配置:
/usr/bin/supervisord #supervisor服务守护进程
/usr/bin/supervisorctl #supervisor服务控制程序,比如:status/start/stop/restart pro_name等
/etc/supervisord.conf #supervisord配置文件,定义服务名称以及接口等
/etc/supervisord/ #独立管理的进程配置文件目录
#修改supervisord.conf,引用/etc/supervisord/内独立配置
echo -e '\n[include]\nfiles = /etc/supervisor/*.conf' >> /etc/supervisord.conf
3. aptitude及apt-get安装后配置:
/usr/bin/supervisord #supervisor服务守护进程
/usr/bin/supervisorctl #supervisor服务控制程序,比如:status/start/stop/restart pro_name等
/etc/supervisor/supervisord.conf #supervisord配置文件,定义服务名称以及接口等
/etc/supervisor/conf.d/ #独立管理的进程配置文件目录
#修改supervisord.conf,引用/etc/supervisord/内独立配置
echo -e '\n[include]\nfiles = /etc/supervisor/*.conf' >> /etc/supervisor/supervisord.conf
运行
#直接运行supervisord,通用
supervisord -c /etc/supervisor/supervisord.conf
运行supervisorctl(依赖上一步)
supervisor> help
default commands (type help <topic>):
=====================================
add exit open reload restart start tail
avail fg pid remove shutdown status update
clear maintail quit reread signal stop version
supervisorctl update #根据最新配置文件,启动新配置或有改动的进程,配置未改动的进程不会受影响而重启
supervisorctl start/stop/restart pro_name #启动/停止/重启某个进程
supervisorctl start/stop/restart all #启动/停止/重启所有进程
#
supervisorctl -c /etc/supervisor/supervisord.conf status 察看supervisor的状态
supervisorctl -c /etc/supervisor/supervisord.conf reload 重新载入 配置文件
supervisorctl -c /etc/supervisor/supervisord.conf start [all]|[appname] 启动指定/所有 supervisor管理的程序进程
supervisorctl -c /etc/supervisor/supervisord.conf stop [all]|[appname] 关闭指定/所有 supervisor管理的程序进程
作者:人世间
链接:http://www.jianshu.com/p/be9dd421fb8d
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
#通过init.supervisord启动运行
/etc/init.d/supervisord start
cat /etc/init.d/supervisord
#!/usr/bin/env bash
# chkconfig: - 85 15
PATH=/sbin:/bin:/usr/sbin:/usr/bin
PROGNAME=supervisord
DAEMON=/usr/bin/$PROGNAME
CONFIG=/etc/supervisor/$PROGNAME.conf
PIDFILE=/tmp/$PROGNAME.pid
DESC="supervisord daemon"
SCRIPTNAME=/etc/init.d/$PROGNAME
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
start()
{
echo -n "Starting $DESC: $PROGNAME"
$DAEMON -c $CONFIG
echo ".............start success"
}
stop()
{
echo "Stopping $DESC: $PROGNAME"
if [ -f "$PIDFILE" ];
then
supervisor_pid=$(cat $PIDFILE)
kill -15 $supervisor_pid
echo "......"
echo "stop success"
else
echo "$DESC: $PROGNAME is not Runing"
echo ".........................stop sucess"
fi
}
status()
{ statusport=`netstat -lntp|grep 9001|awk -F ' ' '{print $4}'|awk -F ':' '{print $2}'`
if [ -f "$PIDFILE" ];
then
supervisor_pid=$(cat $PIDFILE)
echo "$DESC: $PROGNAME is Runing pid=$supervisor_pid"
else
echo "$DESC: $PROGNAME is not Runing"
echo "please use command /etc/init.d/supervisord start Run the service"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart}" >&2
exit 1
;;
esac
exit 0
FAQ
http://supervisord.org/index.html
https://www.gitbook.com/book/wohugb/supervisor/details
http://www.restran.net/2015/10/04/supervisord-tutorial/
http://stackoverflow.com/questions/14479894/stopping-supervisord-shut-down
http://serverfault.com/questions/96499/how-to-automatically-start-supervisord-on-linux-ubuntu