Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why can't I seem to set an environment variable using another environment variable's value? #447

Closed
abevoelker opened this issue Jun 16, 2014 · 3 comments

Comments

@abevoelker
Copy link

I'm trying to set an environment variable in my supervisord config by using the value of an existing environment variable. The existing variable is REDIS_PORT_6379_TCP_ADDR (comes from a Docker linked container); the value is an IP address (e.g. 172.17.0.5). This was my first naive attempt:

[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

Which doesn't work at all as supervisord can't parse it:

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

Then I tried quoting the environment section:

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

That didn't work as the variable didn't get interpolated before being passed to my program:

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?)

Then, per this StackOverflow answer, I tried using the %(ENV) syntax:

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

Once again it can't parse it:

$ 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

Same result if I remove the double quotes:

$ 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

I've tried the same things by putting export into the command section:

[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

Result:

$ 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

Result:

$ 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

What am I doing wrong?

I'm on 3.0b2:

$supervisord --version
3.0b2
@abevoelker
Copy link
Author

Guess my feeble Python abilities are showing. I needed to add an s to the end of %() to format the value as a string. This config works, finally:

[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

@robertdumitrescu
Copy link

You're using the wrong version. That syntax is properly supported by supervisor 3.2.

@abevoelker
Copy link
Author

abevoelker commented Oct 18, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants