Monit is a program whose purpose is to monitor if a process is running and boot the process in the case that is down.
It can monitor any type of service or daemon or disk file system, disk space monitoring, PID process IDs, perform checksum and many other things, the way you set is so powerful that almost requires a set programming language.
Complementing Monit will use upstart to start a process easily. As an example we will use nodejs process to be monitored, a library of I/O (input / output, input / output) that can read and write to files, network connections (sockets) in the OS and processes to manage and manipulate and data buffers are asynchronous events.
We’ll set up a server monitoring nodejs.
As usual we will use as base distribution, Ubuntu.
We started by installing upstart
#! sh sudo apt-get install upstart
The last two versions of Ubuntu have this package installed by default.
Next we will configure the service / process monitoring system to boot using upstart, in our case a server nodejs.
#! upstart description «node.js server»
author «Juanvi»
start on startup
stop on shutdown
script = production
export NODE_ENV $
sudo echo $ echo $ $> /var/run/ sudo -u node.pid exec script /home/script/local/bin/node/home/script /pbsb/pubsub.js 2> & 1 >> / var/log/end script node.log
Save this file in /etc/init.d o in /etc/event.d depending on your version of Ubuntu / Linux programa.conf name (in our case would be for example node.conf)
Now we can start and stop our process / service with commands
start yourprogram
stop yourprogram
in our case
start node
stop node
Next we will install monit:
apt-get install monit
Following this review the basic setup of monit in /etc/monit/monitrc:
# Monit control file
# ==================
# Monit global settings:
# ———————-
set daemon 60 set logfile syslog facility log_daemon set mailserver node set alert usuario@dominio.com # direccion a donde enviaremos las alertas del sistema set mail-format { from: monit@node subject: $SERVICE $EVENT message: $ACTION $SERVICE at $DATE on $HOST: $DESCRIPTION. } set httpd port 2812 and
allow xxx.xxx.xxx.xxx # The IP will be allowed to see the web interface
allow user: password # username and password to access the web interface
include /etc/monit/nodejs.monit -> configuration files to monitor process
Then we define the configuration of the monitoring and appropriate actions to raise the process node in case of a fall
#!monit set logfile /var/log/monit.log check process nodejs with pidfile /var/run/node.pid start program = "/sbin/start node" stop program = "/sbin/stop node"
Thus if the process not be running, not exits node.pid file, monit will detect it and start the action, using upstart.
And with Monit can check many system parameters, the response of an http request etc … perfectly complementing the more limited upstart in that regard.