11

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!

11

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.

  • 1
    Thanks, that was a very pragmatic answer, and that'll probably save me a lot of time. I, as a novice user, would make this mistake (and never think about bash -c as a solution!). – Daniel Costa Sep 16 '15 at 20:11
6

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.

  • 2
    Mark, thanks for your answer but I think the other one was a more plausible scenario (while yours is not incorrect to me, I still need to choose one right answer..). Besides that, i'm also helping the new user with fewer points. – Daniel Costa Sep 16 '15 at 20:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.