CentOS 7安装supervisord(亲测) 有更新!

  aluaa

废话少说,直蹦主题!

1、安装必要的包:

yum install python-setuptools
easy_install pip

2、安装supervisor

pip install supervisor

3、生成supervisor配置文件

echo_supervisord_conf > /etc/supervisord.conf

4、新建自定义进程脚本目录

mkdir /etc/supervisord.d/

5、修改supervisor配置文件/etc/supervisor.conf,方便管理自定义进程

[include]
files = /etc/supervisord.d/*.conf

6、创建supervisord启动脚本

/etc/init.d/supervisord
#!/bin/sh
#
# /etc/init.d/supervisord
#
# Supervisor is a client/server system that
# allows its users to monitor and control a
# number of processes on UNIX-like operating
# systems.
#
# chkconfig: - 64 36
# description: Supervisor Server
# processname: supervisord

# Source init functions
. /etc/rc.d/init.d/functions

prog="supervisord"

prefix="/usr/local"
exec_prefix="${prefix}"
prog_bin="${exec_prefix}/bin/supervisord"
PIDFILE="/var/run/$prog.pid"

start()
{
       echo -n $"Starting $prog: "
       ###注意下面这一行一定得有-c /etc/supervisord.conf   不然修改了配置文件根本不生效!
       daemon $prog_bin -c /etc/supervisord.conf --pidfile $PIDFILE
       [ -f $PIDFILE ] && success $"$prog startup" || failure $"$prog startup"
       echo
}

stop()
{
       echo -n $"Shutting down $prog: "
       [ -f $PIDFILE ] && killproc $prog || success $"$prog shutdown"
       echo
}

case "$1" in

 start)
   start
 ;;

 stop)
   stop
 ;;

 status)
       status $prog
 ;;

 restart)
   stop
   start
 ;;

 *)
   echo "Usage: $0 {start|stop|restart|status}"
 ;;

esac

7、supervisor加入开机启动

chmod +x /etc/init.d/supervisord
chkconfig --add supervisord
chkconfig supervisord on
service supervisord start

8、supervisor最基本使用方法

创建一个后台进程执行脚本:

vi /etc/supervisord.d/test.conf
[program:test]                                                                            
command=tail -f  /etc/supervisord.conf   ;常驻后台的命令
autostart=true                           ;是否随supervisor启动
autorestart=true                         ;是否在挂了之后重启,意外关闭后会重启,比如kill掉!
startretries=3                           ;启动尝试次数
stderr_logfile=/tmp/test.err.log        ;标准输出的位置
stdout_logfile=/tmp/test.out.log        ;标准错误输出的位置

9、重启supervisor

/etc/init.d/supervisord restart