Supervisor: 为什么我似乎不能使用另一个环境变量的值来设置环境变量?

创建于 2014-06-16  ·  3评论  ·  资料来源: Supervisor/supervisor

我正在尝试通过使用现有环境变量的值在我的 supervisord 配置中设置一个环境变量。 现有变量是REDIS_PORT_6379_TCP_ADDR (来自 Docker 链接容器); 该值是一个 IP 地址(例如172.17.0.5 )。 这是我第一次天真的尝试:

[program:sidekiq]
user=web
directory=/var/www
environment=REDIS_URL=redis://$REDIS_PORT_6379_TCP_ADDR:6379/0
command=bundle exec sidekiq -c 50
redirect_stderr=true
autorestart=true

这根本不起作用,因为 supervisord 无法解析它:

$ supervisord -c /etc/supervisor/supervisord.conf -n
Error: Unexpected end of key/value pairs
For help, use /usr/bin/supervisord -h

然后我尝试引用环境部分:

environment=REDIS_URL="redis://$REDIS_PORT_6379_TCP_ADDR:6379/0"

这不起作用,因为变量在传递给我的程序之前没有被插值:

2014-06-16T03:08:35Z 240 TID-oqy09ga9c WARN: the scheme redis does not accept registry part: $REDIS_PORT_6379_TCP_ADDR:6379 (or bad hostname?)

然后,根据这个 StackOverflow 答案,我尝试使用%(ENV)语法:

environment=REDIS_URL="redis://%(ENV_REDIS_PORT_6379_TCP_ADDR):6379/0"

它再次无法解析它:

$ supervisord -c /etc/supervisor/supervisord.conf -n                              
Error: Format string 'REDIS_URL="redis://%(ENV_REDIS_PORT_6379_TCP_ADDR):6379/0"' for 'environment' is badly formatted
For help, use /usr/bin/supervisord -h

如果我删除双引号,结果相同:

$ supervisord -c /etc/supervisor/supervisord.conf -n
Error: Format string 'REDIS_URL=redis://%(ENV_REDIS_PORT_6379_TCP_ADDR):6379/0' for 'environment' is badly formatted
For help, use /usr/bin/supervisord -h

我通过将export放入command部分来尝试相同的事情:

[program:sidekiq]
user=web
directory=/var/www
command="export REDIS_URL=redis://$REDIS_PORT_6379_TCP_ADDR:6379/0; bundle exec sidekiq -c 50"
redirect_stderr=true
autorestart=true

结果:

$ supervisord -c /etc/supervisor/supervisord.conf -n
2014-06-16 03:35:00,170 WARN Included extra file "/etc/supervisor/conf.d/sidekiq.conf" during parsing
2014-06-16 03:35:00,193 INFO RPC interface 'supervisor' initialized
2014-06-16 03:35:00,194 INFO supervisord started with pid 346
2014-06-16 03:35:01,197 INFO spawnerr: can't find command 'export REDIS_URL=redis://$REDIS_PORT_6379_TCP_ADDR:6379/0; bundle exec sidekiq -c 50'
[program:sidekiq]
user=web
directory=/var/www
command="export REDIS_URL=redis://%(ENV_REDIS_PORT_6379_TCP_ADDR):6379/0; bundle exec sidekiq -c 50"
redirect_stderr=true
autorestart=true

结果:

$ supervisord -c /etc/supervisor/supervisord.conf -n                              
Error: Format string '"export REDIS_URL=redis://%(ENV_REDIS_PORT_6379_TCP_ADDR):6379/0; bundle exec sidekiq -c 50"' for 'command' is badly formatted
For help, use /usr/bin/supervisord -h

我究竟做错了什么?

我在 3.0b2:

$supervisord --version
3.0b2

最有用的评论

4 年前我写这篇文章时,3.2 还不存在🙄

2018 年 10 月 18 日星期四凌晨 1:49 Dumitrescu Robert [email protected]
写道:

你使用了错误的版本。 该语法得到了正确的支持
主管 3.2.


您收到此消息是因为您修改了打开/关闭状态。
直接回复此邮件,在 GitHub 上查看
https://github.com/Supervisor/supervisor/issues/447#issuecomment-430894666
或使线程静音
https://github.com/notifications/unsubscribe-auth/AAJXc_Y0Zd4ykEzNc7eH4CZhz09RTVLNks5umCRhgaJpZM4CEaUX
.

所有3条评论

猜猜我微弱的 Python 能力正在表现出来。 我需要在%()的末尾添加一个s以将值格式化为字符串。 这个配置终于起作用了:

[program:sidekiq]
user=web
directory=/var/www
environment=REDIS_URL=redis://%(ENV_REDIS_PORT_6379_TCP_ADDR)s:6379/0
command=bundle exec sidekiq -c 50
redirect_stderr=true
autorestart=true

你使用了错误的版本。 主管 3.2 正确支持该语法。

4 年前我写这篇文章时,3.2 还不存在🙄

2018 年 10 月 18 日星期四凌晨 1:49 Dumitrescu Robert [email protected]
写道:

你使用了错误的版本。 该语法得到了正确的支持
主管 3.2.


您收到此消息是因为您修改了打开/关闭状态。
直接回复此邮件,在 GitHub 上查看
https://github.com/Supervisor/supervisor/issues/447#issuecomment-430894666
或使线程静音
https://github.com/notifications/unsubscribe-auth/AAJXc_Y0Zd4ykEzNc7eH4CZhz09RTVLNks5umCRhgaJpZM4CEaUX
.

此页面是否有帮助?
0 / 5 - 0 等级