class MCollective::Runner
Attributes
state[R]
Public Class Methods
new(configfile)
click to toggle source
# File lib/mcollective/runner.rb 5 def initialize(configfile) 6 begin 7 @config = Config.instance 8 @config.loadconfig(configfile) unless @config.configured 9 @config.mode = :server 10 @stats = PluginManager["global_stats"] 11 @connection = PluginManager["connector_plugin"] 12 13 # @state describes the current contextual state of the MCollective runner. 14 # Valid states are: 15 # :running - MCollective is alive and receiving messages from the middleware 16 # :stopping - MCollective is shutting down and in the process of terminating 17 # :stopped - MCollective is not running 18 # :pausing - MCollective is going into it's paused state 19 # :unpausing - MCollective is waking up from it's paused state 20 # :paused - MCollective is paused and not receiving messages but can be woken up 21 @state = :stopped 22 @exit_receiver_thread = false 23 @registration_thread = nil 24 @agent_threads = [] 25 26 @security = PluginManager["security_plugin"] 27 @security.initiated_by = :node 28 29 unless Util.windows? 30 Signal.trap("USR1") do 31 Thread.new do 32 Log.info("Reloading all agents after receiving USR1 signal") 33 @agents.loadagents 34 end 35 end 36 37 Signal.trap("USR2") do 38 Thread.new do 39 Log.info("Cycling logging level due to USR2 signal") 40 Log.cycle_level 41 end 42 end 43 44 Signal.trap("WINCH") do 45 Thread.new do 46 Log.info("Reopening logfiles due to WINCH signal") 47 Log.reopen 48 Log.info("Reopened logfiles due to WINCH signal") 49 end 50 end 51 else 52 Util.setup_windows_sleeper 53 end 54 rescue => e 55 Log.error("Failed to initialize MCollective runner.") 56 Log.error(e) 57 Log.error(e.backtrace.join("\n\t")) 58 raise e 59 end 60 end
Public Instance Methods
main_loop()
click to toggle source
The main runner loop
# File lib/mcollective/runner.rb 69 def main_loop 70 # Enter the main context 71 @receiver_thread = start_receiver_thread 72 loop do 73 begin 74 case @state 75 when :stopping 76 Log.debug("Stopping MCollective server") 77 78 # If soft_shutdown has been enabled we wait for all running agents to 79 # finish, one way or the other. 80 if @config.soft_shutdown 81 soft_shutdown 82 end 83 84 stop_threads 85 @state = :stopped 86 return 87 88 # When pausing we stop the receiver thread but keep everything else alive 89 # This means that running agents also run to completion. 90 when :pausing 91 Log.debug("Pausing MCollective server") 92 stop_threads 93 @state = :paused 94 95 when :unpausing 96 Log.debug("Unpausing MCollective server") 97 start_receiver_thread 98 end 99 100 # prune dead threads from the agent_threads array 101 @agent_threads.reject! { |t| !t.alive? } 102 sleep 0.1 103 rescue SignalException => e 104 Log.info("Exiting after signal: #{e}") 105 stop 106 rescue => e 107 Log.error("A failure occurred in the MCollective runner.") 108 Log.error(e) 109 Log.error(e.backtrace.join("\n\t")) 110 stop 111 end 112 end 113 end
pause()
click to toggle source
# File lib/mcollective/runner.rb 119 def pause 120 if @state == :running 121 @state = :pausing 122 else 123 Log.error("Cannot pause MCollective while not in a running state") 124 end 125 end
resume()
click to toggle source
# File lib/mcollective/runner.rb 127 def resume 128 if @state == :paused 129 @state = :unpausing 130 else 131 Log.error("Cannot unpause MCollective when it is not paused") 132 end 133 end
run()
click to toggle source
Deprecated
# File lib/mcollective/runner.rb 63 def run 64 Log.warn("The #run method has been deprecated. Use #main_loop instead.") 65 main_loop 66 end
stop()
click to toggle source
# File lib/mcollective/runner.rb 115 def stop 116 @state = :stopping 117 end