def run
      Log.init(@identity, @options[:log_path], :print => true)
      Log.level = @options[:log_level] if @options[:log_level]
      RightSupport::Log::Mixin.default_logger = Log
      ErrorTracker.init(self, @options[:agent_name], :shard_id => @options[:shard_id], :trace_level => TRACE_LEVEL,
                        :airbrake_endpoint => @options[:airbrake_endpoint], :airbrake_api_key => @options[:airbrake_api_key])
      @history.update("start")

      now = Time.now
      Log.info("[start] Agent #{@identity} starting; time: #{now.utc}; utc_offset: #{now.utc_offset}")
      @options.each { |k, v| Log.info("-  #{k}: #{k.to_s =~ /pass/ ? '****' : (v.respond_to?(:each) ? v.inspect : v)}") }

      begin
        # Capture process id in file after optional daemonize
        pid_file = PidFile.new(@identity)
        pid_file.check
        daemonize(@identity, @options) if @options[:daemonize]
        pid_file.write
        at_exit { pid_file.remove }

        if @mode == :http
          # HTTP is being used for RightNet communication instead of AMQP
          # The code loaded with the actors specific to this application
          # is responsible to call setup_http at the appropriate time
          start_service
        else
          # Initiate AMQP broker connection, wait for connection before proceeding
          # otherwise messages published on failed connection will be lost
          @client = RightAMQP::HABrokerClient.new(Serializer.new(:secure), @options.merge(:exception_stats => ErrorTracker.exception_stats))
          @queues.each { |s| @remaining_queue_setup[s] = @client.all }
          @client.connection_status(:one_off => @options[:connect_timeout]) do |status|
            if status == :connected
              # Need to give EM (on Windows) a chance to respond to the AMQP handshake
              # before doing anything interesting to prevent AMQP handshake from
              # timing-out; delay post-connected activity a second
              EM_S.add_timer(1) { start_service }
            elsif status == :failed
              terminate("failed to connect to any brokers during startup")
            elsif status == :timeout
              terminate("failed to connect to any brokers after #{@options[:connect_timeout]} seconds during startup")
            else
              terminate("broker connect attempt failed unexpectedly with status #{status} during startup")
            end
          end
        end
      rescue PidFile::AlreadyRunning
        EM.stop if EM.reactor_running?
        raise
      rescue StandardError => e
        terminate("failed startup", e)
      end
      true
    end
def run
      Log.init(@identity, @options[:log_path], :print => true)
      Log.level = @options[:log_level] if @options[:log_level]
      RightSupport::Log::Mixin.default_logger = Log
      ErrorTracker.init(self, @options[:agent_name], :shard_id => @options[:shard_id], :trace_level => TRACE_LEVEL,
                        :airbrake_endpoint => @options[:airbrake_endpoint], :airbrake_api_key => @options[:airbrake_api_key])
      @history.update("start")

      now = Time.now
      Log.info("[start] Agent #{@identity} starting; time: #{now.utc}; utc_offset: #{now.utc_offset}")
      @options.each { |k, v| Log.info("-  #{k}: #{k.to_s =~ /pass/ ? '****' : (v.respond_to?(:each) ? v.inspect : v)}") }

      begin
        # Capture process id in file after optional daemonize
        pid_file = PidFile.new(@identity)
        pid_file.check
        daemonize(@identity, @options) if @options[:daemonize]
        pid_file.write
        at_exit { pid_file.remove }

        if @mode == :http
          # HTTP is being used for RightNet communication instead of AMQP
          # The code loaded with the actors specific to this application
          # is responsible to call setup_http at the appropriate time
          start_service
        else
          # Initiate AMQP broker connection, wait for connection before proceeding
          # otherwise messages published on failed connection will be lost
          @client = RightAMQP::HABrokerClient.new(Serializer.new(:secure), @options.merge(:exception_stats => ErrorTracker.exception_stats))
          @queues.each { |s| @remaining_queue_setup[s] = @client.all }
          @client.connection_status(:one_off => @options[:connect_timeout]) do |status|
            if status == :connected
              # Need to give EM (on Windows) a chance to respond to the AMQP handshake
              # before doing anything interesting to prevent AMQP handshake from
              # timing-out; delay post-connected activity a second
              EM_S.add_timer(1) { start_service }
            elsif status == :failed
              terminate("failed to connect to any brokers during startup")
            elsif status == :timeout
              terminate("failed to connect to any brokers after #{@options[:connect_timeout]} seconds during startup")
            else
              terminate("broker connect attempt failed unexpectedly with status #{status} during startup")
            end
          end
        end
      rescue PidFile::AlreadyRunning
        EM.stop if EM.reactor_running?
        raise
      rescue StandardError => e
        terminate("failed startup", e)
      end
      true
    end
Initialize the new agent

 === Parameters
 opts(Hash):: Configuration options per start method above

 === Return
 true:: Always return true
 Put the agent in service
 This requires making a RightNet connection via HTTP or AMQP
 and other initialization like loading actors

 === Return
 true:: Always return true