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? Thanks, Jonathan -- 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+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
On Mon, Aug 15, 2011 at 6:29 AM, Jonathan Gazeley <jonathan.gazeley@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+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Hi, A couple of ways come to mind. Use the ''before'' metaparameter in your configtest exec. You can use ordering syntax ''->'' between your resources, see http://docs.puppetlabs.com/guides/language_guide.html#chaining-resources See this for a complete overview: http://docs.puppetlabs.com/learning/ordering.html Cheers, Den On 15/08/2011, at 23:29, Jonathan Gazeley <jonathan.gazeley@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? > > Thanks, > Jonathan > > -- > 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+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en. >-- 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+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.
Thanks for your response. Having "before" in the configtest exec and "notify" in the dhcpd service causes an error about a circular dependency. Dropping the "notify" but keeping the "before" makes the order work properly, but the configtest doesn''t get triggered when the service restarts. Is there a way to trigger the test when and only when the service restarts, and guaranteed before the service restarts? The only other idea I''ve had is to trigger the "notify" from the File declaration of the config file. This isn''t really practical for me because some of my daemons have 20+ config files. Thanks, Jonathan On 15/08/11 23:00, Denmat wrote:> Hi, > > A couple of ways come to mind. Use the ''before'' metaparameter in your configtest exec. > > You can use ordering syntax ''->'' between your resources, see http://docs.puppetlabs.com/guides/language_guide.html#chaining-resources > > See this for a complete overview: > http://docs.puppetlabs.com/learning/ordering.html > > Cheers, > Den > > On 15/08/2011, at 23:29, Jonathan Gazeley<jonathan.gazeley@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? >> >> Thanks, >> Jonathan >> >> -- >> 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+unsubscribe@googlegroups.com. >> For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en. >> >-- 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+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.