避免多个程序的supervisord配置重复

var*_*tec 5 linux supervisord

我必须运行同一应用程序的多个实例,但设置略有不同。唯一改变的是一个命令行参数。

所以目前我的脚本看起来像这样:

[program:thing-one]
command=/usr/local/thing --instance one
user=a_user
stdout_logfile=/var/log/thing.log
autostart=true
autorestart=true
startsecs=10
redirect_stderr=true
directory=/
startretries=1000

[program:thing-two]
command=/usr/local/thing --instance two
user=a_user
stdout_logfile=/var/log/thing.log
autostart=true
autorestart=true
startsecs=10
redirect_stderr=true
directory=/
startretries=1000

[program:thing-three]
command=/usr/local/thing --instance three
user=a_user
stdout_logfile=/var/log/thing.log
autostart=true
autorestart=true
startsecs=10
redirect_stderr=true
directory=/
startretries=1000
Run Code Online (Sandbox Code Playgroud)

如何避免重复相同的设置?

san*_*mai 0

由于同一程序只有三个实例,仅在一个参数上有所不同,因此我们可以在内部使用 Python 的字符串表达式扩展,command如下所示。

[program:things]
command=/usr/local/thing --instance %(process_num)s
numprocs=3
user=a_user
stdout_logfile=/var/log/thing.log
autostart=true
autorestart=true
startsecs=10
redirect_stderr=true
directory=/
startretries=1000
Run Code Online (Sandbox Code Playgroud)

与您的配置相比,我更改了两行并添加了一行。

此外,文档说如果您使用numprocs> 1,则必须包含所述扩展。