Why can't supervisor find command source

Supervisor does not start a shell at all, either bash or sh -- so it's no surprise that it can't find shell-builtin commands. If you need one, you're obliged to start one yourself. Thus:

command=/bin/bash -c 'source "$0" && exec "$@"' /opt/ros/indigo/setup.sh daphne -b 0.0.0.0 -p 8000 robot_configuration_interface.asgi:channel_layer

and

command=/bin/bash -c 'source "$0" && exec "$@"' /opt/ros/indigo/setup.bash django-admin runworker

In both these cases, the exec is present to tell the shell to replace itself in-memory with the process it's executing rather than leaving a shell instance that does nothing but wait for that process to exit.

The first argument after bash -c is placed in $0, and subsequent ones after that are placed in $1 and onward; thus, we can source "$0" and execute "$@" to refer to the first such argument and then those subsequent to same.


From the docs:

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.

Thus, shell operations (including &&) similarly cannot be expected to be usable at top level.


I also encounter this problem.

And I found a better solution.

Using source ~/.bash_profile maybe better.

[program: dapi]
user=pyer
command=/bin/bash -c 'source ~/.bash_profile  && /usr/local/python3.6/bin/pipenv run python manage.py'
directory=/data/prd/tools/dapi
autostart=true
startretries=1
stopasgroup=true

If the process started by supervisor created subprocesses, maybe can ref: http://supervisord.org/subprocess.html#pidproxy-program