Application cookbook which installs and configures confd.
It is often the case that application configuration files must be dynamically generated, distributed to a set of machines and a service must be kicked to reload the changes. This faculty can be made to work with Chef, but using confd offers the ability for an immediate configuration change and subsequent bounce of a service across your fleet.
The default recipe writes a basic configuration out for confd using
node attributes that can be modified by changing any of the keys and
values in the node['confd']['config']
hash. If the configuration
changes on disk Chef will kick the confd service which is running
as a service.
The confd_service custom resource provides basic capabilities for a binary or a package installation. By default the binary is downloaded and installed from the confd GitHub project's release page.
There are two additional custom resources which provide the means for writing out confd templates and executing confd ad-hoc instead of as a service. The former custom resource assumes that confd has been installed separately as only the service resource performs the actual package or binary installation.
The confd-iptables cookbook provides an excellent example of advanced usage of the custom resource for writing out confd templates. An example of using that custom resource can be seen below, but make sure to take a look at the confd-iptables cookbook default recipe for the latest.
confd_template '/etc/iptables/confd' do
template_source node['confd-iptables']['template_source']
prefix node['confd-iptables']['prefix']
keys node.tags.map { |t| "/groups/#{t}" }
check_command "/sbin/iptables-restore -n -t < #{path}"
reload_command "/sbin/iptables-restore -n < #{path}"
notifies :restart, 'confd_service[confd]', :delayed
end