Class: Puma::App::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/puma/app/status.rb

Overview

Check out #call's source code to see what actions this web application can respond to.

Constant Summary collapse

OK_STATUS =
'{ "status": "ok" }'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(cli, token = nil) ⇒ Status

Returns a new instance of Status.


12
13
14
15
# File 'lib/puma/app/status.rb', line 12

def initialize(cli, token = nil)
  @cli = cli
  @auth_token = token
end

Instance Method Details

#call(env) ⇒ Object


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/puma/app/status.rb', line 17

def call(env)
  unless authenticate(env)
    return rack_response(403, 'Invalid auth token', 'text/plain')
  end

  case env['PATH_INFO']
  when /\/stop$/
    @cli.stop
    rack_response(200, OK_STATUS)

  when /\/halt$/
    @cli.halt
    rack_response(200, OK_STATUS)

  when /\/restart$/
    @cli.restart
    rack_response(200, OK_STATUS)

  when /\/phased-restart$/
    if !@cli.phased_restart
      rack_response(404, '{ "error": "phased restart not available" }')
    else
      rack_response(200, OK_STATUS)
    end

  when /\/reload-worker-directory$/
    if !@cli.send(:reload_worker_directory)
      rack_response(404, '{ "error": "reload_worker_directory not available" }')
    else
      rack_response(200, OK_STATUS)
    end

  when /\/gc$/
    GC.start
    rack_response(200, OK_STATUS)

  when /\/gc-stats$/
    rack_response(200, GC.stat.to_json)

  when /\/stats$/
    rack_response(200, @cli.stats)

  when /\/thread-backtraces$/
    backtraces = []
    @cli.thread_status do |name, backtrace|
      backtraces << { name: name, backtrace: backtrace }
    end

    rack_response(200, backtraces.to_json)
  else
    rack_response 404, "Unsupported action", 'text/plain'
  end
end