如何设置 Supervisord 的 PATH 以便它找到可执行文件

发布于 2024-12-01 04:10:26 字数 439 浏览 6 评论 0原文

我正在尝试设置 supervisor.conf。我的一个应用程序需要node.js,但节点没有安装系统明智。另外,因为它需要绑定到端口 80,所以需要以 root 身份运行。如何修改 PATH 变量,以便supervisord 可以找到node 可执行文件(位于目录中)并运行node.js 应用程序。


我正在尝试这样做

[supervisord]
environment=PATH=/path/to/where/node/executable/is

[program:web]
command=node web.js -c config.json

这失败了

2011-08-25 16:49:29,494 INFO spawnerr: can't find command 'node'

I'm trying to setup supervisor.conf. One of my apps requires node.js, but node is not installed system wise. Also, because it needs to bind to port 80 it need to run as root. How can I modify the PATH variable so that supervisord can find the node executable (which is located in a directory) and run the node.js app.


I'm trying to do it like this

[supervisord]
environment=PATH=/path/to/where/node/executable/is

[program:web]
command=node web.js -c config.json

This fails with

2011-08-25 16:49:29,494 INFO spawnerr: can't find command 'node'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

各空 2024-12-08 04:10:26

您可以使用 env 将其添加到命令中:

[program:web]
command=env PATH="/path/to/where/node/executable/is" node web.js -c config.json

似乎环境在某些情况下不起作用。

You can add it in the command using env:

[program:web]
command=env PATH="/path/to/where/node/executable/is" node web.js -c config.json

It seems environment does not work on some cases.

薄荷港 2024-12-08 04:10:26

我开始与主管一起使用的一种模式(类似于 zenbeni 的)是使用 shell 脚本来启动我正在运行的任何程序,该程序允许设置环境变量等。

例如,

#!/bin/sh
export EXAMPLE_VARIABLE=something
export PYTHONPATH=/something
export PATH=$PATH:/somewhere/else
exec python somescript.py

“exec”的使用很重要。它用正在执行的程序替换 /bin/sh ,而不是将其作为子程序生成。这意味着周围没有任何额外的进程,并且信号也按预期工作。

与 zenbeni 的方法相比,这种方法的(小)优点是,当更新环境变量等时,只需要重新启动主管,即不需要重新读取/更新等。如果您遇到与我相同的错误(完全重新启动主管以更新事件侦听器环境变量),那么在使用事件侦听器时,此优势会变得更大。

A pattern I've started using with supervisor (which is similar to zenbeni's) is to use a shell script to start whichever program I'm running which allows setup of environment variables etc.

e.g.

#!/bin/sh
export EXAMPLE_VARIABLE=something
export PYTHONPATH=/something
export PATH=$PATH:/somewhere/else
exec python somescript.py

The use of 'exec' is important. It replaces /bin/sh with the program being executed instead of spawning it as a child. This means that there aren't any additional processes around, and also signals work as expected.

The (small) advantage of this over zenbeni's method is that when updating environment variables etc it only takes a supervisor restart, i.e. no reread/update etc is required. This advantage gets bigger when using an event listener if you hit the same bug I did (full restart of supervisor to update event listener environment variables).

野稚 2024-12-08 04:10:26

您只需设置命令的绝对路径即可:

[program:web]
command=/path/to/where/node/executable/is/node web.js -c config.json

You can just set the absolute path to the command:

[program:web]
command=/path/to/where/node/executable/is/node web.js -c config.json
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文