【发布时间】:2014-08-05 20:03:58
【问题描述】:
我正在尝试使用现有环境变量的值在我的 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?)
然后,根据this answer,我尝试使用%(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
我做错了什么?
编辑:
$supervisord --version
3.0b2
【问题讨论】:
标签: python supervisord