supervisor进程管理器
---------------------------
1. 安装依赖
yum install python-setuptools-devel
2. 安装supervisor
pip install supervisor 或者 easy_install supervisor
3. 生成配置文件
echo_supervisord_conf > /etc/supervisord.conf
修改
[unix_http_server]
file=/var/run/supervisor.sock
[supervisord]
logfile=/var/log/supervisord.log
pidfile=/var/run/supervisord.pid
[supervisorctl]
serverurl=unix:///var/run/supervisor.sock
[include]
files = /etc/supervisord.d/*.conf
4. 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
sleep 1
[ -f $PIDFILE ] && success $"$prog startup" || failure $"$prog startup"
echo
}
stop()
{
if [ -f $PIDFILE ]
then
echo -n $"Shutting down $prog: "
[ -f $PIDFILE ] && killproc $prog || success $"$prog shutdown"
echo
else
echo -n "$prog is not running"
echo
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status $prog
;;
restart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
;;
esac
5. 管理服务配置文件示例
#cat /etc/supervisord.d/kafka.conf
[program:zookeeper]
command=/data/elk/kafka/bin/zookeeper-server-start.sh /data/elk/kafka/config/zookeeper.properties
autostart = true
startsecs = 5
#user = root
redirect_stderr = true
stdout_logfile = /var/log/supervisord/zookeeper.log
[program:kafka]
command=/data/elk/kafka/bin/kafka-server-start.sh /data/elk/kafka/config/server.properties
autostart = true
startsecs = 5
#user = root
redirect_stderr = true
stdout_logfile = /var/log/supervisord/kafka.log
6. supervisord命令行管理工具
supervisorctl start program
supervisorctl stop program
supervisorctl restart program
supervisorctl restart all
supervisorctl status
supervisorctl reload