2014-07-04 82 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