Supervisord进程管家

Supervisord是一个守护进程的工具,当进程意外终止或服务器掉电起来后,希望进程能够自动运行,supervisord可以很好的为我们做这件事情。同时supervisord也自带监控界面,可以通过浏览器灵活的查看、操作。

以安徽storm快数据系统为例,20台服务器总计268个进程(不包括CDH hadoop集群进程),全部由supervisord接管。

1)  首先安装meld3和supervisor:

下载地址

https://pypi.python.org/pypi/meld3

https://pypi.python.org/pypi/supervisor

tar xfz meld3-1.0.2.tar.gz

cd meld3-1.0.2

python setup.py install

python setup.py install安装报错

[root@localhost meld3-1.0.2]# python setup.py install

Traceback (most recent call last):

File "setup.py", line 1, in ?

from setuptools import setup

ImportError: No module named setuptools

解决办法

http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz

tar zxvf setuptools-0.6c11.tar.gz

cd setuptools-0.6c11

python setup.py build

python setup.py install

tar xfz supervisor-3.2.3.tar.gz

cd supervisor-3.2.3

python setup.py install

2)生成配置文件:

echo_supervisord_conf >
/etc/supervisord.conf

3)修改配置文件,并在末尾添加app守护:

vi /etc/supervisord.conf

末尾添加app信息:

[program:storm_nimbus]

user=inas

autorestart=true

directory=/home/inas/storm/bin

command=/home/inas/storm/bin/storm nimbus

[program:storm_ui]

user=inas

autorestart=true

directory=/home/inas/storm/bin

command=/home/inas/storm/bin/storm ui

[program:storm_supervisor]

user=inas

autorestart=true

directory=/home/inas/storm/bin

command=/home/inas/storm/bin/storm
supervisor

附录/etc/supervisord.conf  (安徽样例)

4)添加自启动服务脚本:

vi /etc/init.d/supervisord

详见附录/etc/init.d/supervisord

5)生成日志目录并添加到服务里:

mkdir -p /var/log/supervisor

chmod +x /etc/init.d/supervisord

chkconfig --add supervisord

chkconfig --list supervisord

6)相关命令:

service supervisord
start|stop|status|reload|restart

supervisorctl status

supervisorctl start xxx

supervisorctl stop xxx

supervisorctl update

7)监控页面(如需要安全性,也可以设置账号):

http://x.x.x.x:9001

8)FAQ:

Q)由supervisord守护的进程条件?

A)启动命令中不能包含daemon或&后台符来运行即可。

Q)如果/etc/supervisord.conf里新增加了app,需要重启supervisord?

A)可以通过service
supervisord restart来重启所有app;

也可以通过supervisorctl
update命令来运行新增的app,而原有未改动的app不受影响。

附录1:

/etc/supervisord.conf文件样例:

; Sample supervisor config file.

;

; For more information on the config file,
please see:

; http://supervisord.org/configuration.html

;

; Notes:

;  -
Shell expansion ("~" or "$HOME") is not supported.  Environment

;   
variables can be expanded using this syntax: "%(ENV_HOME)s".

;  -
Comments must have a leading space: "a=b ;comment" not
"a=b;comment".

[unix_http_server]

file=/tmp/supervisor.sock       ; (the path to the socket file)

;chmod=0700                 ; socket file mode (default
0700)

;chown=nobody:nogroup       ; socket file uid:gid owner

;username=user              ; (default is no username (open
server))

;password=123               ; (default is no password (open
server))

[inet_http_server]         ; inet (TCP) server disabled by
default

port=0.0.0.0:9001         ; (ip_address:port specifier, *:port for all
iface)

;username=user              ; (default is no username (open
server))

;password=123               ; (default is no password (open
server))

[supervisord]

logfile=/var/log/supervisor/supervisord.log
; (main log file;default $CWD/supervisord.log)

logfile_maxbytes=50MB        ; (max main logfile bytes b4
rotation;default 50MB)

logfile_backups=10           ; (num of main logfile rotation
backups;default 10)

loglevel=info                ; (log level;default info;
others: debug,warn,trace)

pidfile=/var/run/supervisord.pid ;
(supervisord pidfile;default supervisord.pid)

nodaemon=false               ; (start in foreground if
true;default false)

