class Puma::App::Status

Constants

OK_STATUS

Attributes

auth_token[RW]

Public Class Methods

new(server, cli) click to toggle source
# File lib/puma/app/status.rb, line 4
def initialize(server, cli)
  @server = server
  @cli = cli
  @auth_token = nil
end

Public Instance Methods

authenticate(env) click to toggle source
# File lib/puma/app/status.rb, line 13
def authenticate(env)
  return true unless @auth_token
  env['QUERY_STRING'].to_s.split(/&;/).include?("token=#{@auth_token}")
end
call(env) click to toggle source
# File lib/puma/app/status.rb, line 18
def call(env)
  unless authenticate(env)
    return rack_response(403, 'Invalid auth token', 'text/plain')
  end

  case env['PATH_INFO']
  when "/stop"
    @server.stop
    return rack_response(200, OK_STATUS)

  when "/halt"
    @server.halt
    return rack_response(200, OK_STATUS)

  when "/restart"
    if @cli and @cli.restart_on_stop!
      @server.begin_restart

      return rack_response(200, OK_STATUS)
    else
      return rack_response(200, '{ "status": "not configured" }')
    end

  when "/stats"
    b = @server.backlog
    r = @server.running
    return rack_response(200, %Q{ "backlog": #{b}, "running": #{r} }!)
  end

  rack_response 404, "Unsupported action", 'text/plain'
end