Node.js (sudo) 和 monit
我创建了一个新贵脚本来守护主宰(一个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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为你应该使用专用用户运行nodeJS,然后从启动脚本中删除“exec sudo”,并直接告诉monit你想使用哪个用户。
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.
只需使用 sudo 启动 Monit,当然将 monit 添加到 sudoers
Just start Monit with sudo and of course add monit to sudoers
检查 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.