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

Created on 16 Jun 2014  Â·  3Comments  Â·  Source: Supervisor/supervisor

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

Most helpful comment

3.2 didn’t exist yet when I wrote this over 4 years ago 🙄

On Thu, Oct 18, 2018 at 1:49 AM Dumitrescu Robert notifications@github.com
wrote:

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

—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
https://github.com/Supervisor/supervisor/issues/447#issuecomment-430894666,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAJXc_Y0Zd4ykEzNc7eH4CZhz09RTVLNks5umCRhgaJpZM4CEaUX
.

All 3 comments

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

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

3.2 didn’t exist yet when I wrote this over 4 years ago 🙄

On Thu, Oct 18, 2018 at 1:49 AM Dumitrescu Robert notifications@github.com
wrote:

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

—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
https://github.com/Supervisor/supervisor/issues/447#issuecomment-430894666,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAJXc_Y0Zd4ykEzNc7eH4CZhz09RTVLNks5umCRhgaJpZM4CEaUX
.

Was this page helpful?
0 / 5 - 0 ratings