Supervisord配置使用

Supervisord是一款用Python实现的进程管理工具,主要用于监控和管理进程。它要求被管理的进程由其启动,并且是非守护进程。本文介绍了Supervisord的基本概念、安装方法、配置步骤及常用命令。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

概要

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

转载于:https://my.oschina.net/HeAlvin/blog/1377724

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值