Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have created an upstart script in order to daemonize a node.js app. The upstart script is the following:

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

My monit script is the following:

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

It works fine but now I want to add nginx as load balanser with upstream like the following:

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;
    }
}

So how should I change upstart and monit scripts for supporting two services? Do I need to write one more upstart and monit scripts?

Thanks.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

For monit, you can use a separate configuration file under /etc/monit.d (or whatever directory you have for the service configuration files) that looks something like:

check process nginx with pidfile /var/run/nginx.pid
  if failed host localhost port 80 
       protocol HTTP request "/ok" then restart
  start program = "/etc/init.d/nginx start"
  stop program  = "/etc/init.d/nginx stop"
  group www-data (for ubuntu, debian)

There are more configuration examples on the official Monit site. You can look at the Apache example for further tests you can do.

For Upstart, Nginx's docs has an example.

To some extent, using both Monit and Upstart is vaguely overkill and potentially conflicting. Both will do process respawns (though Monit allows more detailed testing of the service) and you may have a weird situation where they are both competing to restart the service if it dies unexpectedly. A leaner approach would be to use Monit in general to monitor those services (with whatever extra HTTP probes and memory/cpu usage checks you want), and then use Upstart to make sure that Monit is running.

share|improve this answer
    
Why do you think that using mint and upstart together is overkill? There are a lot of posts about using them together: google.ru/… –  Erik May 12 '13 at 19:50
    
Oh, I see what you're doing with service control inside monit. That's fine, then. –  cjc May 13 '13 at 10:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.