I plan to store some application settings in environment variables, such as MYSQL_URL=mysql://... I use supervisord to manage the application process. How to load environment variables before the subprocess is started? Especially when these settings are changed, I hope a restart of the subprocess will load the new settings.
Also I'm wondering where to store these environment variables. A file that I can "export $(cat filename)"? Or some better ways. I'm curious how Heroku manage its environment variables.
You can set per-process environment variables in the supervisord configuration in the [program:x
] section, these will be passed to the process when it starts:
[program:yourprocess]
# ... other settings
environment =
MYSQL_URL=mysql://,
OTHER_VAR="some other value"
Note that you need to use a comma between each variable. I used newlines in the above example as well, those are optional. If you have spaces in your environment values you need to enclose the value in quotes.
You can also set environment variables for all processes in the [supervisord]
section, using the same format.
Last but not least, any environment variables set when supervisord starts are passed on to the processes managed by supervisord too. See the documentation section on environment variables for details.
Do note that if you change environment variables configured in the configuration file, you'll need to signal to supervisord to reload the configuration and restart the subprocesses for them to pick up these changes:
supervisorctl update
supervisorctl restart yourprocess
If however you change environment variables outside of supervisord, you'll need to shut down supervisord all together to pick these up:
supervisorctl shutdown
supervisord
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With