Monit无法启动Node脚本

时间:2014-07-04 07:53:35

标签: node.js monit

我已安装并(希望)配置Monit在/etc/monit.d(在CentOS 6.5上)创建新任务

我的任务文件名为test

check host test with address 127.0.0.1
    start program = "/usr/local/bin/node /var/node/test/index.js" as uid node and gid node
    stop program  = "/usr/bin/pkill -f 'node /var/node/test/index.js'"
    if failed port 7000 protocol HTTP
        request /
        with timeout 10 seconds
        then restart

当我跑步时:

service monit restart

在我的监控日志中显示:

[CEST Jul  4 09:50:43] info     : monit daemon with pid [21946] killed
[CEST Jul  4 09:50:43] info     : 'nsxxxxxx.ip-xxx-xxx-xxx.eu' Monit stopped
[CEST Jul  4 09:50:47] info     : 'nsxxxxxx.ip-xxx-xxx-xxx.eu' Monit started
[CEST Jul  4 09:50:47] error    : 'test' failed, cannot open a connection to INET[127.0.0.1:7000] via TCP
[CEST Jul  4 09:50:47] info     : 'test' trying to restart
[CEST Jul  4 09:50:47] info     : 'test' stop: /usr/bin/pkill
[CEST Jul  4 09:50:47] info     : 'test' start: /usr/local/bin/node

我不明白为什么脚本不起作用,如果我从命令行运行它:

su node # user created for node scripts
node /var/node/test/index.js

一切正常......

我已经关注this tutorial

如何解决此问题?感谢

1 个答案:

答案 0 :(得分:4)

同样对我来说也不起作用,我所做的是制作一个开始/停止脚本并将该脚本传递到start program& monit中的stop program参数 您可以从here找到启动/停止脚本示例 下面是我对node.js应用程序的monit设置

check host my-node-app with address 127.0.0.1
    start program = "/etc/init.d/my-node-app start"
    stop program = "/etc/init.d/my-node-app stop"
    if failed port 3002 protocol HTTP
        request /
        with timeout 5 seconds
        then restart
    if 5 restarts within 5 cycles then timeout