以下是我的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
这是我得到的错误:
INFO spawnerr: can't find command 'source'
bash 不应该有命令源吗?如果这是使用 sh
我如何强制它运行 bash?
最佳答案
Supervisor 根本不启动 shell,无论是 bash
还是 sh
-- 所以它找不到 shell 也就不足为奇了-内置命令。如果你需要一个,你必须自己开始一个。因此:
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
和
command=/bin/bash -c 'source "$0" && exec "$@"' /opt/ros/indigo/setup.bash django-admin runworker
在这两种情况下,exec
都会告诉 shell 将内存中的自身替换为正在执行的进程,而不是让 shell 实例只等待该进程退出.
bash -c
之后的第一个参数放在$0
中,后面的参数放在$1
中;因此,我们可以获取 "$0"
并执行 "$@"
来引用第一个这样的参数,然后是相同的后续参数。
来自 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.
因此,同样不能期望 shell 操作(包括 &&
)在顶层可用。
关于bash - 为什么主管找不到命令源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43076406/