Official Site:


MONIT is a deamon watcher. It can restart daemons that faced certain trouble, inform you about it, and so on. It also have its own httpd interface, by which you can see the status of the daemons and manually stop or start them even from remote hosts. Since Version 4, MONIT have had the ability to watch status of devices such like partition usage. There are also other famous programs for this kind of task, for example, Webmin and djb's daemontools. But if you think they are too loud or adhesive, it's worth a try to use this simple and docile program.


Table of Contents


If you are using RedHat family (or have RPM utilities), I recomend you to build an RPM binary package. Dag Wieers has contributed SPEC files for MONIT.

PostgreSQL patch

[2006/5/3: This my PGSQL test code has officially added to MONIT 4.8. Unless you, for some reason, have to keep using 4.7 or older, you can use PGSQL test without applying this patch if you install 4.8 or later. I am glad to have a chance to return a favour to GNU and to MONIT.]

Until Ver.4.7, MONIT didn't have ability to check the connectivity of PostgreSQL though it did about Mysql. Through my experiment with its `general purpose connection test', I had to conclude that it is not usable for PostgreSQL, as it makes the postmaster complain with logs saying `incomplete startup packet' every check interval, every two minutes per MONIT's default. (I read the series of mailing-list log about Mysql. They were talking of an actual problem that Mysql sulks becuase of `too many errors' caused by this kind of `abuse'). This happens because MONIT's generic connection test sends some message regardless of PGSQL protocol and closes connection in an unilateral way. From a Postgres' point of view, it is just like relentless hung-up calls in every two minutes.

So, I came to wrote this PostgreSQL connection test for MONIT.


Now that this takes a form of a patch, you can apply it to MONIT by the commands below (if you intend to build a RPM binary package you need to unzip and untar the source once). Say pgsql patch is in the parent directory up on the MONIT source;

user$ cd monit-4.7
user$ patch -p1 < ../monit-4.7-pgsql.diff

If you intend to build your own RPM, re-archive the patched source (tar czvf monit-4.7.tar.gz monit-4.7/) before start building. This patch has been tested under;

For detailed usage of the pgsql test see Register the controled deamons section.

I found, in writing the new test code, that MONIT team have provided their source with basis which makes it easier to develop new connection tests. You will also find a brief HOWTO, NOTES text in protocols directory of the source. So it is not so baffling to develop a new one, though you will have to be all eyes with actual packets via ethereal or tcpdump thing with certain protocol hadbook at your side. Other existent connection test codes will inspire you too.
Note: The MONIT development Team are always trying to minimize links with specific external libraries to keep generality and stability of MONIT. Though PGSQL test, for example, could have been written with libqp linked, now I am eventually satisfied with the code using only the functions MONIT provides.

Manual installation

Configure options

Generate Makefile through the configure script;

root# ./configure option
Recommended configure options
--sysconfdir=/etc --localstatedir=/var --mandir=/usr/share/man

Compilation and installation

root# make
root# make install

Copy MONIT's main configuration file sample if this is the first time you install MONIT;

root# cp monitrc /etc
root# chmod 600 /etc/monitrc

MONIT will exit immediately if the configuration file is world readable such as 644. Also note that only the owner of the configuration file can control the services defined in it.

Build your RPM packages

