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

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?

share|improve this question

3 Answers 3

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
share|improve this answer
    
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 mmonit.com/wiki/Monit/Upstart –  mixdev Oct 21 '12 at 23:08

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.

share|improve this answer
    
I am familiar with Monit and concur with this answer. –  Brian De Smet Jan 25 '10 at 0:02
    
I already done this several days ago.. and monit daemon stopped some hours ago... but is the number "234" above is PID? thanks –  Kewasen Jan 25 '10 at 1: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 3:38

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.

share|improve this answer

Your Answer

 
discard

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