On Mon, Aug 15, 2011 at 6:29 AM, Jonathan Gazeley <jonathan.gaze...@bristol.ac.uk> wrote: > Hi all, > > I'm trying to set up a routine in puppet where if a service is scheduled for > a restart, eg because of new configs, then a config test is executed first. > If the config test fails, the service is not restart (and so keeps running > with the old config, rather than stopping and causing an outage). > > So far I've tried this kind of thing: > > # DHCP service > service { "dhcpd": > require => [ File["dhcpd.conf"], Package['dhcp'] ], > ensure => running, > enable => true, > hasstatus => true, > hasrestart => true, > notify => Exec['dhcpd-config-test'], > } > > # This exec tests the dhcpd config and fails if it's bad > exec { "dhcpd-config-test": > command => '/etc/init.d/dhcpd configtest 2>&1 | grep "Syntax: OK" | wc > -l', > returns => 0, > refreshonly => true > } > > > In this context, is it better to use notify or require in the service > declaration? Using only "notify" seems to not care about the order, and > sometimes the dhcpd-config-test is executed *after* the dhcpd service has > already been restarted, which is useless. > > Using only "require" doesn't always trigger dhcpd-config-test when dhcpd > restarts. > > Is there a better way of reliably triggering a config test before the > service restarts, but only when it restarts, and then failing if necessary?
The order should be File['config'] ~> Exec['chk_config'] ~> Service['dhcpd'], and beware of the #5670 refreshonly bug if you are using version < 2.6.8. Thanks, Nan -- You received this message because you are subscribed to the Google Groups "Puppet Users" group. To post to this group, send email to puppet-users@googlegroups.com. To unsubscribe from this group, send email to puppet-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.