diff options
author | Ethan Rowe <ethan@endpoint.com> | 2009-07-30 01:17:01 -0400 |
---|---|---|
committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
commit | 2cf647c34f5e71fc30fccb2de0c5acef5799b924 (patch) | |
tree | 3d0cae1bebdd3f8c129771b8a5e2340620ab9447 /lib | |
parent | ce944a5d9ae7b18a2557eb282ac20e4ff49ce6f3 (diff) | |
download | puppet-2cf647c34f5e71fc30fccb2de0c5acef5799b924.tar.gz puppet-2cf647c34f5e71fc30fccb2de0c5acef5799b924.tar.xz puppet-2cf647c34f5e71fc30fccb2de0c5acef5799b924.zip |
Fix 2239 (step one): introduce global settings represeting application run state with methods for
setting the state and appropriately-named predicates for querying state, all in the Puppet::Application
class itself. To be used by Puppet::Daemon and Puppet::Agent and Puppet::Transaction for better response
to TERM, INT, HUP.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/application.rb | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/lib/puppet/application.rb b/lib/puppet/application.rb index 8597bd652..83f90a18d 100644 --- a/lib/puppet/application.rb +++ b/lib/puppet/application.rb @@ -5,6 +5,7 @@ require 'optparse' # * setting up options # * setting up logs # * choosing what to run +# * representing execution status # # === Usage # The application is a Puppet::Application object that register itself in the list @@ -86,6 +87,31 @@ require 'optparse' # to be run. # If it doesn't exist, it defaults to execute the +main+ command if defined. # +# === Execution state +# The class attributes/methods of Puppet::Application serve as a global place to set and query the execution +# status of the application: stopping, restarting, etc. The setting of the application status does not directly +# aftect its running status; it's assumed that the various components within the application will consult these +# settings appropriately and affect their own processing accordingly. Control operations (signal handlers and +# the like) should set the status appropriately to indicate to the overall system that it's the process of +# stopping or restarting (or just running as usual). +# +# So, if something in your application needs to stop the process, for some reason, you might consider: +# +# def stop_me! +# # indicate that we're stopping +# Puppet::Application.stop! +# # ...do stuff... +# end +# +# And, if you have some component that involves a long-running process, you might want to consider: +# +# def my_long_process(giant_list_to_munge) +# giant_list_to_munge.collect do |member| +# # bail if we're stopping +# return if Puppet::Application.stop_requested? +# process_member(member) +# end +# end class Puppet::Application include Puppet::Util @@ -96,6 +122,44 @@ class Puppet::Application class << self include Puppet::Util + + attr_accessor :run_status + + def clear! + self.run_status = nil + end + + def stop! + self.run_status = :stop_requested + end + + def restart! + self.run_status = :restart_requested + end + + # Indicates that Puppet::Application.restart! has been invoked and components should + # do what is necessary to facilitate a restart. + def restart_requested? + :restart_requested == run_status + end + + # Indicates that Puppet::Application.stop! has been invoked and components should do what is necessary + # for a clean stop. + def stop_requested? + :stop_requested == run_status + end + + # Indicates that one of stop! or start! was invoked on Puppet::Application, and some kind of process + # shutdown/short-circuit may be necessary. + def interrupted? + [:restart_requested, :stop_requested].include? run_status + end + + # Indicates that Puppet::Application believes that it's in usual running mode (no stop/restart request + # currently active). + def clear? + run_status.nil? + end end attr_reader :options, :opt_parser |