Question

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)

Était-ce utile?

La solution

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.

Autres conseils

I was able to use a system environment variable in a Supervisor command like this:

command=php artisan queue:listen --env=%(ENV_APP_ENVIRONMENT)s

The above command will expand to command=php artisan queue:listen --env=production if the APP_ENVIRONMENT environment variable is production.

Note: In the Supervisor config, you must prefix your system environment variables with ENV_, as specified in the documentation here.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top