2014-07-04 55 views
0

我已经安装和(希望)配置在monit的创建/etc/monit.d(在CentOS 6.5)monit的不启动节点脚本

我的任务文件称为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 

在我的monit日志显示:

[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

我该如何解决这个问题?由于

+0

没有monit的无法启动的过程中,或只是无法对HTTP响应端口7000 ? –

+0

同样的问题,我在Ubuntu 12.我解决这个新贵https://codeplease.wordpress.com/2013/09/27/deploying-node-js-production/ – duckegg

+0

我已经使用PM2,这是一个很棒的工具管理Node.js应用程序 –

回答

3

同样也没有为我工作,我所做的是做了一个启动/停止脚本,通过该脚本中的monit start program & stop program参数。
可以发现启动的采样/从here
停止脚本下面是我的monit设置于Node.js应用

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