3

I use monit to make sure everything running fine, but monit daemon was also stopped.

I dont know how this be, and how to prevent monit daemon from stopped?

3 Answers3

4

On Ubuntu 9.10, /etc/inittab does not exist, because Ubuntu uses upstart instead of /sbin/init. So to achieve the same thing as answer #1 above we need an upstart script:

# This is an event.d (upstart) script to keep monit running
# To install disable the old way of doing things:
#
#   /etc/init.d/monit stop && update-rc.d -f monit remove
#
# then put this script here: /etc/init/monit.conf
#
# You can manually start and stop monit like this:
# 
# start monit
# stop monit
#
# Karim Ratib (http://thereisamoduleforthat.com)
# 
# Based on monit.upstart (https://code.google.com/p/monit/source/browse/trunk/contrib/monit.upstart?r=132)
# by Michael Hale (http://halethegeek.com)

start on runlevel [2345]
stop on runlevel [06]

exec /usr/sbin/monit -Ic /etc/monit/monitrc
respawn
infojunkie
  • 147
  • 6
  • Just FYI, Redhat (and so Centos) have started using Upstart instead of inittab in the latest linux versions. So this may work there too. – mixdev Oct 21 '12 at 22:49
  • On Redhats, this will work http://mmonit.com/wiki/Monit/Upstart – mixdev Oct 21 '12 at 23:08
2

The best option I can think of for something that absolutely has to be run and must be restarted if it happens to die is to run the process out of init.

You put an entry like the following in /etc/inittab:

name:234:respawn:/usr/local/bin/daemon

Then restart init with:

init q

Now anytime your daemon dies, it will automatically be "respawned"

Edit: I am not familiar with Monit, but I happened to check their FAQ page, and they have detailed this specifically for monit.

Alex
  • 6,477
  • 1
  • 23
  • 32
  • I am familiar with Monit and concur with this answer. – Brian De Smet Jan 25 '10 at 00:02
  • I already done this several days ago.. and monit daemon stopped some hours ago... but is the number "234" above is PID? thanks –  Jan 25 '10 at 01:51
  • 234 are the runlevels in which the process should run. You may need to add a 5 to that if you are running on a system that boots directly to an X-based login. – Alex Jan 25 '10 at 03:38
0

Taken from monit docs: http://mmonit.com/wiki/Monit/FAQ#init

Q: How can I run monit from init so it can be respawned in case monit dies unexpectedly?

A: It is recommended that you use Monit version 5 or later when running Monit from init.

Use either the 'set init' statement in monits configuration file or use the -I option from the command line. Here's a sample /etc/inittab entry for monit:

 # Run monit in standard runlevels
 mo:2345:respawn:/usr/local/sbin/monit -Ic /etc/monitrc

After you have modified inits configuration file, you can run the following command to re-examine the runlevel and start monit:

 telinit q

You should consider adding another layer of monitoring to your scenario like Nagios/Icinga, Zabix or Sensu to check monit status.

Even though monit can respawn if dead, there are some cases in which monit stop working and the daemon still lives, so respawn is never triggered.

At this point, the another layer of monitoring can be configured to send you an email warning you that monit status is not available and then you fix the problem.

Lucas Castro
  • 121
  • 1
  • 5