Class: Puppet::Agent
Overview
A general class for triggering a run of another class.
Defined Under Namespace
Modules: Locker
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#client_class ⇒ Object
readonly
Returns the value of attribute client_class.
-
#splayed ⇒ Object
readonly
Returns the value of attribute splayed.
Instance Method Summary collapse
-
#initialize(client_class) ⇒ Agent
constructor
Just so we can specify that we are “the” instance.
- #lockfile_path ⇒ Object
- #needing_restart? ⇒ Boolean
-
#run(*args) ⇒ Object
Perform a run with our client.
-
#splay ⇒ Object
Sleep when splay is enabled; else just return.
-
#splayed? ⇒ Boolean
Have we splayed already?.
-
#start ⇒ Object
Start listening for events.
- #stopping? ⇒ Boolean
- #sync ⇒ Object
Methods included from Locker
#disable, #enable, #lock, #lockfile, #running?
Constructor Details
#initialize(client_class) ⇒ Agent
Just so we can specify that we are “the” instance.
14 15 16 17 18 |
# File 'lib/puppet/agent.rb', line 14 def initialize(client_class) @splayed = false @client_class = client_class end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
11 12 13 |
# File 'lib/puppet/agent.rb', line 11 def client @client end |
#client_class ⇒ Object (readonly)
Returns the value of attribute client_class.
11 12 13 |
# File 'lib/puppet/agent.rb', line 11 def client_class @client_class end |
#splayed ⇒ Object (readonly)
Returns the value of attribute splayed.
11 12 13 |
# File 'lib/puppet/agent.rb', line 11 def splayed @splayed end |
Instance Method Details
#lockfile_path ⇒ Object
20 21 22 |
# File 'lib/puppet/agent.rb', line 20 def lockfile_path client_class.lockfile_path end |
#needing_restart? ⇒ Boolean
24 25 26 |
# File 'lib/puppet/agent.rb', line 24 def needing_restart? Puppet::Application.restart_requested? end |
#run(*args) ⇒ Object
Perform a run with our client.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/puppet/agent.rb', line 29 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 SystemExit,NoMemoryError raise rescue Exception => 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 |
#splay ⇒ Object
Sleep when splay is enabled; else just return.
63 64 65 66 67 68 69 70 71 |
# File 'lib/puppet/agent.rb', line 63 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 |
#splayed? ⇒ Boolean
Have we splayed already?
58 59 60 |
# File 'lib/puppet/agent.rb', line 58 def splayed? splayed end |
#start ⇒ Object
Start listening for events. We’re pretty much just listening for timer events here.
75 76 77 78 79 80 81 82 83 |
# File 'lib/puppet/agent.rb', line 75 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 # Run once before we start following the timer timer.sound_alarm end |
#stopping? ⇒ Boolean
53 54 55 |
# File 'lib/puppet/agent.rb', line 53 def stopping? Puppet::Application.stop_requested? end |
#sync ⇒ Object
85 86 87 |
# File 'lib/puppet/agent.rb', line 85 def sync @sync ||= Sync.new end |