Node.js (sudo) 和 monit

发布于 2024-10-16 07:40:06 字数 1303 浏览 3 评论 0原文

我创建了一个新贵脚本来守护主宰(一个node.js应用程序) 新贵脚本如下

description "juggernaut server"
author      "panojsee"

start on startup
stop on shutdown

script
    # We found $HOME is needed. Without it, we ran into problems
    #export HOME="/home/ubuntu/src/juggernaut"
    chdir /home/ubuntu/src/juggernaut
    exec sudo /usr/bin/node server.js 2>&1 >> /var/log/node.log
end script

如您所见,我想使用 sudo 运行节点(以便我可以使用 Flash 套接字)。 我的 monit 脚本如下:

set logfile /var/log/monit.log

check host juggernaut with address 127.0.0.1
    start program = "/sbin/start juggernaut"
    stop program  = "/sbin/stop juggernaut"
    if failed port 8080 protocol HTTP
        request /
        with timeout 10 seconds
        then restart

Monit 不允许我启动程序 = "sudo /sbin/start juggernaut" 一旦我杀死了 juggernaut(节点),monit 就会尝试重新启动它,但会死掉并显示以下消息。

[UTC Feb  3 22:48:25] error    : 'nodejs' failed, cannot open a connection to INET[127.0.0.1:8080] via TCP
[UTC Feb  3 22:48:25] info     : 'nodejs' trying to restart
[UTC Feb  3 22:48:25] info     : 'nodejs' stop: sudo
[UTC Feb  3 22:48:25] error    : Error: Could not execute sudo
[UTC Feb  3 22:48:25] info     : 'nodejs' start: sudo

有什么线索可以告诉 monit 执行 sudo 命令吗?

I have created an upstart script in order to daemonize juggernaut (a node.js app)
The upstart script is the following

description "juggernaut server"
author      "panojsee"

start on startup
stop on shutdown

script
    # We found $HOME is needed. Without it, we ran into problems
    #export HOME="/home/ubuntu/src/juggernaut"
    chdir /home/ubuntu/src/juggernaut
    exec sudo /usr/bin/node server.js 2>&1 >> /var/log/node.log
end script

As you can see I want to run node with sudo (so that I can use Flash sockets).
My monit script is the following:

set logfile /var/log/monit.log

check host juggernaut with address 127.0.0.1
    start program = "/sbin/start juggernaut"
    stop program  = "/sbin/stop juggernaut"
    if failed port 8080 protocol HTTP
        request /
        with timeout 10 seconds
        then restart

Monit does not allow me to have start program = "sudo /sbin/start juggernaut"
Once I kill juggernaut (node) then monit tries to restart it but dies with the following message.

[UTC Feb  3 22:48:25] error    : 'nodejs' failed, cannot open a connection to INET[127.0.0.1:8080] via TCP
[UTC Feb  3 22:48:25] info     : 'nodejs' trying to restart
[UTC Feb  3 22:48:25] info     : 'nodejs' stop: sudo
[UTC Feb  3 22:48:25] error    : Error: Could not execute sudo
[UTC Feb  3 22:48:25] info     : 'nodejs' start: sudo

Any clue how can I tell monit to execute a sudo command ?

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

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

发布评论

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

评论(3

尘曦 2024-10-23 07:40:06

我认为你应该使用专用用户运行nodeJS,然后从启动脚本中删除“exec sudo”,并直接告诉monit你想使用哪个用户。

启动程序 =“/sbin/start juggernaut”作为 uid 用户 ID

I think you should run nodeJS with dedicated user then remove "exec sudo" from the starting script, and tell monit directly which user you would like to use.

start program = "/sbin/start juggernaut" as uid user-id

So要识趣 2024-10-23 07:40:06

只需使用 sudo 启动 Monit,当然将 monit 添加到 sudoers

Just start Monit with sudo and of course add monit to sudoers

阳光的暖冬 2024-10-23 07:40:06

检查 monit 正在以什么用户身份运行。该用户是否配置为运行 sudo?还要检查 sudo 是否报告了任何错误(可能在 /var/log/messages 中)。

我发现这个答案对于弄清楚monit行为非常有帮助。

Check what user monit is running as. Is that user configured to run sudo? Check also if sudo has reported any errors (probably in /var/log/messages).

I found this answer to be very helpful in figuring out monit behavior.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文