How to use environment variables in supervisord commands

daveoncode picture daveoncode · Mar 7, 2014 · Viewed 14.4k times · Source

How can I use an environment variable in a supervisord command? I tried:

flower --broker=$MYVAR

but it doesn't work (variable is not expanded), so I tried using an inline python script:

command=python -c "import os;os.system('flower --broker={0}'.format(os.environ['MYVAR']))"

The command above works, but then I'm unable to terminate the process using supervisorctl stop ...I get "stopped" back but the process is actually still running! How can I solve my issue? (I don't want to put that parameter inline)

Answer

robbyt picture robbyt · Jun 11, 2015

According to the Supervisor docs, you can access environment variables in the command by prefixing ENV_ like: %(ENV_YOUR_VAR)s

http://supervisord.org/configuration.html#environment-variables

String expressions are evaluated against a dictionary containing the keys group_name, host_node_name, process_num, program_name, here (the directory of the supervisord config file), and all supervisord’s environment variables prefixed with ENV_.

However, according to this commit: https://github.com/Supervisor/supervisor/commit/2d6ca34582a8a07a5dd96ae45ef62cd58a459f4f this feature was added after version 3.2.