CFEngine : Checking for processes

GearsCFEngine can do wonders to keep a cluster in shape, but it can be very useful for a single server as well. Here is a configuration sample to monitor a few common services and restart them should they fail.

Here is how you can setup cfengine to monitor services on a server :

# cat cfagent.conf
control:
        actionsequence = ( processes )
processes:
        "/usr/sbin/sshd"
                restart "/usr/sbin/sshd"
        "sendmail"
                restart "/usr/sbin/sendmail a-L sm-mta -C/etc/mail/localhost.cf -bd -q30m"
        "named"
                restart "named"

In the “control/actionsequence” part, we state that the “processes” part should be executed. Each statement in the processes part is composed of 2 lines :

  1. description of the running service (as it should appear if you run ps)
  2. how to restart it if it is not there

So if you put cfexecd -F to run periodically in your crontab, it CfEngine will ensure that the services you monitor are running.

PS : This is the 100th post 🙂