Running an Exec resource *before* deleting a File resource

asked 2016-10-11 16:16:01 -0600

bschonecker gravatar image

I have a class that is adding a (rhel6) 'upstart' configuration in /etc/init. When Puppet creates the configuration file, I have to execute "initctl start <service>" based on the service name that I'm adding. The problem that I'm having is that I need an exec to run before I remove the file so that I shut down the service before the file gets removed. If I don't shut down the service, then 'initctl' complains that the service isn't there.

Now, "service" isn't in the true sense of a Puppet service. It's more of a 'reload' or "telinit q' (for SysV). Here's what I have:

case $enabled {
  true: {
    # Create the upstart file then start the 'service'.
    $file_ensure = file
    $cmd_refresh_init = "start"
    File[$iucvtty_file] ~> Exec[$refresh_init_exec]

  false: {
    # Stop the upstart 'service' then delete the file.
    $file_ensure = absent
    $cmd_refresh_init = "stop"
    Exec[$refresh_init_exec] -> File[$iucvtty_file]
} # case

file {$iucvtty_file:
  ensure  => $file_ensure,
  content => template("${name}/${template_file}"),

exec {$refresh_init_exec:
  command     => $cmd_refresh_init,
  refreshonly => true,
  logoutput   => true,

When $enabled = true everything works just fine. When $enabled = false, the exec never runs yet the configuration file gets removed. I would have thought that with the following chain:

      Exec[$refresh_init_exec] -> File[$iucvtty_file]

the resource ordering would have been satisfied. Unfortunately even when I remove "refreshonly" the exec still doesn't run.

Is there any way (cleanly) to get this exec to run BEFORE the File resource gets removed?

edit retag flag offensive close merge delete


puser gravatar imagepuser ( 2016-10-12 06:36:45 -0600 )edit