Parent

Class/Module Index [+]

Quicksearch

MCollective::Runner

Attributes

state[R]

Public Class Methods

new(configfile) click to toggle source
# File lib/mcollective/runner.rb, line 5
def initialize(configfile)
  begin
    @config = Config.instance
    @config.loadconfig(configfile) unless @config.configured
    @config.mode = :server
    @stats = PluginManager["global_stats"]
    @connection = PluginManager["connector_plugin"]

    # @state describes the current contextual state of the MCollective runner.
    # Valid states are:
    #   :running   - MCollective is alive and receiving messages from the middleware
    #   :stopping  - MCollective is shutting down and in the process of terminating
    #   :stopped   - MCollective is not running
    #   :pausing   - MCollective is going into it's paused state
    #   :unpausing - MCollective is waking up from it's paused state
    #   :paused    - MCollective is paused and not receiving messages but can be woken up
    @state = :stopped
    @exit_receiver_thread = false
    @registration_thread = nil
    @agent_threads = []

    @security = PluginManager["security_plugin"]
    @security.initiated_by = :node

    unless Util.windows?
      Signal.trap("USR1") do
        Log.info("Reloading all agents after receiving USR1 signal")
        @agents.loadagents
      end

      Signal.trap("USR2") do
        Log.info("Cycling logging level due to USR2 signal")
        Log.cycle_level
      end
    else
      Util.setup_windows_sleeper
    end
  rescue => e
    Log.error("Failed to initialize MCollective runner.")
    Log.error(e)
    Log.error(e.backtrace.join("\n\t"))
    raise e
  end
end

Public Instance Methods

main_loop() click to toggle source

The main runner loop

# File lib/mcollective/runner.rb, line 57
def main_loop
  # Enter the main context
  @receiver_thread = start_receiver_thread
  loop do
    begin
      case @state
      when :stopping
        Log.debug("Stopping MCollective server")

        # If soft_shutdown has been enabled we wait for all running agents to
        # finish, one way or the other.
        if @config.soft_shutdown
          if Util.windows?
            Log.warn("soft_shutdown specified. This feature is not available on Windows. Shutting down normally.")
          else
            Log.debug("Waiting for all running agents to finish or timeout.")
            @agent_threads.each do |t|
              if t.alive?
                t.join
              end
            end
            Log.debug("All running agents have completed. Stopping.")
          end
        end

        stop_threads
        @state = :stopped
        return

      # When pausing we stop the receiver thread but keep everything else alive
      # This means that running agents also run to completion.
      when :pausing
        Log.debug("Pausing MCollective server")
        stop_threads
        @state = :paused

      when :unpausing
        Log.debug("Unpausing MCollective server")
        start_receiver_thread
      end

      # prune dead threads from the agent_threads array
      @agent_threads.reject! { |t| !t.alive? }
      sleep 0.1
    rescue SignalException => e
      Log.info("Exiting after signal: #{e}")
      stop
    rescue => e
      Log.error("A failure occurred in the MCollective runner.")
      Log.error(e)
      Log.error(e.backtrace.join("\n\t"))
      stop
    end
  end
end
pause() click to toggle source
# File lib/mcollective/runner.rb, line 117
def pause
  if @state == :running
    @state = :pausing
  else
    Log.error("Cannot pause MCollective while not in a running state")
  end
end
resume() click to toggle source
# File lib/mcollective/runner.rb, line 125
def resume
  if @state == :paused
    @state = :unpausing
  else
    Log.error("Cannot unpause MCollective when it is not paused")
  end
end
run() click to toggle source

Deprecated

# File lib/mcollective/runner.rb, line 51
def run
  Log.warn("The #run method has been deprecated. Use #main_loop instead.")
  main_loop
end
stop() click to toggle source
# File lib/mcollective/runner.rb, line 113
def stop
  @state = :stopping
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.