Linking actions with define
From Cfwiki
This is probably the #1 most frequently asked question on the mailing list:
Can I restart a process only after I change something in master server file? For example if I change /etc/sysconfig/iptables in $(server) and copy it to client, iptables should restart itself, but if nothing changed in the config file, don't do anything. How can I do that?
Here's a specific solution (assuming Redhat-ish linux from the example) that illustrates the methodology:
control:
AddInstallables = ( restartIptables )
actionsequence = ( copy shellcommands )
cfserver = ( myserver.domain.com )
copy:
/masterfiles/$(host)/etc/sysconfig/iptables
dest=/etc/sysconfig/iptables
type=checksum
server=$(cfserver)
define=restartIptables
shellcommands:
restartIptables::
"/sbin/service iptables restart"
Many actions support a 'define=' option, and this is a fundamental building block of cfengine practice. files:, links:, copy:, processes:, packages:, shellcommands:, and tidy: all support this syntax.
Editfiles, par for the course, is an outlier, and the syntax is different. You want either DefineClasses if you just have one edit action in the file, or DefineInGroup if you do multiple edits in a single file with BeginGroup/EndGroup sections.
See also Autodefine Bliss for another option.
