2013-05-11 7 views
3

나는 Node.js를 응용 프로그램을 디먼 화하기 위해 신출내기 스크립트를 만들었습니다upstart 및 monit에서 여러 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 스크립트를 변경하는 방법이를 지원하기 위해? 당신은 세 가지 MONIT 검사, nginx를위한 하나의 각 하나를 만들어야합니다

답변

0

는 예를 nodejs : 실패하거나 둘 경우 아래

있습니다 nodejs 경우 그들이 실패 할 때 nodejs 인스턴스를 다시 시작하고 nginx를합니다

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