PBWebGuy
2011-Jul-14 15:55 UTC
[Puppet Users] How to use notify to invoke something prior to a change
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], } -- 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.
Nan Liu
2011-Jul-15 20:35 UTC
Re: [Puppet Users] How to use notify to invoke something prior to a change
On Thu, Jul 14, 2011 at 8:55 AM, PBWebGuy <pbwebguy@gmail.com> wrote:> 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], > }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 -- 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.
John Martin
2011-Jul-20 12:46 UTC
[Puppet Users] Re: How to use notify to invoke something prior to a change
Nan - that is an interesting approach to call Puppet from Puppet. I''ll have to give that a try and experiment. Thanks! -- 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.