minfds=1024                  ; (min. avail startup file
descriptors;default 1024)

minprocs=200                 ; (min. avail process
descriptors;default 200)

;umask=022                   ; (process file creation
umask;default 022)

;user=chrism                 ; (default is current user,
required if root)

;identifier=supervisor       ; (supervisord identifier, default is
'supervisor')

;directory=/tmp              ; (default is not to cd during
start)

;nocleanup=true              ; (don't clean up tempfiles at
start;default false)

;childlogdir=/tmp            ; ('AUTO' child log dir, default
$TEMP)

;environment=KEY="value"     ; (key value pairs to add to environment)

;strip_ansi=false            ; (strip ansi escape codes in logs;
def. false)

; the below section must remain in the
config file for RPC

; (supervisorctl/web interface) to work,
additional interfaces may be

; added by defining them in separate
rpcinterface: sections

[rpcinterface:supervisor]

supervisor.rpcinterface_factory =
supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]

serverurl=unix:///tmp/supervisor.sock ; use
a unix:// URL  for a unix socket

;serverurl=http://127.0.0.1:9001 ; use an
http:// url to specify an inet socket

;username=chris              ; should be same as http_username
if set

;password=123                ; should be same as
http_password if set

;prompt=mysupervisor         ; cmd line prompt (default
"supervisor")

;history_file=~/.sc_history  ; use readline history if available

; The below sample program section shows
all possible program subsection values,

; create one or more 'real' program:
sections to be able to control them under

; supervisor.

;[program:theprogramname]

;command=/bin/cat              ; the program (relative uses
PATH, can take args)

;process_name=%(program_name)s ;
process_name expr (default %(program_name)s)

;numprocs=1                    ; number of processes
copies to start (def 1)

;directory=/tmp                ; directory to cwd to before exec (def no cwd)

;umask=022                     ; umask for process
(default None)

;priority=999                  ; the relative start priority
(default 999)

;autostart=true                ; start at supervisord start
(default: true)

;startsecs=1                   ; # of secs prog must stay
up to be running (def. 1)

;startretries=3                ; max # of serial start
failures when starting (default 3)

;autorestart=unexpected        ; when to restart if exited after
running (def: unexpected)

;exitcodes=0,2                 ; 'expected' exit codes used
with autorestart (default 0,2)

;stopsignal=QUIT               ; signal used to kill process
(default TERM)

;stopwaitsecs=10               ; max num secs to wait b4
SIGKILL (default 10)

;stopasgroup=false             ; send stop signal to the UNIX
process group (default false)

;killasgroup=false             ; SIGKILL the UNIX process group
(def false)

;user=chrism                   ; setuid to this UNIX
account to run the program

;redirect_stderr=true          ; redirect proc stderr to stdout
(default false)

;stdout_logfile=/a/path        ; stdout log path, NONE for none;
default AUTO

;stdout_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default
50MB)

;stdout_logfile_backups=10     ; # of stdout logfile backups (default 10)

;stdout_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default
0)

;stdout_events_enabled=false   ; emit events on stdout writes (default
false)

;stderr_logfile=/a/path        ; stderr log path, NONE for none;
default AUTO

;stderr_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default
50MB)

;stderr_logfile_backups=10     ; # of stderr logfile backups (default 10)

;stderr_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default
0)

;stderr_events_enabled=false   ; emit events on stderr writes (default
false)

;environment=A="1",B="2"       ; process environment additions (def no
adds)

;serverurl=AUTO                ; override serverurl
computation (childutils)

; The below sample eventlistener section
shows all possible

; eventlistener subsection values, create
one or more 'real'

; eventlistener: sections to be able to
handle event notifications

; sent by supervisor.

;[eventlistener:theeventlistenername]

;command=/bin/eventlistener    ; the program (relative uses PATH, can take
args)

;process_name=%(program_name)s ;
process_name expr (default %(program_name)s)

;numprocs=1                    ; number of processes
copies to start (def 1)

