Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 67 lines (55 sloc) 1.722 kB
c5aad50 @evanphx Add App::Status rack app to control a server
evanphx authored
1 module Puma
2 module App
3 class Status
c48b804 @evanphx Refactor modes, fix control server to always work
evanphx authored
4 def initialize(cli)
d8026e8 @evanphx Add ability to restart by reexecing and pumactl to use it
evanphx authored
5 @cli = cli
a91d64a @evanphx Add auth token support to App::Status
evanphx authored
6 @auth_token = nil
7 end
ede98da @jc00ke Return valid Rack responses from status server
jc00ke authored
8 OK_STATUS = '{ "status": "ok" }'.freeze
a91d64a @evanphx Add auth token support to App::Status
evanphx authored
9
10 attr_accessor :auth_token
11
12 def authenticate(env)
13 return true unless @auth_token
14 env['QUERY_STRING'].to_s.split(/&;/).include?("token=#{@auth_token}")
c5aad50 @evanphx Add App::Status rack app to control a server
evanphx authored
15 end
16
c48b804 @evanphx Refactor modes, fix control server to always work
evanphx authored
17 def rack_response(status, body, content_type='application/json')
18 headers = {
19 'Content-Type' => content_type,
20 'Content-Length' => body.bytesize.to_s
21 }
22
23 [status, headers, [body]]
24 end
25
c5aad50 @evanphx Add App::Status rack app to control a server
evanphx authored
26 def call(env)
a91d64a @evanphx Add auth token support to App::Status
evanphx authored
27 unless authenticate(env)
29a7102 @jc00ke Use correct Content-Type
jc00ke authored
28 return rack_response(403, 'Invalid auth token', 'text/plain')
a91d64a @evanphx Add auth token support to App::Status
evanphx authored
29 end
30
c5aad50 @evanphx Add App::Status rack app to control a server
evanphx authored
31 case env['PATH_INFO']
a2a5331 allow for alternate locations for status app
Paco Viromontes authored
32 when /\/stop$/
c48b804 @evanphx Refactor modes, fix control server to always work
evanphx authored
33 @cli.stop
ede98da @jc00ke Return valid Rack responses from status server
jc00ke authored
34 return rack_response(200, OK_STATUS)
c5aad50 @evanphx Add App::Status rack app to control a server
evanphx authored
35
a2a5331 allow for alternate locations for status app
Paco Viromontes authored
36 when /\/halt$/
c48b804 @evanphx Refactor modes, fix control server to always work
evanphx authored
37 @cli.halt
ede98da @jc00ke Return valid Rack responses from status server
jc00ke authored
38 return rack_response(200, OK_STATUS)
c5aad50 @evanphx Add App::Status rack app to control a server
evanphx authored
39
a2a5331 allow for alternate locations for status app
Paco Viromontes authored
40 when /\/restart$/
c48b804 @evanphx Refactor modes, fix control server to always work
evanphx authored
41 @cli.restart
42 return rack_response(200, OK_STATUS)
8920846 @evanphx + Add ability to inherit server sockets on restart
evanphx authored
43
c48b804 @evanphx Refactor modes, fix control server to always work
evanphx authored
44 when /\/phased-restart$/
45 if !@cli.phased_restart
678a6c7 @mjc Fix typo in phased-restart response
mjc authored
46 return rack_response(404, '{ "error": "phased restart not available" }')
d8026e8 @evanphx Add ability to restart by reexecing and pumactl to use it
evanphx authored
47 else
c48b804 @evanphx Refactor modes, fix control server to always work
evanphx authored
48 return rack_response(200, OK_STATUS)
d8026e8 @evanphx Add ability to restart by reexecing and pumactl to use it
evanphx authored
49 end
50
48b50a3 @rubencaro Add reload_worker_directory
rubencaro authored
51 when /\/reload-worker-directory$/
52 if !@cli.reload_worker_directory
53 return rack_response(404, '{ "error": "reload_worker_directory not available" }')
54 else
55 return rack_response(200, OK_STATUS)
56 end
57
a2a5331 allow for alternate locations for status app
Paco Viromontes authored
58 when /\/stats$/
c48b804 @evanphx Refactor modes, fix control server to always work
evanphx authored
59 return rack_response(200, @cli.stats)
60 else
61 rack_response 404, "Unsupported action", 'text/plain'
c5aad50 @evanphx Add App::Status rack app to control a server
evanphx authored
62 end
63 end
64 end
65 end
66 end
Something went wrong with that request. Please try again.