supervisor配置文件

近期在看supervisor相关的知识,这里简单的对配置文件里的一些参数做些简单的翻译,加强自己的记忆的同时,方便后续查看!

##配置文件

一般配置文件都命名为supervisord.conf,且这个文件为supervisord和supervisorctl共用。如果启动时没有使用-c选项,那么就会按照如下顺序查找,使用第一个找到的配置文件

1
2
3
4
5
6
1. $CWD/supervisord.conf
2. $CWD/etc/supervisord.conf
3. /etc/supervisord.conf
4. /etc/supervisor/supervisord.conf (since Supervisor 3.3.0)
5. ../etc/supervisord.conf (Relative to the executable)
6. ../supervisord.conf (Relative to the executable)

[unix_http_server]

这部分的配置参数用于HTTP服务器监听一个UNIX域socket的。允许的配置参数如下。

file

存放UNIX域socket文件的路径(/tmp/supervisord.sock),supervisor通过它来监听HTTP/XML_RPC请求。supervisorctl通过这个端口用XML-RPC来与supervisord通信。该选项可以使用%(here)s值,表示supervisord配置文件所在位置。

默认值:None

是否必须:否

引入版本:3.0

chmod

socket文件在supervisor启动时的权限值。

默认值:0700

是否必须:否

引入版本:3.0

chown

改变socket文件的所有者和所属群组。

默认值:启动supervisord的用户名及其群组

是否必须:否

引入版本:3.0

username

用于HTTP服务器认证的用户名。

默认值:无

是否必须:否

引入版本:3.0

password

用于HTTP服务器认证的密码,可以是明文,也可以SHA-1密文(以{SHA}开头)

默认值:无

是否必须:否

引入版本:3.0

[unix_http_server]简单实例

1
2
3
4
5
6
[unix_http_server]
file = /tmp/supervisor.sock
chmod = 0777
chown= nobody:nogroup
username = user
password = 123

[inet_http_server]

这部分的配置参数用于HTTP服务器监听一个TCP socket的。允许的配置参数如下。

port

一个TCP主机:端口值(如,127.0.0.1:9001),supervisor通过它来监听HTTP/XML_RPC请求。supervisorctl通过这个端口用XML-RPC来与supervisord通信。

默认值:无

是否必须:否

引入版本:3.0

username

用于HTTP服务器认证的用户名。

默认值:无

是否必须:否

引入版本:3.0

password

用于HTTP服务器认证的密码,可以是明文,也可以SHA-1密文(以{SHA}开头)

默认值:无

是否必须:否

引入版本:3.0

[inet_http_server]简单实例

1
2
3
4
[inet_http_server]
port = 127.0.0.1:9001
username = user
password = 123

[supervisord]

与supervisord进程相关的全局配置,具体参数如下

logfile

supervisord进程活动日志存放路径。使用%(here)s表示配置文件所在路径。

默认值:$CWD/supervisord.log

是否必须:否

引入版本:3.0

logfile_maxbytes

logfile文件大小最大值,设为0表示不限制大小。

默认值:50MB

是否必须:否

引入版本:3.0

logfile_backups

最多保留logfile文件数目,设为0表示不保存。

默认值:10

是否必须:否

引入版本:3.0

loglevel

日志级别,值为critical, error, warn, info, debug, traceblather中的一个。

默认值:info

是否必须:否

引入版本:3.0

pidfile

supervisord保存pid文件路径。使用%(here)s表示配置文件所在路径。

默认值:$CWD/supervisord.pid

是否必须:否

引入版本:3.0

umask

supervisord进程的umask

默认值:022

是否必须:否

引入版本:3.0

nodaemon

值为true时,supervisord将以非后台程序运行。

默认值:false

是否必须:否

引入版本:3.0

minfds

supervisord启动时所需的最小文件描述符个数。

默认值:1024

是否必须:否

引入版本:3.0

minprocs

supervisord启动时所需的最小进程描述符个数。

默认值:200

是否必须:否

引入版本:3.0

nocleanup

避免supervisord在启动时清理任何已经存在的AUTO子log文件。

默认值:false

是否必须:否

引入版本:3.0

childlogdir

AUTO子log文件存储路径,使用%(here)s表示配置文件所在路径。

默认值:Python的tempfile.get_tempdir()

是否必须:否

引入版本:3.0

user

Instruct supervisord to switch users to this UNIX user account before doing any meaningful processing。

默认值:不切换用户

是否必须:否

引入版本:3.0

directory

当supervisors在后台运行时,切换到这个路径。

默认值:不切换路径

是否必须:否

引入版本:3.0

strip_ansi

去掉子日志文件中所有ANSI escape sequences。

默认值:不切换用户

是否必须:否

引入版本:3.0

environment

