Why use `bash -c` in supervisor instead of calling script directly?

I'm beginning to use supervisord to control services in my server. I'm not a pro user of linux but can get with it quite well and get it running.

Just out of curiosity, I've noticed that most commands in supervisord seem to be called like:

[program:install]
command=bash -c "/src/etc/install.sh"

I've read bash's man, and know that -c should be used to insert variables passed after the string.

So what's the point in using bash -c in supervisor (or any other place) instead of calling the script directly (like example below), considering that no variables where passed/used?

[program:install]
command=/src/etc/install.sh

Thanks!


Solution 1:

Shell features such as pathname expansion (*, ?), command lists (;, &&, ||), redirection (<, >, |,) are not implemented by supervisord that only splits the command into an array of argument strings.

The bash -c may be just a help for novice user who might be tempted to use such features in the command. For example it avoids the surprise that

command=echo foo > /tmp/bar

outputs foo > /tmp/bar instead of writing foo to /tmp/bar.

-c has little to do with variables. Any additional arguments to the bash would only be available as script arguments $0, $1, etc. in the command, but that feature has seldom any use. For example bash -c 'echo $0 $0' foo outputs foo foo.

Solution 2:

It is explained in the documentation:

No shell is executed by supervisord when it runs a subprocess, so environment variables such as USER, PATH, HOME, SHELL, LOGNAME, etc. are not changed from their defaults or otherwise reassigned. This is particularly important to note when you are running a program from a supervisord run as root with a user= stanza in the configuration.

To get around this issue bash -c may be used.