diff options
author | Ethan Rowe <ethan@endpoint.com> | 2009-07-30 14:09:26 -0400 |
---|---|---|
committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
commit | edbe9b6a988932c4b91dd194bc00ca201626d0ae (patch) | |
tree | 9d952872b641f1a01bd8d26ea02d149017f52dd7 /lib/puppet | |
parent | 2cf647c34f5e71fc30fccb2de0c5acef5799b924 (diff) | |
download | puppet-edbe9b6a988932c4b91dd194bc00ca201626d0ae.tar.gz puppet-edbe9b6a988932c4b91dd194bc00ca201626d0ae.tar.xz puppet-edbe9b6a988932c4b91dd194bc00ca201626d0ae.zip |
Fix 2239 (step two): introduce Puppet::Application.controlled_run method to provide simple status-restricted execution of a passed in block; this can replace the process status checks and properly handle delayed restart behavior for Puppet::Agent.
Diffstat (limited to 'lib/puppet')
-rw-r--r-- | lib/puppet/application.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/puppet/application.rb b/lib/puppet/application.rb index 83f90a18d..a80f42289 100644 --- a/lib/puppet/application.rb +++ b/lib/puppet/application.rb @@ -160,6 +160,18 @@ class Puppet::Application def clear? run_status.nil? end + + # Only executes the given block if the run status of Puppet::Application is clear (no restarts, stops, + # etc. requested). + # Upon block execution, checks the run status again; if a restart has been requested during the block's + # execution, then controlled_run will send a new HUP signal to the current process. + # Thus, long-running background processes can potentially finish their work before a restart. + def controlled_run(&block) + return unless clear? + result = block.call + Process.kill(:HUP, $$) if restart_requested? + result + end end attr_reader :options, :opt_parser |