;events=EVENT                  ; event notif. types to
subscribe to (req'd)

;buffer_size=10                ; event buffer queue size
(default 10)

;directory=/tmp                ; directory to cwd to before
exec (def no cwd)

;umask=022                     ; umask for process
(default None)

;priority=-1                   ; the relative start
priority (default -1)

;autostart=true                ; start at supervisord start
(default: true)

;startsecs=1                   ; # of secs prog must stay
up to be running (def. 1)

;startretries=3                ; max # of serial start failures when
starting (default 3)

;autorestart=unexpected        ; autorestart if exited after running
(def: unexpected)

;exitcodes=0,2                 ; 'expected' exit codes used
with autorestart (default 0,2)

;stopsignal=QUIT               ; signal used to kill process
(default TERM)

;stopwaitsecs=10               ; max num secs to wait b4
SIGKILL (default 10)

;stopasgroup=false             ; send stop signal to the UNIX
process group (default false)

;killasgroup=false             ; SIGKILL the UNIX process group (def
false)

;user=chrism                   ; setuid to this UNIX
account to run the program

;redirect_stderr=false         ; redirect_stderr=true is not allowed
for eventlisteners

;stdout_logfile=/a/path        ; stdout log path, NONE for none;
default AUTO

;stdout_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default
50MB)

;stdout_logfile_backups=10     ; # of stdout logfile backups (default 10)

;stdout_events_enabled=false   ; emit events on stdout writes (default
false)

;stderr_logfile=/a/path        ; stderr log path, NONE for none;
default AUTO

;stderr_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default
50MB)

;stderr_logfile_backups=10     ; # of stderr logfile backups (default 10)

;stderr_events_enabled=false   ; emit events on stderr writes (default
false)

;environment=A="1",B="2"       ; process environment additions

;serverurl=AUTO                ; override serverurl
computation (childutils)

; The below sample group section shows all
possible group values,

; create one or more 'real' group: sections
to create "heterogeneous"

; process groups.

;[group:thegroupname]

;programs=progname1,progname2  ; each refers to 'x' in [program:x]
definitions

;priority=999                  ; the relative start priority
(default 999)

; The [include] section can just contain
the "files" setting.  This

; setting can list multiple files
(separated by whitespace or

; newlines).  It can also contain wildcards.  The filenames are

; interpreted as relative to this
file.  Included files *cannot*

; include files themselves.

;[include]

