Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

    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
    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 {

server {

    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?


share|improve this question
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/
  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:… – 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


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.