environment-variablessupervisord

How can I reuse an environment definition of a supervisor process for multiple processes


I have multiple supervisor programs defined and they all have the same environment variables defined, now I needed to add a new one and I had to add it to each program section. Is there a way to define a environment variable which is valid for the whole supervisor config file and which I could reuse? E.g file under /etc/supervisor/conf.d/foo.conf:

my_env=foo=2,bar="hi",zee="ok"

[program:foo]
environment=my_env

[program:bar]
environment=my_env

Solution

  • Yes, that's possible. You may add your custom environment key-values into the Supervisord section, below the environment key.

    environment

    A list of key/value pairs in the form KEY="val",KEY2="val2" that will be placed in the environment of all child processes. This does not change the environment of supervisord itself. This option can include the value %(here)s, which expands to the directory in which the supervisord configuration file was found. Values containing non-alphanumeric characters should be quoted (e.g. KEY="val:123",KEY2="val,456"). Otherwise, quoting the values is optional but recommended. To escape percent characters, simply use two. (e.g. URI="/first%%20name") Note that subprocesses will inherit the environment variables of the shell used to start supervisord except for the ones overridden here and within the program’s environment option. See Subprocess Environment.

    Since you have multiple supervisor programs running, I believe you will need to specify this environment key-value pairs in the [supervisord] section of each .conf file.

    Edit: To clarify OP's confusion in comments, [supervisord] section is different from a [program] section.