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

67 lines
1.7 KiB
Ruby
Raw Normal View History

module Puma
module App
class Status
def initialize(cli)
@cli = cli
2011-12-06 19:22:02 -05:00
@auth_token = nil
end
OK_STATUS = '{ "status": "ok" }'.freeze
2011-12-06 19:22:02 -05:00
attr_accessor :auth_token
def authenticate(env)
return true unless @auth_token
env['QUERY_STRING'].to_s.split(/&;/).include?("token=#{@auth_token}")
end
def rack_response(status, body, content_type='application/json')
headers = {
'Content-Type' => content_type,
'Content-Length' => body.bytesize.to_s
}
[status, headers, [body]]
end
def call(env)
2011-12-06 19:22:02 -05:00
unless authenticate(env)
2012-04-29 15:24:00 -04:00
return rack_response(403, 'Invalid auth token', 'text/plain')
2011-12-06 19:22:02 -05:00
end
case env['PATH_INFO']
when /\/stop$/
@cli.stop
return rack_response(200, OK_STATUS)
when /\/halt$/
@cli.halt
return rack_response(200, OK_STATUS)
when /\/restart$/
@cli.restart
return rack_response(200, OK_STATUS)
when /\/phased-restart$/
if !@cli.phased_restart
return rack_response(404, '{ "error": "phased restart not available" }')
else
return rack_response(200, OK_STATUS)
end
2014-02-25 08:52:20 -05:00
when /\/reload-worker-directory$/
if !@cli.reload_worker_directory
return rack_response(404, '{ "error": "reload_worker_directory not available" }')
else
return rack_response(200, OK_STATUS)
end
when /\/stats$/
return rack_response(200, @cli.stats)
else
rack_response 404, "Unsupported action", 'text/plain'
end
end
end
end
end