Class: Puppet::Agent
- Includes:
- Locker
- Defined in:
- lib/vendor/puppet/agent.rb
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?.
- #stopping? ⇒ Boolean
- #sync ⇒ Object
Methods included from Locker
#disable, #disabled?, #enable, #lock, #lockfile, #running?
Constructor Details
#initialize(client_class) ⇒ Agent
Just so we can specify that we are “the” instance.
13 14 15 16 17 |
# File 'lib/vendor/puppet/agent.rb', line 13 def initialize(client_class) @splayed = false @client_class = client_class end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
10 11 12 |
# File 'lib/vendor/puppet/agent.rb', line 10 def client @client end |
#client_class ⇒ Object (readonly)
Returns the value of attribute client_class.
10 11 12 |
# File 'lib/vendor/puppet/agent.rb', line 10 def client_class @client_class end |
#splayed ⇒ Object (readonly)
Returns the value of attribute splayed.
10 11 12 |
# File 'lib/vendor/puppet/agent.rb', line 10 def splayed @splayed end |
Instance Method Details
#lockfile_path ⇒ Object
19 20 21 |
# File 'lib/vendor/puppet/agent.rb', line 19 def lockfile_path client_class.lockfile_path end |
#needing_restart? ⇒ Boolean
23 24 25 |
# File 'lib/vendor/puppet/agent.rb', line 23 def needing_restart? Puppet::Application.restart_requested? end |
#run(*args) ⇒ Object
Perform a run with our client.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/vendor/puppet/agent.rb', line 28 def run(*args) if running? Puppet.notice "Run of #{client_class} already in progress; skipping" return end if disabled? Puppet.notice "Skipping run of #{client_class}; administratively disabled; use 'puppet agent --enable' to re-enable." 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 (#{Puppet::Application.run_status.inspect}); skipping run" unless block_run result end |
#splay ⇒ Object
Sleep when splay is enabled; else just return.
67 68 69 70 71 72 73 74 75 |
# File 'lib/vendor/puppet/agent.rb', line 67 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?
62 63 64 |
# File 'lib/vendor/puppet/agent.rb', line 62 def splayed? splayed end |
#stopping? ⇒ Boolean
57 58 59 |
# File 'lib/vendor/puppet/agent.rb', line 57 def stopping? Puppet::Application.stop_requested? end |
#sync ⇒ Object
77 78 79 |
# File 'lib/vendor/puppet/agent.rb', line 77 def sync @sync ||= Sync.new end |