Class: Puppet::Agent
- Defined in:
- lib/puppet/agent.rb
Overview
A general class for triggering a run of another class.
Defined Under Namespace
Constant Summary
Constants included from Disabler
Disabler::DISABLED_MESSAGE_JSON_KEY
Instance Attribute Summary collapse
- #client ⇒ Object readonly
- #client_class ⇒ Object readonly
- #should_fork ⇒ Object readonly
- #splayed ⇒ Object readonly
Instance Method Summary collapse
-
#initialize(client_class, should_fork = true) ⇒ Agent
constructor
Just so we can specify that we are “the” instance.
- #needing_restart? ⇒ Boolean
-
#run(client_options = {}) ⇒ Object
Perform a run with our client.
- #run_in_fork(forking = true) ⇒ Object
-
#splay(do_splay = Puppet[:splay]) ⇒ Object
Sleep when splay is enabled; else just return.
-
#splayed? ⇒ Boolean
Have we splayed already?.
- #stopping? ⇒ Boolean
Methods included from Disabler
#disable, #disable_message, #disabled?, #enable
Methods included from Locker
#lock, #lockfile_path, #running?
Constructor Details
#initialize(client_class, should_fork = true) ⇒ Agent
Just so we can specify that we are “the” instance.
15 16 17 18 19 20 |
# File 'lib/puppet/agent.rb', line 15 def initialize(client_class, should_fork=true) @splayed = false @should_fork = should_fork @client_class = client_class end |
Instance Attribute Details
#client_class ⇒ Object (readonly)
12 13 14 |
# File 'lib/puppet/agent.rb', line 12 def client_class @client_class end |
#should_fork ⇒ Object (readonly)
12 13 14 |
# File 'lib/puppet/agent.rb', line 12 def should_fork @should_fork end |
#splayed ⇒ Object (readonly)
12 13 14 |
# File 'lib/puppet/agent.rb', line 12 def splayed @splayed end |
Instance Method Details
#needing_restart? ⇒ Boolean
22 23 24 |
# File 'lib/puppet/agent.rb', line 22 def needing_restart? Puppet::Application.restart_requested? end |
#run(client_options = {}) ⇒ Object
Perform a run with our client.
27 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 56 |
# File 'lib/puppet/agent.rb', line 27 def run( = {}) if running? Puppet.notice "Run of #{client_class} already in progress; skipping (#{lockfile_path} exists)" return end if disabled? Puppet.notice "Skipping run of #{client_class}; administratively disabled (Reason: '#{disable_message}');\nUse 'puppet agent --enable' to re-enable." return end result = nil block_run = Puppet::Application.controlled_run do splay .fetch :splay, Puppet[:splay] result = run_in_fork(should_fork) do with_client do |client| begin client_args = .merge(:pluginsync => Puppet[:pluginsync]) lock { client.run(client_args) } rescue SystemExit,NoMemoryError raise rescue Exception => detail Puppet.log_exception(detail, "Could not run #{client_class}: #{detail}") end end end true end Puppet.notice "Shutdown/restart in progress (#{Puppet::Application.run_status.inspect}); skipping run" unless block_run result end |
#run_in_fork(forking = true) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/puppet/agent.rb', line 78 def run_in_fork(forking = true) return yield unless forking or Puppet.features.windows? child_pid = Kernel.fork do $0 = "puppet agent: applying configuration" begin exit(yield) rescue SystemExit exit(-1) rescue NoMemoryError exit(-2) end end exit_code = Process.waitpid2(child_pid) case exit_code[1].exitstatus when -1 raise SystemExit when -2 raise NoMemoryError end exit_code[1].exitstatus end |
#splay(do_splay = Puppet[:splay]) ⇒ Object
Sleep when splay is enabled; else just return.
68 69 70 71 72 73 74 75 76 |
# File 'lib/puppet/agent.rb', line 68 def splay(do_splay = Puppet[:splay]) return unless do_splay return if splayed? time = rand(Puppet[:splaylimit] + 1) Puppet.info "Sleeping for #{time} seconds (splay is enabled)" sleep(time) @splayed = true end |
#splayed? ⇒ Boolean
Have we splayed already?
63 64 65 |
# File 'lib/puppet/agent.rb', line 63 def splayed? splayed end |
#stopping? ⇒ Boolean
58 59 60 |
# File 'lib/puppet/agent.rb', line 58 def stopping? Puppet::Application.stop_requested? end |