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.
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正常运行,就类似于监控的监控。
supervisord的配置文件主要由几个配置段构成,配置项以K/V格式呈现,下面就看看各个配置端需要怎样配置:
[unix_http_server]
在该配置块的参数项表示的是一个监听在socket上的HTTP server,如果[unix_http_server]块不在配置文件中,则不会启动基于socket的HTTP server。
file:一个unix domain socket的文件路径,HTTP/XML-RPC会监听在这上面
chmod:在启动时修改unix domain socket的mode
chown:修改socket文件的属主
username:HTTP server在认证时的用户名
password:认证密码<span style="font-family:'Microsoft YaHei';font-size:16px;line-height:1.5;"></span>
eg: