Sean’s Obsessions

  • Archives

30 May

Using cfengine to manage RedHat services

I’ve really been getting into cfengine lately to manage configurations across multiple servers.

One thing I want to do is to make sure that the proper services are started. Making sure they’re running is easy with the processes command:


processes:
"cfenvd" restart "/sbin/service cfenvd restart"

I also want to make sure that cfenvd is in the startup scripts. My solution earlier was


shellcommands:
"/usr/bin/test -f /etc/rc3.d/S*cfenvd || /sbin/chkconfig cfenvd on"

Which worked, but was run every time and generated unnecessary emails.

I tried some variants of


classes:
service_cfenvd_on = ( ReturnsZero("/sbin/chkconfig --list cfenvd | grep -q 3:on") )

but for some reason the pipe causes problems.

Reading through the chkconfig man page, I see that a simple “chkconfig cfenvd” will return 0 if the service is started in the current runlevel, and 1 otherwise. Thus:


classes:
service_cfenvd_on = ( ReturnsZero("/sbin/chkconfig --level 3 cfenvd") )
shellcommands:
!service_cfenvd_on::
"/sbin/chkconfig cfenvd on"

One Response to “Using cfengine to manage RedHat services”

  1. 1
    Luke Kanies Says:

    If you’re just getting started, I highly recommend looking at some of the newer tools — cfengine hasn’t changed much in the last five years, and it’s always had some significant usability problems.

    You should give Puppet a try; you’ll find that it’s much easier to manage services using it. For instance, here’s the equivalent code for your example:

    service { cfenvd: enabled => true }

    Notice no worries about how to use chkconfig — Puppet figures out what “enabled” means and translates appropriately for you.

    It also transparently handles packages, users, and much more, and in a way that is portable across most of the major Unixes.

Leave a Reply

Protected by the Herculean, widespread, magnitudinous, and consummate Hashcash!

© 2008 Sean’s Obsessions | Entries (RSS) and Comments (RSS)

Powered by Wordpress, design by Web4Sudoku, based on Pinkline byGPS Gazette