summaryrefslogtreecommitdiffstats
path: root/lib/puppet/agent.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puppet/agent.rb')
-rw-r--r--lib/puppet/agent.rb170
1 files changed, 85 insertions, 85 deletions
diff --git a/lib/puppet/agent.rb b/lib/puppet/agent.rb
index a01da483b..52acc64aa 100644
--- a/lib/puppet/agent.rb
+++ b/lib/puppet/agent.rb
@@ -5,101 +5,101 @@ require 'puppet/application'
# A general class for triggering a run of another
# class.
class Puppet::Agent
- require 'puppet/agent/locker'
- include Puppet::Agent::Locker
+ require 'puppet/agent/locker'
+ include Puppet::Agent::Locker
- attr_reader :client_class, :client, :splayed
+ attr_reader :client_class, :client, :splayed
- # Just so we can specify that we are "the" instance.
- def initialize(client_class)
- @splayed = false
+ # Just so we can specify that we are "the" instance.
+ def initialize(client_class)
+ @splayed = false
- @client_class = client_class
- end
-
- def lockfile_path
- client_class.lockfile_path
- end
-
- def needing_restart?
- Puppet::Application.restart_requested?
- end
+ @client_class = client_class
+ end
- # Perform a run with our client.
- def run(*args)
- if running?
- Puppet.notice "Run of #{client_class} already in progress; skipping"
- return
- end
- result = nil
- block_run = Puppet::Application.controlled_run do
- splay
- with_client do |client|
- begin
- sync.synchronize { lock { result = client.run(*args) } }
- rescue => detail
- puts detail.backtrace if Puppet[:trace]
- Puppet.err "Could not run #{client_class}: #{detail}"
- end
- end
- true
- end
- Puppet.notice "Shutdown/restart in progress; skipping run" unless block_run
- result
- end
+ def lockfile_path
+ client_class.lockfile_path
+ end
- def stopping?
- Puppet::Application.stop_requested?
- end
+ def needing_restart?
+ Puppet::Application.restart_requested?
+ end
- # Have we splayed already?
- def splayed?
- splayed
+ # Perform a run with our client.
+ def run(*args)
+ if running?
+ Puppet.notice "Run of #{client_class} already in progress; skipping"
+ return
end
-
- # Sleep when splay is enabled; else just return.
- def splay
- return unless Puppet[:splay]
- return if splayed?
-
- time = rand(Integer(Puppet[:splaylimit]) + 1)
- Puppet.info "Sleeping for #{time} seconds (splay is enabled)"
- sleep(time)
- @splayed = true
- end
-
- # Start listening for events. We're pretty much just listening for
- # timer events here.
- def start
- # Create our timer. Puppet will handle observing it and such.
- timer = EventLoop::Timer.new(:interval => Puppet[:runinterval], :tolerance => 1, :start? => true) do
- run
+ result = nil
+ block_run = Puppet::Application.controlled_run do
+ splay
+ with_client do |client|
+ begin
+ sync.synchronize { lock { result = client.run(*args) } }
+ rescue => detail
+ puts detail.backtrace if Puppet[:trace]
+ Puppet.err "Could not run #{client_class}: #{detail}"
end
-
- # Run once before we start following the timer
- timer.sound_alarm
+ end
+ true
end
-
- def sync
- @sync ||= Sync.new
+ Puppet.notice "Shutdown/restart in progress; skipping run" unless block_run
+ result
+ end
+
+ def stopping?
+ Puppet::Application.stop_requested?
+ end
+
+ # Have we splayed already?
+ def splayed?
+ splayed
+ end
+
+ # Sleep when splay is enabled; else just return.
+ def splay
+ return unless Puppet[:splay]
+ return if splayed?
+
+ time = rand(Integer(Puppet[:splaylimit]) + 1)
+ Puppet.info "Sleeping for #{time} seconds (splay is enabled)"
+ sleep(time)
+ @splayed = true
+ end
+
+ # Start listening for events. We're pretty much just listening for
+ # timer events here.
+ def start
+ # Create our timer. Puppet will handle observing it and such.
+ timer = EventLoop::Timer.new(:interval => Puppet[:runinterval], :tolerance => 1, :start? => true) do
+ run
end
- private
-
- # Create and yield a client instance, keeping a reference
- # to it during the yield.
- def with_client
- begin
- @client = client_class.new
- rescue SystemExit,NoMemoryError
- raise
- rescue Exception => detail
- puts detail.backtrace if Puppet[:trace]
- Puppet.err "Could not create instance of #{client_class}: #{detail}"
- return
- end
- yield @client
- ensure
- @client = nil
+ # Run once before we start following the timer
+ timer.sound_alarm
+ end
+
+ def sync
+ @sync ||= Sync.new
+ end
+
+ private
+
+ # Create and yield a client instance, keeping a reference
+ # to it during the yield.
+ def with_client
+ begin
+ @client = client_class.new
+ rescue SystemExit,NoMemoryError
+ raise
+ rescue Exception => detail
+ puts detail.backtrace if Puppet[:trace]
+ Puppet.err "Could not create instance of #{client_class}: #{detail}"
+ return
end
+ yield @client
+ ensure
+ @client = nil
+ end
end