# Monit exists to restart the node.js server or
# NGINX if either become unresponsive. Upstart
# only restart these processes if they exit.

set logfile /var/www/blot/logs/monit.log

# The route which responds is in app/index.js
# If monit fails to recieve a 200 OK response from node
# for three consecutive attempts then it will attempt 
# to restart its upstart service
check process nodejs with pidfile "/var/run/blot.pid"
    start program = "/sbin/start blot"
    stop program  = "/sbin/stop blot"
    if failed port 8080 protocol HTTP
        request /health
        with timeout 10 seconds
        for 3 cycles
        then restart

# The route which responds is in config/nginx/server.conf
# If monit fails to recieve a 200 OK response from NGINX
# for three consecutive attempts then it will attempt to
# restart its upstart service
check process nginx with pidfile "/var/run/nginx.pid"
    start program = "/sbin/start nginx"
    stop program  = "/sbin/stop nginx"
    if failed port 80 protocol HTTP
        request /health
        with timeout 10 seconds
        for 3 cycles
        then restart