bash - 为什么主管找不到命令源

标签 bash supervisord

以下是我的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/

相关文章:

bash - Raspberry Pi : No X11 DISPLAY variable was set, 但该程序执行了需要它的操作

linux - 有没有办法知道 Linux 中的初始化脚本存储在哪里?

django - 通过 Ansible 为 supervisorctl 管理的 Python 应用程序修改 PYTHONPATH

php - 当 Laravel 队列 :listen times out 时获取当前正在运行的任务

django - Supervisord 抛出错误 : "couldn' t exec/var/application/gunicorn_start: ENOEXEC"

bash - 遇到 IOException 运行导入作业 : java. io.IOException:javac 返回的错误

linux - bash脚本中的简单数学计算

linux - 我如何保证我有一个进程始终启动并运行?

linux - 如何获得流入数据库中当前值和先前值之间的差异

php - 为什么 Laravel 或 Beanstalkd 会跳槽?