bash 为什么supervisor找不到命令源

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43076406/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 15:56:56  来源:igfitidea点击:

Why can't supervisor find command source

bashsupervisord

提问by cjds

The following is my supervisor.conf.

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

信息 spawnerr:找不到命令“源”

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

bash 不应该有命令源。如果这是使用sh我如何强制它运行 bash?

回答by Charles Duffy

Supervisor does not start a shell at all, either bashorsh-- 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:

Supervisor 根本不启动 shell,bash或者sh——所以它找不到 shell 内置命令也就不足为奇了。如果你需要一个,你必须自己开始一个。因此:

command=/bin/bash -c 'source "
command=/bin/bash -c 'source "
[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
" && exec "$@"' /opt/ros/indigo/setup.bash django-admin runworker
" && exec "$@"' /opt/ros/indigo/setup.sh daphne -b 0.0.0.0 -p 8000 robot_configuration_interface.asgi:channel_layer

and

##代码##

In both these cases, the execis 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.

在这两种情况下,exec存在告诉 shell 用它正在执行的进程替换内存中的自身,而不是留下一个只等待该进程退出的 shell 实例。

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

之后的第一个参数bash -c放在 中$0,之后的参数放在 中$1和以后;因此,我们可以 source"$0"和 execute"$@"来引用第一个这样的参数,然后是相同的参数。



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.

supervisord 在运行 subprocess 时不会执行 shell,因此环境变量(如 USER、PATH、HOME、SHELL、LOGNAME 等)不会从其默认值更改或以其他方式重新分配。

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

因此,shell 操作(包括&&)同样不能期望在顶层可用。

回答by Jian Dai

I also encounter this problem.

我也遇到这个问题。

And I found a better solution.

我找到了更好的解决方案。

Using source ~/.bash_profilemaybe better.

使用source ~/.bash_profile也许更好。

##代码##

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

如果supervisor启动的进程创建了子进程,可以参考:http: //supervisord.org/subprocess.html#pidproxy-program