Since Version 4.8, MONIT source includes SPEC file and RPM package can be built without external SPEC file just by issueing `rpmbuild -tb monit-x.x.tar.gz'. But as Dag's SPEC seems better carfted (definition of dependency check for example), you would better follow the instructions below.

You can get MONIT binary packages that Dag Wieers has contributed. He does provide them, but I recommend you to build your own RPM as he also provides the separate SPEC file, which is an instruction file for rpmbuild. By that way you can even customize MONIT source code, or first of all, you will be able to catch up with MONIT's new versions as quick as possible.

SPEC file check and customization

Download the monit.spec from the page mentioned above.

PATH specifications are slightly different from those on manual configure and build. since rpmbuild program takes care of them on its own. It is also possible to set them exactly the same as manual installation via SPEC file, nevertheless we need to stick to it. Below are the PATH specifications based on Fedora Core with Dag's monit.spec

and monit executable resides in /usr/bin/.

At least , edit the line near the beginning of monit.spec;
Version: x.x
corresponding to the MONIT's version you are dealing with. Otherwise rpmbuild will fail.

And to be a bit stricter, also change;
Release: 1
to something like
Release: 1.FC4
you see, with your platform appended. This will be reflected to the built package name and its internal information.

The SPEC file has MONIT's init script within itself. So customize it as you like and put it in the vault for your future usage once you came up to satisfactory one. The contrib/rc.monit included in the original source will be unused.

About config file name

Though it can be a matter of taste, DAG's SPEC has one thing I don't quite agree. He has chenged the MONIT's configuration file name to monit.conf just like other RedHatty packages. Formerly it had lead you in a trouble where you always had to specify -c <control_file> on every invocation of monit, because the built binary still looked for/etc/monitrc by default. This issue has been fixed since SPEC Ver.4.8.1-3. But what does the name deserve? For example, you have to make some additional effort to make use of scripts from contrib directory in the monit original source.

So, I usually disable the change by replacing all the monit.conf with monitrc in the SPEC file. Also you need to delete a line in the recent SPEC ( >=4.8.1-3) that reads;

%{__perl} -pi.orig -e 's|\bmonitrc\b|monit.conf|' monitor.h

which is the very line that fixes the problem mentioned above.

Source preparation and package building

Get monit-x.x.tar.gz from MONIT official site, become root and copy it to /usr/src/redhat/SOURCES/. You need not unzip nor untar it. Copy monit.spec mentioned above to /usr/src/redhat/SPECS/. Then now is the time rpmbuild play its role. Necessary option is only -bb to build only binary package, Really optional --clean tells rpmbuild to delete the souce files that build process extracted under BUILD/<arch>/ tree after successful compilation. (If you ommit --clean now, you can perform only clean-up process by `rpmbuild --clean SPECS/monit.spec' afterwards.)

root# cd /usr/src/redhat
root# rpmbuild -bb --clean SPECS/monit.spec

That's it. Now you must have done configure, make and RPM packaging in one stroke.

Then, if you still have previous MONIT which has been manually installed on your system, remove at least /usr/local/bin/monit, as multiple monit executables in PATH may screw you up someday. Then you can install monit-x.x.<arch>.rpm which must have been created under RPMS/<arch>/. The package made through Dag's SPEC deems it to always replace /etc/init.d/monit, but it won't do /etc/monitrc if there is already one. It is recommended that you rename previous one before installation, especially when two MONITs' versions are significantly different.

MONIT init script

If you have installed MONIT manually from its source, you may want to copy the sample init sctipt from contrib directory of the source. RPM installation doesn't require this because init script has been copied during installation.

root# cp contrib/rc.monit /etc/rc.d/init.d/monit
root# chmod 755 /etc/rc.d/init.d/monit

Adjustment of MONIT init script (only when built manually)

The init script provided by certain version of MONIT needs some fix, while I have never noticed any in Dag's SPEC. Fist of all, the path of monit executable differs from the default installation path;


Fix the conditions of indispensable file checks.
Line 1: change to a test that assures monit is there and is executable
Line 2: add a check of configuration file existence

[ -x $MONIT ] || exit 0
[ -f $MONITRC ] || exit 0

reload section is strangely triing to delete the lock file;

[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/monit <--delete this line

Though this is rare nowadays, if your `initscripts' package is very old, you need to delete "--force" option from the start) and reload) section and also to rewrite stop) section. RedHat 7.2 or older needs this adjustment because old /etc/rc.d/init.d/functions script doesn't have a definition of "--force" for daemon function. I don't know from which version of initscripts it has changed.

default stop) function:

daemon --force $MONIT -c $MONITRC quit 

should be:

killproc monit

Here you can see my (a bit old) /etc/rc.d/init.d/monit.