;files = relative/directory/*.ini

[program:zookeeper]

user=inas

autorestart=true

command=/usr/java/default/bin/java
-Dzookeeper.log.dir=/home/inas/zookeeper-3.4.8/bin -Dzookeeper.root.logger=INFO,CONSOLE
-cp
/home/inas/zookeeper-3.4.8/build/classes:/home/inas/zookeeper-3.4.8/build/lib/*.jar:/home/inas/zookeeper-3.4.8/lib/slf4j-log4j12-1.6.1.jar:/home/inas/zookeeper-3.4.8/lib/slf4j-api-1.6.1.jar:/home/inas/zookeeper-3.4.8/lib/netty-3.7.0.Final.jar:/home/inas/zookeeper-3.4.8/lib/log4j-1.2.16.jar:/home/inas/zookeeper-3.4.8/lib/jline-0.9.94.jar:/home/inas/zookeeper-3.4.8/zookeeper-3.4.8.jar:/home/inas/zookeeper-3.4.8/src/java/lib/*.jar:/home/inas/zookeeper-3.4.8/conf:.:/usr/java/default/lib/dt.jar:/usr/java/default/lib/tools.jar:
-Xms4096m -Xmx4096m -Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.local.only=false
org.apache.zookeeper.server.quorum.QuorumPeerMain
/home/inas/zookeeper-3.4.8/conf/zoo.cfg

[program:storm_nimbus]

user=inas

autorestart=true

command=/home/inas/storm/bin/storm nimbus

[program:storm_ui]

user=inas

autorestart=true

command=/home/inas/storm/bin/storm ui

[program:storm_supervisor]

user=inas

autorestart=true

command=/home/inas/storm/bin/storm supervisor

[program:haproxy]

user=inas

autorestart=true

directory=/home/inas/haproxy

command=/home/inas/haproxy/haproxy -f
haproxy_supervisord.cfg

[program:tomcat1]

user=inas

autorestart=true

directory=/home/inas/tomcat1/bin

command=/home/inas/tomcat1/bin/catalina.sh
run

[program:tomcat2]

user=inas

autorestart=true

directory=/home/inas/tomcat2/bin

command=/home/inas/tomcat2/bin/catalina.sh
run

附录2

/etc/init.d/supervisord 文件样例:

#!/bin/bash

#

# supervisord   Startup script for the Supervisor process control
system

#

# Author:       Mike McGrath <mmcgrath@redhat.com>
(based off yumupdatesd)

#               Jason Koppe
<jkoppe@indeed.com> adjusted to read sysconfig,

#                   use supervisord tools to
start/stop, conditionally wait

#          
        for child processes to
shutdown, and startup later

#               Erwan Queffelec
<erwan.queffelec@gmail.com>

#                   make script LSB-compliant

#

# chkconfig:    345 83 04

# description: Supervisor is a
client/server system that allows \

#  
its users to monitor and control a number of processes on \

#  
UNIX-like operating systems.

# processname: supervisord

# config: /etc/supervisord.conf

# config: /etc/sysconfig/supervisord

# pidfile: /var/run/supervisord.pid

#

### BEGIN INIT INFO

# Provides: supervisord

# Required-Start: $all

# Required-Stop: $all

# Short-Description: start and stop
Supervisor process control system

# Description: Supervisor is a
client/server system that allows

#  
its users to monitor and control a number of processes on

#  
UNIX-like operating systems.

### END INIT INFO

# Source function library

. /etc/rc.d/init.d/functions

# Source system settings

if [ -f /etc/sysconfig/supervisord ]; then

.
/etc/sysconfig/supervisord

fi

# Path to the supervisorctl script, server
binary,

# and short-form for messages.

supervisorctl=/usr/bin/supervisorctl

supervisord=${SUPERVISORD-/usr/bin/supervisord}

prog=supervisord

pidfile=${PIDFILE-/var/run/supervisord.pid}

lockfile=${LOCKFILE-/var/lock/subsys/supervisord}

STOP_TIMEOUT=${STOP_TIMEOUT-60}

OPTIONS="${OPTIONS--c
/etc/supervisord.conf}"

RETVAL=0

start() {

echo -n $"Starting $prog: "

daemon --pidfile=${pidfile} $supervisord $OPTIONS

RETVAL=$?

echo

if [ $RETVAL -eq 0 ]; then

touch ${lockfile}

$supervisorctl $OPTIONS status

fi

return $RETVAL

}

stop() {

echo -n $"Stopping $prog: "

killproc -p ${pidfile} -d ${STOP_TIMEOUT} $supervisord

RETVAL=$?

echo

[
$RETVAL -eq 0 ] && rm -rf ${lockfile} ${pidfile}

}

reload() {

echo -n $"Reloading $prog: "

LSB=1 killproc -p $pidfile $supervisord -HUP

RETVAL=$?

echo

if [ $RETVAL -eq 7 ]; then

failure $"$prog reload"

else

$supervisorctl $OPTIONS status

fi

}

restart() {

stop

start

}

case "$1" in

start)

start

;;

stop)

stop

;;

status)

status -p ${pidfile} $supervisord

RETVAL=$?

[ $RETVAL -eq 0 ] && $supervisorctl $OPTIONS status

;;

restart)

restart

;;

condrestart|try-restart)

if status -p ${pidfile} $supervisord >&/dev/null; then

stop

start

fi

;;

force-reload|reload)

reload

;;

*)

echo $"Usage: $prog
{start|stop|restart|condrestart|try-restart|force-reload|reload}"

RETVAL=2

esac

exit $RETVAL

Supervisord进程管家的更多相关文章

  1. supervisord 进程管家

    s supervisor supervisor管理进程,是通过fork/exec的方式将这些被管理的进程当作supervisor的子进程来启动,所以我们只需要将要管理进程的可执行文件的路径添加到sup ...

  2. Supervisord进程管理工具

    进程管理工具Supervisord Posted on 2014/06/17 by admin Supervisord 上面已经介绍了Go目前是有两种方案来实现他的daemon,但是官方本身还不支持这 ...

  3. supervisord进程管理工具小结

    前言 昨天临近下班,发现业务队列处理不及时,正好想到不久之前,上了一个新功能:通过队列异步转发微信消息.可能是消息太多了处理不过来,没怎么多想,处理不过来了,多增加处理进程就可以了,后来发现自己so ...

  4. supervisord进程管理

    一:简介 supervisord是一个进程管理工具,提供web页面管理,能对进程进行自动重启等操作. 优点: - 可以将非后台运行程序后台运行 - 自动监控,重启进程 缺点: - 不能管理后台运行程序 ...

  5. Supervisord管理进程实践

    今天凑空研究了下Supervisord,这是一款linux进程管理工具,使用python开发,主要用于在后台维护进程(类似master守护进程),可以实现监控进程的状态.自动重启进程等操作,便于一些服 ...

  6. supervisord 小记

    此篇仅用作supervisord的用法,不涉及理论说明和基础介绍 supervisor(一)基础篇 使用supervisord来管理process 进程的守护神 - Supervisor superv ...

  7. 进程管理工具Supervisor(一)简介与使用

    Supervisor是用Python开发的一套client/server架构的进程管理程序,能做到开机启动,以daemon进程的方式运行程序,并可以监控进程状态等等. linux进程管理方式有传统的r ...

  8. Supervisor 安装及配置管理uwsgi进程

    Supervisor介绍 Supervisor 允许其用户在UNIX类操作系统上控制多个进程. 块如下: 方便 需要为每个进程实例编写rc.d脚本通常是不方便的. rc.d脚本是进程初始化/自动启动/ ...

  9. supervisor进程管理的使用

    介绍 Supervisor是用Python开发的一套通用的进程管理程序,能将一个普通的命令行进程变为后台daemon,并监控进程状态,异常退出时能自动重启.它是通过fork/exec的方式把这些被管理 ...

随机推荐

  1. js原生方法promise的实现

    一会儿就要回家过年了,再来手写一个promise吧,要不等着下班真的煎熬... <!DOCTYPE html> <html lang="en"> <h ...

  2. chrome打开Axure Rp导出的html文件提示需要安装Axure Rp插件解决办法

    1.确保chrome安装了Axure Rp扩展插件,如果按照页面的提示去下载,但是打不开的话就是被墙了,贴上科学的上网梯子https://www.lanzous.com/i7i0wuh,直接下载打开就 ...

  3. 【题解】P2610 [ZJOI2012]旅游

    link 题意 T国的国土可以用一个凸N边形来表示,包含 \(N-2\) 个城市,每个城市都是顶点为 \(N\) 边形顶点的三角形,两人的旅游路线可以看做是连接N个顶点中不相邻两点的线段.问一路能经过 ...

  4. 【题解】P6329 【模板】点分树 | 震波

    题外话 (其实模板题没必要在这里水题解的--主要是想说这个qwq) 小常数的快乐.jpg 我也不知道我为啥常数特别小跑得飞快--不加快读就能在 luogu 的最优解上跑到 rank5 ( 说不定深夜提 ...

  5. 微信端video去除最顶层播放

    https://x5.tencent.com/tbs/guide/video.html 给video标签添加属性 x5-video-player-type="h5"

  6. 使用Swiper快速实现3D效果轮播

    最近经常接到轮播图3D效果的需求, 特在此记录一下以备之后使用. 具体实现效果如下: 在这里介绍两种使用方式, 一种原生的html+php后端渲染, 一种是使用vue. 原生实现 引入 首先我们介绍原 ...

  7. SpringBoot-2.3镜像方案为什么要做多个layer

    欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...

  8. 01-docker基本使用

    docker 常用命令 指令 说明 docker images 查看已经下载的镜像 docker rmi 镜像名称:标签名 删除已经下载的镜像 docker search 镜像 从官方仓库中查看镜像 ...

  9. Python中的”黑魔法“与”骚操作“

    本文主要介绍Python的高级特性:列表推导式.迭代器和生成器,是面试中经常会被问到的特性.因为生成器实现了迭代器协议,可由列表推导式来生成,所有,这三个概念作为一章来介绍,是最便于大家理解的,现在看 ...

  10. python极简代码之检测列表是否有重复元素

    极简python代码收集,实战小项目,不断撸码,以防遗忘.持续更新: 1,检测列表是否有重复元素: 1 # !usr/bin/env python3 2 # *-* coding=utf-8 *-* ...