Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't supervisor find command source

The following is my supervisor.conf.

[supervisord]
nodaemon=true

[program:daphne]
command=source "/opt/ros/indigo/setup.sh" && daphne -b 0.0.0.0 -p 8000 robot_configuration_interface.asgi:channel_layer

[program:worker]
environment=DJANGO_SETTINGS_MODULE="robot_configuration_interface.settings"
command= source "/opt/ros/indigo/setup.bash" && django-admin runworker

This is the error I get:

INFO spawnerr: can't find command 'source'

Shouldn't the bash have the command source. If this is using sh how can I force it to run bash?

like image 458
cjds Avatar asked Mar 28 '17 17:03

cjds


2 Answers

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.

like image 193
Charles Duffy Avatar answered Nov 11 '22 13:11

Charles Duffy


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

like image 8
Jian Dai Avatar answered Nov 11 '22 14:11

Jian Dai