1. 安装必要的包:
yum install python-setuptools easy_install pip
pip install supervisor
echo_supervisord_conf > /etc/supervisord.conf
或者
yum install -y supervisor
2. 新建自定义进程脚本目录
mkdir /etc/supervisord.d/
3. 创建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
4. supervisor加入开机启动
chmod +x /etc/init.d/supervisord chkconfig --add supervisord chkconfig supervisord on service supervisord start
5. 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 ;标准错误输出的位置
7. 重启supervisor
/etc/init.d/supervisord restart 或者 service supervisord start 客户端命令 supervisorctl (start|stop|restart|status)