Supervisor是一个C/S系统,它容许用户在类UNIX系统上控制一些进程。它具备如下特性: python
1 简单 git
Supervisor经过INI格式配置文件进行配置,很容易掌握,它为每一个进程提供了不少配置选项,可使你很容易的重启进程或者自动的轮转日志。
github
2 统一
web
Supervisor提供了一种统一的方式来start、stop、monitor你的进程, 进程能够单独控制,也能够成组的控制。你能够在本地或者远程命令行或者web接口来配置Supervisor。
shell
3 有效
ubuntu
Supervisor经过fork/exec启动它的子进程,子进程并非守护进程。当一个进程终止的时候,操做系统会当即给Supervisor发送一个信号,而不是像其余解决方案依赖PID文件。
windows
4 可扩展
安全
Supervisor包含一个简单的事件通知协议,所以任何程序均可以监控它,并且提供一个XML-RPC控制接口。
app
5 兼容
socket
除了windows平台,其余平台均可运行。
Supervisor系统的组件:
supervisord:
服务会启动supervisord服务,它负责调用本身启动子程序,响应来自客户端的命令,重启crash或者退出的进程,记录进程的输出信息,收集事件信息。该服务的配置文件在/etc/supervisor/supervisord.conf
supervisorctl:
客户端的命令行工具,提供一个类shell接口,经过它你能够链接到不一样的supervisord进程上来管理它们各自的子程序。客户端命令经过UNIX socket或者TCP来和服务通信,服务端能够要求客户端提供身份验证以后才能进行操做([supervisorctl])。
Web Server:
一个小的web接口被集成进了supervisorctl,重启supervisord以后就能够访问了([inet_http_server])。
XML-RPC Interface:
就像HTTP提供WEB UI同样,同时还提供了XML-RPC接口来控制supervisor和由它运行的程序。
安装:
supervisor是python编写的,显然用easy_install、pip均可以安装,我懒,直接apt-get了,在ubuntu14.04下安装完后版本是3.0b2。
Supervisor服务的启动
其实启动Supervisor很简单,supervisord -h看看就知道了,最简单的-c根配置文件便可:
supervisord -- run a set of applications as daemons. Usage: /usr/bin/supervisord [options] Options: -c/--configuration FILENAME -- configuration file -n/--nodaemon -- run in the foreground (same as 'nodaemon true' in config file) -h/--help -- print this usage message and exit -v/--version -- print supervisord version number and exit -u/--user USER -- run supervisord as this user (or numeric uid) -m/--umask UMASK -- use this umask for daemon subprocess (default is 022) -d/--directory DIRECTORY -- directory to chdir to when daemonized -l/--logfile FILENAME -- use FILENAME as logfile path -y/--logfile_maxbytes BYTES -- use BYTES to limit the max size of logfile -z/--logfile_backups NUM -- number of backups to keep when max bytes reached -e/--loglevel LEVEL -- use LEVEL as log level (debug,info,warn,error,critical) -j/--pidfile FILENAME -- write a pid file for the daemon process to FILENAME -i/--identifier STR -- identifier used for this instance of supervisord -q/--childlogdir DIRECTORY -- the log directory for child process logs -k/--nocleanup -- prevent the process from performing cleanup (removal of old automatic child log files) at startup. -a/--minfds NUM -- the minimum number of file descriptors for start success -t/--strip_ansi -- strip ansi escape codes from process output --minprocs NUM -- the minimum number of processes available for start success --profile_options OPTIONS -- run supervisord under profiler and output results based on OPTIONS, which is a comma-sep'd list of 'cumulative', 'calls', and/or 'callers', e.g. 'cumulative,callers')
不过既然我这懒人是用apt-get安装的,那安装包的规范必然符合debian系的风格了,直接service supervisor start便可启动,且慢,咱们还没配置supervisor的配置文件呢,启动了也没什么效果。咱们后面详解配置文件的配置。
supervisorctl客户端的使用
supervisorctl有两种模式,一种是交互模式,一种是命令行模式。在命令行输入supervisorctl直接回车,便可进入交互模式。
supervisorctl -- control applications run by supervisord from the cmd line. Usage: /usr/bin/supervisorctl [options] [action [arguments]] Options: -c/--configuration -- configuration file path (default /etc/supervisor.conf) -h/--help -- print usage message and exit -i/--interactive -- start an interactive shell after executing commands -s/--serverurl URL -- URL on which supervisord server is listening (default "http://localhost:9001"). -u/--username -- username to use for authentication with server -p/--password -- password to use for authentication with server -r/--history-file -- keep a readline history (if readline is available) action [arguments] -- see below Actions are commands like "tail" or "stop". If -i is specified or no action is specified on the command line, a "shell" interpreting actions typed interactively is started. Use the action "help" to find out about available actions.
Supervisor的开机自启动
若是你是pip或者easy_install安装的,开机服务自启动还真是个麻烦事,不过官方已经给出一些rc.d脚本示例了,在github上,不过因为我是apt-get安装的,显然这个开机自启动是不用担忧的,用debian的update-rc.d便可搞定。
Supervisor的进程安全
既然是用Supervisor来保证其余进程的正常运行,可是万一Supervisor进程挂了怎么办,咱们可使用daemontools来保证Supervisor正常运行,就相似于监控的监控。
下篇看配置文件