Sean’s Obsessions

Sean Walberg’s blog

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:

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

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

1
2
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

1
2
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:

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

Comments

I’m trying something new here. Talk to me on Twitter with the button above, please.