形如 KEY="val",KEY2="val2" 的键值对列表,用于替换supervisord进程环境(包括子进程环境)。

默认值:无

是否必须:否

引入版本:3.0

identifier

supervisor进程识别码,用于RPC接口。

默认值:supervisor

是否必须:否

引入版本:3.0

[supervisord]简单实例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[supervisord]
logfile = /tmp/supervisord.log
logfile_maxbytes = 50MB
logfile_backups=10
loglevel = info
pidfile = /tmp/supervisord.pid
nodaemon = false
minfds = 1024
minprocs = 200
umask = 022
user = chrism
identifier = supervisor
directory = /tmp
nocleanup = true
childlogdir = /tmp
strip_ansi = false
environment = KEY1="value1",KEY2="value2"

[supervisorctl]

supervisorctl交互shell程序配置,具体如下

serverurl

supervisord服务器url。对于UNIX域socket,使用 unix:///absolute/path/to/file.sock.

默认值: http://localhost:9001

是否必须:否

引入版本:3.0

username

传给supervisord服务器的username,应该与supervisord服务器username一致。

默认值:无

是否必须:否

引入版本:3.0

password

同上。

默认值: 无

是否必须:否

引入版本:3.0

prompt

supervisorctl提示词。

默认值:supervisor

是否必须:否

引入版本:3.0

history_file

不懂有啥用。

默认值:无

是否必须:否

引入版本:3.0

[supervisorctl]简单实例

1
2
3
4
5
[supervisorctl]
serverurl = unix:///tmp/supervisor.sock
username = chris
password = 123
prompt = mysupervisor

[program:x]

必须包含程序名,可以用 %(program_name)s 来表示。可以有一个或多个次模块。模块内的参数如下

command

此程序启动时要执行的命令。可以是绝对路径 /path/to/programname,也可以是相对路径 programname

默认值:无

是否必须:是

引入版本:3.0

process_name

程序名。

默认值: %(program_name)s

是否必须:否

引入版本:3.0

numprocs

进程数量,如果其值大于1,那么process_name必须包含%(process_num)s

默认值:1

是否必须:否

引入版本:3.0

numprocs_start

numprocs 起始值。

默认值:0

是否必须:否

引入版本:3.0

priority

程序的相对优先级,越小越先启动越晚关闭。

默认值:999

是否必须:否

引入版本:3.0

autostart

为true时,程序可以自动重启。

默认值:true

是否必须:否

引入版本:3.0

startsecs

程序需要保持运行状态startsecs秒后,才会被认为是启动成功(进程从STARTING状态转为RUNNING状态)。设置为0时,表示不需要保持运行状态特定的秒数,我理解的就是,直接认为启动成功。

默认值:1

是否必须:否

引入版本:3.0

startretries

程序启动失败后,尝试重启的次数。若仍未成功,设置进程状态为FATAL。

默认值:3

是否必须:否

引入版本:3.0

autorestart

当进程在运行时,出现 false, unexpected, true中一个时,尝试重新启动。为false时该进程不会自己重新启动;为unexpected时,当出现exitcodes定义以外的退出码时重新启动;为true时进程无条件重启。

默认值:unexpected

是否必须:否

引入版本:3.0

exitcodes

预期的退出码列表。

默认值:0,2

是否必须:否

引入版本:3.0

stopsignal

杀死进程的信号,可以为TERM, HUP, INT, QUIT, KILL, USR1, USR2中的一个。

默认值:TERM

是否必须:否

引入版本:3.0

stopwaitsecs

在程序收到stopsignal后,supervisord等待OS返回SIGCHLD的秒数。超出这个时间仍未收到SIGCHLD时,supervisord会尝试以SIGKILL信号杀死程序。

默认值:10

是否必须:否

引入版本:3.0

stopasgroup

为true时,supervisor会给进程组发送stop信号。

默认值:false

是否必须:否

引入版本:3.0

killasgroup

为true时,给进程组发送SIGKILL信号。

默认值:false

是否必须:否

引入版本:3.0

user

Instruct supervisord to use this UNIX user account as the account which runs the program. The user can only be switched if supervisord is run as the root user. If supervisord can’t switch to the specified user, the program will not be started.

默认值:不切换用户

是否必须:否

引入版本:3.0

redirect_stderr

为true时,进程的stderr会送回supervisord的stdout文件描述符。类似于 /the/program 2>&1。在 [eventlistener:x] 区域不要设置 redirect_stderr=true,Eventlisteners使用stdout和stdin与supervisord通信,如果stderr重定向了,stderr的输出会干扰eventlistener协议。

默认值:false

是否必须:否

引入版本:3.0,替换2.0的log_stdoutlog_stderr

stdout_logfile

