首页 新闻动态 技术文章

Supervisor 守护者 安装指南

发布时间:2025-03-24 18:22 点击:124

安装

yum install -y epel-release
yum install -y supervisor

配置文件

cd /etc/
mkdir supervisord.d
echo_supervisord_conf > supervisord.conf
vi /etc/supervisord.conf
#加入以下配置信息
[include]
files = /etc/supervisord.d/*.conf

写入开机自启服务

新建命令脚本

vi /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"
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}"
 ;;
esac


设置命令生效

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


创建监听任务(子配置)

vi /etc/supervisord.d/mq_update_code.conf
[program:mq_update_code]
user=mit
directory=/var/sh/example/code/
command=sh /var/sh/example/code/code1
autostart=true
autorestart=true
startsecs=5
startretries=3
stderr_logfile=/var/log/update_err.log
;stdout_logfile=/var/log/update_out.log


重启服务

service supervisord restart
supervisorctl update

常见命令

supervisorctl status        //查看所有进程的状态
supervisorctl stop es       //停止es进程 配置文件中的process_name
supervisorctl start es      //启动es
supervisorctl restart       //重启es
supervisorctl update        //配置文件修改后使用该命令加载新的配置
supervisorctl reload        //重新启动配置中的所有程序