Supervisor

Supervisor is a client/server system that allows its users to control a number of processes on 
UNIX-like operating systems.

注意:python

Supervisor has been tested and is known to run on Linux (Ubuntu 9.10), Mac OS X (10.4/10.5/10.6), 
and Solaris (10 for Intel) and FreeBSD 6.1. It will likely work fine on most UNIX systems. Supervisor will not run at all under any version of Windows. Supervisor is known to work with Python 2.4 or later but will not work under any version of
  Python 3.

 

线上环境服务中止:
1、手动重启
2、集群、负载均衡
3、supervisor
    前提: 没有集群、负载均衡, 手动启动时间又没法接收


优势:
    出现问题,能够立刻拉起程序
    启动自动化,减小人为因素的干预
缺点:
    程序自己有BUG,它挂掉了,但又经过supervisor起来了(若果它对系统产生影响,例如open-files,它不断打开文件,达到系统上限,--》系统崩溃,
有一个影响,加重影响)

 

 

特色:web

  • 简单
  • 高效
  • 集中
  • 可扩展

组成:shell

  • supervisord:服务器部分(监督者)
功能:在本身的调用中启动子程序,响应客户机的命令,从新启动崩溃或推出子进程,记录其子进程stdout和stderr输出,
生成和处理子进程生命周期中对应的‘事件’
  • supervisorctl:客户机部分
提供了一个相似于shell的接口,能够链接到监视器提供的特性。客户能够从weaksorctl链接到不一样的监控程序(一次一个),
得到被监控子进程的状态,中止并从新启动子进程,并得到监控进程的运行列表
  • Web Server
能够经过浏览器访问server url  查看和控制进程的状态
  • xml-rpc接口
该接口可用于询问和控制主管及其运行的程序

 

 

安装:浏览器

sudo apt-get install supervosor
->配置文件已经在/etc/supervisor/supervisord.conf

 # 主要修改如下内容tomcat

;[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)
;autorestart=unexpected        ; whether/when to restart (default: unexpected)
;startsecs=1                   ; number of secs prog must stay running (def. 1)
;startretries=3                ; max # of serial start failures (default 3)
;exitcodes=0,2                 ; 'expected' exit codes for process (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_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        ; # 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)
stopasgroup = true    # 若是supervisor 管理的晋升px又产生了若干子进程,使用supervisor中止px京城,
      中止信号会传播给px产生的全部子进程,确保子进程也一块儿中止。这一配置对但愿中止全部进程的需求是很是有用的 autostart =true # 当启动supervisor的时候讲该配置项设置为true的全部进程自动启动

 

 一个例子安全

[unix_http_server]
file=/tmp/supervisor.sock   ; (the path to the socket file)
chmod=0777


[inet_http_server]         ; HTTP 服务器,提供 web 管理界面
port=127.0.0.1:9001      ; Web 管理后台运行的 IP 和端口,若是开放到公网,须要注意安全性
username=admin             ; 登陆管理后台的用户名
password=1qaz@WSX?         ; 登陆管理后台的密码

[supervisord]
logfile=/tmp/supervisord.log ; 日志文件,默认是 $CWD/supervisord.log
logfile_maxbytes=50MB        ; 日志文件大小,超出会 rotate,默认 50MB
logfile_backups=10           ; 日志文件保留备份数量默认 10
loglevel=info                ; 日志级别,默认 info,其它: debug,warn,trace
pidfile=/tmp/supervisord.pid ; pid 文件
nodaemon=false               ; 是否在前台启动,默认是 false,即以 daemon 的方式启动
minfds=1024                  ; 能够打开的文件描述符的最小值,默认 1024
minprocs=200                 ; 能够打开的进程数的最小值,默认 200

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL  for a unix socket
; 包含其余的配置文件 

[program:xxx]
command=python /home/ace/桌面/camera/sd/123.py

 

[program:tomcat]
directory = /app/zpy/tomcat/bin/ ; 程序的启动目录
command = sh startup.sh  ; 启动命令,能够看出与手动在命令行启动的命令是同样的
autostart = true     ; 在 supervisord 启动的时候也自动启动
startsecs = 5        ; 启动 5 秒后没有异常退出,就看成已经正常启动了
autorestart = true   ; 程序异常退出后自动重启
startretries = 3     ; 启动失败自动重试次数,默认是 3
user = zpy          ; 用哪一个用户启动
redirect_stderr = true  ; 把 stderr 重定向到 stdout,默认 false
stdout_logfile_maxbytes = 20MB  ; stdout 日志文件大小,默认 50MB
stdout_logfile_backups = 20     ; stdout 日志文件备份数
; stdout 日志文件,须要注意当指定目录不存在时没法正常启动,因此须要手动建立目录(supervisord 会自动建立日志文件)
stdout_logfile = /app/zpy/supervisor/usercenter_stdout.log

 

 

确保配置无误后能够再每台主机上使用如下的命令启动supervisor的服务端supervisord服务器

sudo supervisord -c  /etc/supervisor/supervisord.conf       # 启动
supervisorctl shutdown # 中止supervisord
supervisorctl reload # 从新加载配置文件

 

进程管理app

supervisorctl   start  all    启动管理的全部进程
supervisorctl   stop   all    中止全部
supervisorctl -c /etc/supervisor/supervisord.conf  需指定同一个配置文件 supervisorctl    start program-name // program-name 为【program:xxx】 supervisorctl    stop ............... supervisorctl restart all //重启全部 supervisorctl restart program-name supervisorctl    status      产看当前管理的全部进程的状态

unix:///tmp/supervisor.sock no such file负载均衡

出现上述错误的缘由是supervisord并未启动,只要在命令行中使用命令sudo supervisord启动supervisord便可。socket

相关文章
相关标签/搜索