2011-12-05 12:01:19 -05:00
|
|
|
module Puma
|
|
|
|
module App
|
|
|
|
class Status
|
2011-12-05 18:58:23 -05:00
|
|
|
def initialize(server, cli)
|
2011-12-05 12:01:19 -05:00
|
|
|
@server = server
|
2011-12-05 18:58:23 -05:00
|
|
|
@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}")
|
2011-12-05 12:01:19 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
2011-12-06 19:22:02 -05:00
|
|
|
unless authenticate(env)
|
|
|
|
return [403, {}, ["Invalid auth token"]]
|
|
|
|
end
|
|
|
|
|
2011-12-05 12:01:19 -05:00
|
|
|
case env['PATH_INFO']
|
|
|
|
when "/stop"
|
|
|
|
@server.stop
|
|
|
|
return [200, {}, ['{ "status": "ok" }']]
|
|
|
|
|
|
|
|
when "/halt"
|
|
|
|
@server.halt
|
|
|
|
return [200, {}, ['{ "status": "ok" }']]
|
|
|
|
|
2011-12-05 18:58:23 -05:00
|
|
|
when "/restart"
|
|
|
|
if @cli and @cli.restart_on_stop!
|
|
|
|
@server.stop
|
|
|
|
return [200, {}, ['{ "status": "ok" }']]
|
|
|
|
else
|
|
|
|
return [200, {}, ['{ "status": "not configured" }']]
|
|
|
|
end
|
|
|
|
|
2011-12-05 12:01:19 -05:00
|
|
|
when "/stats"
|
|
|
|
b = @server.backlog
|
|
|
|
r = @server.running
|
|
|
|
return [200, {}, ["{ \"backlog\": #{b}, \"running\": #{r} }"]]
|
|
|
|
end
|
|
|
|
|
|
|
|
[404, {}, ["Unsupported action"]]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|