How to use notify to invoke something prior to a change

136 views
Skip to first unread message

PBWebGuy

unread,
Jul 14, 2011, 11:55:49 AM7/14/11
to Puppet Users
I have a Chicken and Egg scenario here and trying to come up with a
way to solve it.

I have a mount definition that manages mount points. The problem
arises when the mount point changes after it is in use. Case in
point, we have mount points for the mysql data and logs directories.
If we change the configuration of the mount (i.e. options) then Puppet
will unmount and remount the directory automatically. MySQL will not
be to happy with that.

So, what I want to do is to optionally pass the service name to the
define and to shut it down, but ONLY if the mount command detects a
change and mysql is running.

The problem I have is that if the mount command notifies shutdown,
then the shutdown happens to late and I only what to shutdown if mount
detects a change. It would be great if there was a "pre-notify"
option to force an exec to run beforehand.

I tried putting a Notify and Require from the mount to the stop
service exec but that causes a circular reference and just the require
in the mount does not trigger the stop service exec because of the
refreshonly=>true which is necessary so that it doesn't always run.

Any thoughts?

Thanks, John

Here's what I have:

exec { "stop service for remount $name":
onlyif => ["test -f /etc/init.d/$service", "service
$service status"],
command => "service $service stop",
refreshonly => true,
notify => Exec["restart service for remount $name"],
}

# Mount the file system
mount { $name:
name => $mount_point,
ensure => mounted,
options => $options,
atboot => $atboot,
fstype => $fstype,
device => $device,
dump => 0,
pass => 0,
require => Exec["stop service for remount $name"],
# notify => Exec["stop service for remount $name"],
}

exec { "restart service for remount $name":
command => "service $service start",
refreshonly => true,
require => Mount[$name],
}

Nan Liu

unread,
Jul 15, 2011, 4:35:31 PM7/15/11
to puppet...@googlegroups.com

No good way at the moment since the type and provider doesn't allow
resource to trigger actions between detection of resource state and
updates to the resource. This would be an interesting feature request
if there isn't one yet. At the moment, you can abuse puppet resource
with noop to check if there will be changes to the resource (puppet
resource does not support arrays, maybe we need -e to support
arbitrary puppet manifests string):

Exec { "shutdown service":


command     => "service $service stop",

onlyif => "puppet resource --noop mount name=$mount_point ... | grep notice"
}

Thanks,

Nan
--
==========================================
Join us in PDX for PuppetConf: http://bit.ly/puppetconfsig

John Martin

unread,
Jul 20, 2011, 8:46:41 AM7/20/11
to Puppet Users
Nan - that is an interesting approach to call Puppet from Puppet.
I'll have to give that a try and experiment.

Thanks!
Reply all
Reply to author
Forward
0 new messages