I would like to put configuration (in this case, site name) into supervisor environment variables, for expansion in program:x command arguments. Is this supported? The documentation's wording would seem to indicate yes.
The following syntax is not working for me on supervisor-3.0 (excerpt of config file):
[supervisord] environment = SITE="mysite" [program:service_name] command=/path/to/myprog/myservice /data/myprog/%(ENV_SITE)s/%(ENV_SITE)s.db %(program_name)s_%(process_num)03d process_name=%(program_name)s_%(process_num)03d numprocs=5 numprocs_start=1
Raises the following error:
sudo supervisord -c supervisord.conf Error: Format string '/path/to/myprog/myservice /data/myprog/%(ENV_SITE)s/%(ENV_SITE)s.db %(program_name)s_%(process_num)03d' for 'command' contains names which cannot be expanded
Reading the documentation, I expected environment variables to be available for expansion in program:x command as %(ENV_VAR)s:
http://supervisord.org/configuration.html#program-x-section-values
command:
"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_."
Introduced: 3.0
Related:
There are open pull requests to enable expansion in additional section values:
https://github.com/Supervisor/supervisor/issues?labels=expansions&page=1&state=open
A search of goole (or SO) returns no examples of attempts to use %(ENV_VAR)s expansion in the command section value:
https://www.google.com/search?q=supervisord+environment+expansion+in+command
So with that patch, supervisor looks for supervisord. conf in the local directory, in the etc/ subdirectory, then in the global /etc/supervisor/ and /etc/ directories. causing supervisord to load any extra files put in the conf. d directory.
Once our configuration file is created and saved, we can inform Supervisor of our new program through the supervisorctl command. First we tell Supervisor to look for any new or changed program configurations in the /etc/supervisor/conf. d directory with: sudo supervisorctl reread.
To start supervisord, run $BINDIR/supervisord. The resulting process will daemonize itself and detach from the terminal. It keeps an operations log at $CWD/supervisor.
I agree supervisor is not clear about this ( to me at least ).
I've found the easiest solution to execute /bin/bash -c. In your case it would be:
command=/bin/bash -c"/path/to/myprog/myservice /data/myprog/${SITE}/${SITE}.db ..."
What do you think?
I've found inspiration here: http://blog.trifork.com/2014/03/11/using-supervisor-with-docker-to-manage-processes-supporting-image-inheritance/
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