1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00
puma--puma/lib/puma/app/status.rb

50 lines
1.1 KiB
Ruby
Raw Normal View History

module Puma
module App
class Status
def initialize(server, cli)
@server = server
@cli = cli
2011-12-06 19:22:02 -05:00
@auth_token = nil
end
attr_accessor :auth_token
def authenticate(env)
return true unless @auth_token
env['QUERY_STRING'].to_s.split(/&;/).include?("token=#{@auth_token}")
end
def call(env)
2011-12-06 19:22:02 -05:00
unless authenticate(env)
return [403, {}, ["Invalid auth token"]]
end
case env['PATH_INFO']
when "/stop"
@server.stop
return [200, {}, ['{ "status": "ok" }']]
when "/halt"
@server.halt
return [200, {}, ['{ "status": "ok" }']]
when "/restart"
if @cli and @cli.restart_on_stop!
@server.stop
return [200, {}, ['{ "status": "ok" }']]
else
return [200, {}, ['{ "status": "not configured" }']]
end
when "/stats"
b = @server.backlog
r = @server.running
return [200, {}, ["{ \"backlog\": #{b}, \"running\": #{r} }"]]
end
[404, {}, ["Unsupported action"]]
end
end
end
end