Hi,

You can do something like this :

file { '/etc/dhcp/dhcpd.conf':
  ...
  notify => Exec['dhcp-syntax-check']
}

exec { 'dhcp-syntax-check':
  ...
  subscribe => File['/etc/dhcp/dhcpd.conf'],
  notify    => Service['dhcpd']
}

service { 'dhcpd':
  ...
  subscribe => Exec['dhcp-syntax-check']
}

(subscribe metaparameters are not mandatory here)

The Service is only refreshed when the configuration file changed so you 
can insert an Exec between File and Service.

But it's not that simple to manage execution of an Exec. Have a look 
to https://docs.puppetlabs.com/references/4.2.latest/type.html#exec and 
check the Refresh section.



Regards,
BP


Le lundi 6 juillet 2015 14:08:58 UTC+2, Jonathan Gazeley a écrit :
>
> Hi folks, 
>
> I'm tying myself in knots trying to figure out the best metaparameters 
> to use here. I want to define an exec that only runs when a service is 
> scheduled to be restarted. It should check the config file and if the 
> syntax is invalid, it should abort restarting the service (i.e. won't 
> kill a running service). 
>
> This is what I've got so far: 
>
> service { 'dhcpd': 
>    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 
> # It isn't run every time puppet runs, but only when dhcpd is to be 
> restarted 
> exec { 'dhcpd-config-test': 
>    command     => '/usr/bin/sudo /usr/sbin/dhcpd -t', 
>    returns     => 0, 
>    refreshonly => true, 
>    logoutput   => on_failure, 
> } 
>
> Notify on its own is no good, since if the exec fails, the service gets 
> restarted anyway. 
>
> Require on its own is no good, since the exec runs every time. 
>
> Is there some way to combine the two? 
>
> Thanks, 
> Jonathan 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/6f3586b7-0008-45a0-bd2e-0d8be36d6bb7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to