有条件地运行supervisord程序

时间:2016-03-29 16:21:40

标签: supervisord

假设我在监督中有两个节目。有没有办法有条件地运行第一个程序(后台进程)而不必将其移动到单独的脚本文件?

[supervisord]
nodaemon=true
logfile=/tmp/supervisord.log

#Need this program to run conditionally - say based off an environment variable being set
[program:prog1]
command=/bin/prog1

[program:prog2]
command=/bin/prog2 -DFOREGROUND

2 个答案:

答案 0 :(得分:1)

将条件值传递给 SERVER1_START 并控制流程。

[program:somecommand]
command=bash -c "if [ ${SERVER1_START} = "VALUE-X" ]; then /apps/bin/start.sh 
/apps/server.properties; fi"

答案 1 :(得分:0)

正在恢复旧线程,但是@nelson的答案不完整。即,超级用户中的环境变量需要被格式化为%(ENV_YOURVARIABLE)s才能被识别(注意前缀ENV_%放在方括号之前,s末尾)。此外,您必须先导出它,然后再将其发送到bash脚本:

[program:prog1]
command=bash -c "export INIT_PROG=%(ENV_INIT_PROG)s  && ./conditional-startup.sh"

conditional-startup.sh:

#!/bin/bash

if [ $INIT_PROG = "some value" ]; then
    /bin/prog1
fi

另请参见: