【问题标题】:Supervisord overriding environmental variablesSupervisord 覆盖环境变量
【发布时间】:2018-01-24 16:02:41
【问题描述】:

我有一个通过 supervisord 管理的应用程序(部署在 docker 容器中)

我的supervisord.conf 看起来像:

[supervisord]
nodaemon=true
logfile=/var/log/supervisor/supervisord.log
loglevel=INFO

[program:anjay]
priority=1
#USE SOME_CLI for different run configurations
command=/some/binary %(ENV_SOME_CLI)s
stdout_logfile=/dev/fd/1
stderr_logfile=/dev/fd/2
stdout_logfile_maxbytes=0
stderr_logfile_maxbytes=0
autostart=true
autorestart=false
stopsignal=INT
user=root

我希望能够使用不同的参数重新启动 /some/binary(由 SOME_CLI 环境变量驱动)
第一次启动应用程序完美运行,参数被扩展。例如:

export SOME_CLI=A
/some/binary A

然后我想exportSOME_CLI=B,我希望重启后:

export SOME_CLI=B
/some/binary B

可惜还是有

/some/binary A

是否可以通过这种方式使用不同的参数重新启动已配置的应用程序?
如果没有,如何实现这样的功能?

备注:我知道我的应用程序部署在容器中,我可以使用不同的参数重新启动容器。这似乎不是正确的做法(重新启动整个容器只是为了更改一些参数)。

如果我错了,请纠正我

【问题讨论】:

  • 第一件事在容器内运行主管。容器旨在运行一个应用程序且仅运行一个应用程序。它不是一个虚拟机,它是一个容器。环境变量被读取一次,除非进程重新启动,否则不会更新。

标签: docker environment-variables restart supervisord application-restart


【解决方案1】:

直接在你的conf文件的[program]部分添加环境变量,如:

[program:anjay]
environment=ENV_SOME_CLI=your_value

通过使用 supervisorctl update 告诉 supervisord 该文件有更改来应用更改。

【讨论】:

  • 再次尝试不直接调用二进制文件,而是运行一个 shell 脚本,其中存在实际命令和对环境变量的引用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多