将进程的stdout输出到此文件中,如果redirect_stderr为true,则将stderr也输出到此文件中。如果stdout_logfile 未设置或者设置为AUTO,supervisor会自动选择一个文件位置。如果设置为NONE,则不创建log文件。当supervisord重启时,AUTO log文件和其备份会被删除。注意,当rotation没有开启时,两个进程共享一个log文件会造成文件混乱。

默认值:AUTO

是否必须:否

引入版本:3.0,替换2.0的logfile

stdout_logfile_maxbytes

stdout_logfile最大值。

默认值:50MB

是否必须:否

引入版本:3.0,替换2.0的logfile_maxbytes

stdout_logfile_backups

默认值:10

是否必须:否

引入版本:3.0,替换2.0的logfile_backups

stdout_capture_maxbytes

stdout capture mode使用。

默认值:0

是否必须:否

引入版本:3.0

stdout_events_enabled

不懂。

默认值:0

是否必须:否

引入版本:3.0a7

stderr_logfile

默认值:AYTO

是否必须:否

引入版本:3.0

stderr_logfile_maxbytes

默认值:50MB

是否必须:否

引入版本:3.0

stderr_logfile_backups

默认值:10

是否必须:否

引入版本:3.0

stderr_capture_maxbytes

默认值:0

是否必须:否

引入版本:3.0

stderr_events_enabled

默认值:false

是否必须:否

引入版本:3.0

environment

见上。

默认值:无

是否必须:否

引入版本:3.0

directory

默认值:无

是否必须:否

引入版本:3.0

umask

默认值:无,继承supervisor的

是否必须:否

引入版本:3.0

serverurl

默认值:AUTO

是否必须:否

引入版本:3.0

program:x简单实例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[program:cat]
command=/bin/cat
process_name=%(program_name)s
numprocs=1
directory=/tmp
umask=022
priority=999
autostart=true
autorestart=unexpected
startsecs=10
startretries=3
exitcodes=0,2
stopsignal=TERM
stopwaitsecs=10
stopasgroup=false
killasgroup=false
user=chrism
redirect_stderr=false
stdout_logfile=/a/path
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=10
stdout_capture_maxbytes=1MB
stdout_events_enabled=false
stderr_logfile=/a/path
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=10
stderr_capture_maxbytes=1MB
stderr_events_enabled=false
environment=A="1",B="2"
serverurl=AUTO

[include]

引入其他配置文件。只有supervisord用到,supervisorctl不用。

files

默认值:无

是否必须:是

引入版本:3.0

[include]简单实例

1
2
[include]
files = /an/absolute/filename.conf /an/absolute/*.conf foo.conf config??.conf

[group:x]

[group:x]简单实例

1
2
3
[group:foo]
programs=bar,baz
priority=999

[fcgi-program:x]

[fcgi-program:x]简单实例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
[fcgi-program:fcgiprogramname]
command=/usr/bin/example.fcgi
socket=unix:///var/run/supervisor/%(program_name)s.sock
socket_owner=chrism
socket_mode=0700
process_name=%(program_name)s_%(process_num)02d
numprocs=5
directory=/tmp
umask=022
priority=999
autostart=true
autorestart=unexpected
startsecs=1
startretries=3
exitcodes=0,2
stopsignal=QUIT
stopasgroup=false
killasgroup=false
stopwaitsecs=10
user=chrism
redirect_stderr=true
stdout_logfile=/a/path
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=10
stdout_events_enabled=false
stderr_logfile=/a/path
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=10
stderr_events_enabled=false
environment=A="1",B="2"
serverurl=AUTO

[eventlistener:x]

以下是[program:x] 没有的参数

buffer_size

事件监听池事件队列缓存大小。满时,最早的事件会被遗弃。

events

监听器想要接收到的事件通知,以逗号分隔的事件类型名列表。

result_handler

默认值为supervisor.dispatchers:default_handler

[eventlistener:x]简单实例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[eventlistener:theeventlistenername]
command=/bin/eventlistener
process_name=%(program_name)s_%(process_num)02d
numprocs=5
events=PROCESS_STATE
buffer_size=10
directory=/tmp
umask=022
priority=-1
autostart=true
autorestart=unexpected
startsecs=1
startretries=3
exitcodes=0,2
stopsignal=QUIT
stopwaitsecs=10
stopasgroup=false
killasgroup=false
user=chrism
redirect_stderr=false
stdout_logfile=/a/path
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=10
stdout_events_enabled=false
stderr_logfile=/a/path
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=10
stderr_events_enabled=false
environment=A="1",B="2"
serverurl=AUTO

[rpcinterface:x]

[rpcinterface:x]简单实例

1
2
3
[rpcinterface:another]
supervisor.rpcinterface_factory = my.package:make_another_rpcinterface
retries = 1

就写到这吧,翻译文档真的是一件很无聊的事情啊!

谢谢支持