2013-05-11 47 views
3

我曾爲了守護進程使Node.js應用程序創建一個暴發戶腳本:如何通過暴發和監視來支持多個nodejs服務?

description "app_name" 

start on startup 
stop on shutdown 

script 
    export HOME="/home/ubuntu/nodeapp" 

    exec sudo -u nodejs /usr/local/bin/node $HOME/app/server.js production 2>>/var/log/app_name.error.log >>/var/log/app_name.log 
end script 

我monit的腳本如下:

check host app_name with address 127.0.0.1 
    start "/sbin/start app_name" 
    stop "/sbin/stop app_name" 
    if failed port 80 protocol HTTP 
     request /ok 
     with timeout 5 seconds 
     then restart 

它工作正常,但現在我想補充的nginx作爲負載均衡器與上游如下:

upstream cluster1 { 
    least_conn; 
    server 127.0.0.1:8000; 
    server 127.0.0.1:8001; 
} 

server { 
    listen 0.0.0.0:80; 

    location/{ 
    proxy_pass http://cluster1; 
    } 
} 

那麼我應該如何更改新貴和monit腳本來支持?

回答

0

你應該創建三個monit的檢查,一個nginx的,一個用於每個實例的NodeJS:

check host nginx with address 127.0.0.1 
    start "/sbin/start nginx" 
    stop "/sbin/stop nginx" 
    if failed port 80 protocol HTTP 
     request /ok 
     with timeout 5 seconds 
     then restart 

check host app_name_on_8000 with address 127.0.0.1 
    start "/sbin/start app_name_on_8000" 
    stop "/sbin/stop app_name_on_8000" 
    if failed port 8000 protocol HTTP 
     request /ok 
     with timeout 5 seconds 
     then restart 

check host app_name_on_8001 with address 127.0.0.1 
    start "/sbin/start app_name_on_8001" 
    stop "/sbin/stop app_name_on_8001" 
    if failed port 8000 protocol HTTP 
     request /ok 
     with timeout 5 seconds 
     then restart 

當他們失敗,如果失敗或兩個實例的NodeJS下降

這將重新啓動實例的NodeJS和Nginx的
相關問題