86201746 2019-06-25
#第一种 yum install python-setuptools easy_install pip pip install supervisor #第二种 yum install python-setuptools easy_install supervisor #第三种 wget https://pypi.python.org/packages/source/s/supervisor/supervisor-3.1.3.tar.gz tar zxvf supervisor-3.1.3.tar.gz cd supervisor python setup.py install #第四种 yum install -y epel-release yum install -y supervisor
cd /etc/ mkdir supervisord.d echo_supervisord_conf > supervisord.conf vim /etc/supervisord.conf #加入以下配置信息 [include] files = /etc/supervisord.d/*.conf
#!/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"
prog_bin="/usr/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}"
 ;;
 
esacchmod +x /etc/init.d/supervisord chkconfig --add supervisord chkconfig supervisord on service supervisord start
# 如果想通过web查看管理的进程,加入以下代码,监听9001,用户user,密码123 [inet_http_server] port=9001 username=user password=123
#在重启之前随便创建一个挂在后台的命令 vim /etc/supervisord.d/tail.conf [program:task1] command=tail -f /etc/supervisord.conf ;常驻后台的命令 autostart=true ;是否随supervisor启动 autorestart=true ;是否在挂了之后重启,意外关闭后会重启,比如kill掉! startretries=3 ;启动尝试次数 stderr_logfile=/tmp/task1.err.log ;标准输出的位置 stdout_logfile=/tmp/task1.out.log ;标准错误输出的位置
##查看一下是否监听 lsof -i:9001 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME superviso 7782 root 4u IPv4 74522612 0t0 TCP *:etlservicemgr (LISTEN)
http://ip:9001 #输入你上面设置的账号密码,管理台上可以启动和停止服务