Article Listing 1 jan2006.tar

Listing 1 cfengine example

# An example cfengine file that does simple maintenance and
# configures a web server if the class 'web_server' is defined.

control:
  any::
    # the list of things to do:
    actionsequence = (
      links packages shellcommands editfiles
      tidy disable files copy processes )

    # we use RPMs for our packages:
    DefaultPkgMgr = ( rpm )

    # Email me, and don't try to use any local SMTP servers!
    sysadm = ( hostmaster@example.com )
    smtpserver = ( mx1.example.com )

classes:
  # If the class host1 is defined, then define the class 'web_server'
  web_server = ( host1 )

packages:
  web_server::
    "httpd"
    elsedefine=no_rpm_httpd

processes:
  web_server::
    # if you don't see any matches, restart with the 'restart' script.
    # you don't have to parse the restart script in a subshell.
    # also, if no matches then define 'http_chkconfig'.
    matches>0
    restart "/etc/init.d/httpd start"
    useshell=false
    elsedefine=httpd_chkconfig

shellcommands:
  # on the first pass, no_rpm_httpd is defined (from 'packages').
  no_rpm_httpd::
    "/usr/sbin/up2date --solvedeps=httpd"

  # on the first cfengine pass, 'processes' hasn't run yet.
  # on the second (internal) cfengine pass, 'httpd_chkconfig' is defined.

  # this statement is *below* 'processes' in this file so cfengine
  # knows that we might need the value of all the classes
  # that could be defined in the 'processes' section.

  # See the article's "POTENTIAL PROBLEMS" section for more information.
  httpd_chkconfig::
    "/sbin/chkconfig httpd on"
 
editfiles:
  any::
  # Autocreate means create the file if it doesn't exist.
  # AppendIfNoSuchLine is whitespace-sensitive.
    { /etc/hosts
      AppendIfNoSuchLine "127.0.0.1 localhost.localdomain localhost"
      Autocreate }

links:
  any::
    # create this relative link *from* /etc/init.d to rc.d/init.d
    /etc/init.d -> rc.d/init.d

tidy:
  web_server.redhat::  # both Red Hat and a web server
    # delete the annoying configuration file immediately (age=0)
    /etc/httpd/conf.d/welcome.conf
    age=0

disable:
  any::
    /etc/hosts.equiv

files:
  any::
    # put files you find in the MD5 checksum database.  cfengine
    # will start complaining if the checksums change, unless you
    # set the control variables 'ChecksumPurge' and 'ChecksumUpdates'
    # to 'on'.
    /bin
    checksum=md5
    owner=root,rpm
    recurse=inf

  web_server::
    # make sure the group permissions are correct.  act=fixall
    # means actually fix the problem rather than just warning about it.
    /etc/httpd/conf
    group=apache
    act=fixall
    mode=0664
    recurse=inf

copy:
  web_server::
    # copy
    #  cfserver.example.com:/cfserver/config/server/web_server/conf.d
    # to '/etc/httpd/conf.d'
    # using cfengine's cfservd to get the files.
    /cfserver/config/server/web_server/conf.d
    dest=/etc/httpd/conf.d
    recurse=inf
    ignore=CVS
    mode=0644
    server=cfserver.example.com

alerts:
  # Alerts do not have to be specified in the actionsequence.
  # If the condition is true, then cfengine will notify you with the
  # message you provide.
  httpd_chkconfig::
    "I turned on chkconfig for you."