passenger_api 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c96538b9f4c72d79d7c4951a498b812d4cf9efc0
4
- data.tar.gz: c1af38bf1c52e7f04107f42a246202720fcb4539
2
+ SHA256:
3
+ metadata.gz: d3981d1dcd88cc9810839a91a11c255c7746e25e646123102d376f9dbd5d6423
4
+ data.tar.gz: 18398b956c362efd2acf4bef2e3bc612f68b6c4cea81a82ece4675e420c305a0
5
5
  SHA512:
6
- metadata.gz: 9b4f4fa6a7a82860e5b1a2a9a0606e9c227aee498bd29cd126d34856857ffaa04cac99bb3fd6957c06eb833c618493a80c3b77928619d19588e1c519e0c722f2
7
- data.tar.gz: f87b4528041e5440bccc496cb32be3a24b326d430d12cec725b5847a73170c8150dae5908d23cd51e58a01beddcc96ef4d8e7bc62af8efb3d9bc0da0528a5edf
6
+ metadata.gz: 3f56efa6ddd0a5d968b634d28ef96bf280ce5b1763f8aa9cd02d898ff907328245d0be89c0157d05847506cee5e5b0245ee612c274499ea01978defed26ea4b5
7
+ data.tar.gz: e16c1c5d88c21380b20eb67dc12552345a40e6984289d5dd3ff8d8481ec698cc7c1611033448f44737c3653f96743a572e3bd5e1613bad238530e015372d9641
@@ -1,6 +1,5 @@
1
1
  .bundle
2
2
  .git
3
- Gemfile.lock
4
3
  coverage
5
4
  gemfiles
6
5
  vendor
data/.gitignore CHANGED
@@ -1,6 +1,5 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
- /Gemfile.lock
4
3
  /_yardoc/
5
4
  /coverage/
6
5
  /doc/
@@ -4,7 +4,7 @@ language: ruby
4
4
 
5
5
  rvm:
6
6
  - 2
7
- - 1.8
7
+ - 2.2
8
8
 
9
9
  install:
10
10
  - bundle install --jobs=3 --retry=3
data/Appraisals CHANGED
@@ -1,17 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- appraise 'passenger-5.0.10' do
4
- gem 'passenger', '5.0.10'
3
+ appraise 'passenger-5.0.22' do
4
+ gem 'passenger', '5.0.22'
5
5
  end
6
6
 
7
7
  appraise 'passenger-5.0' do
8
- gem 'passenger', '~> 5.0.10'
8
+ gem 'passenger', '~> 5.0.23'
9
9
  end
10
10
 
11
- appraise 'passenger-5.1.0' do
12
- gem 'passenger', '5.1.0'
11
+ appraise 'passenger-5.1' do
12
+ gem 'passenger', '~> 5.1'
13
13
  end
14
14
 
15
- appraise 'passenger-5.1' do
16
- gem 'passenger', '~> 5.1.0'
15
+ appraise 'passenger-5.2' do
16
+ gem 'passenger', '~> 5.2'
17
+ end
18
+
19
+ appraise 'passenger-5.3' do
20
+ gem 'passenger', '~> 5.3'
17
21
  end
@@ -0,0 +1,32 @@
1
+ FROM ruby
2
+
3
+ WORKDIR /app
4
+
5
+ COPY pkg/passenger_api-*.gem ./
6
+ RUN set -eux; \
7
+ gem install passenger_api-*.gem; \
8
+ passenger-config install-standalone-runtime; \
9
+ passenger-config build-native-support
10
+
11
+ #RUN set -eux; \
12
+ # gem install passenger_api; \
13
+ # passenger-config install-standalone-runtime; \
14
+ # passenger-config build-native-support
15
+
16
+
17
+
18
+
19
+ FROM ruby:slim
20
+
21
+ CMD ["passenger_api"]
22
+ EXPOSE 3000
23
+ WORKDIR /app
24
+
25
+ ENV \
26
+ PASSENGER_APP_ENV=production \
27
+ PASSENGER_MAX_POOL_SIZE=2 \
28
+ PASSENGER_MIN_INSTANCES=2 \
29
+ PASSENGER_DISABLE_SECURITY_UPDATE_CHECK=true \
30
+ PASSENGER_LOG_FILE=/dev/stdout
31
+
32
+ COPY --from=0 /usr/local/bundle /usr/local/bundle
data/Gemfile CHANGED
@@ -7,15 +7,4 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
7
7
  # Specify your gem's dependencies in passenger_api.gemspec
8
8
  gemspec
9
9
 
10
- if RUBY_VERSION > '2.0'
11
- gem 'rubocop', '0.49.1'
12
- end
13
-
14
- if RUBY_VERSION < '2.3'
15
- gem 'rack', '< 2'
16
- end
17
-
18
- if RUBY_VERSION < '1.9'
19
- gem 'json'
20
- gem 'rack-test', '< 0.7'
21
- end
10
+ gem 'rubocop', '0.49.1'
@@ -0,0 +1,62 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ passenger_api (0.2.0)
5
+ passenger (>= 5.0.22)
6
+ rack
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ appraisal (2.2.0)
12
+ bundler
13
+ rake
14
+ thor (>= 0.14.0)
15
+ ast (2.4.0)
16
+ docile (1.3.1)
17
+ json (2.1.0)
18
+ minitest (5.11.3)
19
+ parallel (1.12.1)
20
+ parser (2.5.1.0)
21
+ ast (~> 2.4.0)
22
+ passenger (5.3.1)
23
+ rack
24
+ rake (>= 0.8.1)
25
+ powerpack (0.1.1)
26
+ rack (2.0.5)
27
+ rack-test (1.0.0)
28
+ rack (>= 1.0, < 3)
29
+ rainbow (2.2.2)
30
+ rake
31
+ rake (10.5.0)
32
+ rubocop (0.49.1)
33
+ parallel (~> 1.10)
34
+ parser (>= 2.3.3.1, < 3.0)
35
+ powerpack (~> 0.1)
36
+ rainbow (>= 1.99.1, < 3.0)
37
+ ruby-progressbar (~> 1.7)
38
+ unicode-display_width (~> 1.0, >= 1.0.1)
39
+ ruby-progressbar (1.9.0)
40
+ simplecov (0.16.1)
41
+ docile (~> 1.1)
42
+ json (>= 1.8, < 3)
43
+ simplecov-html (~> 0.10.0)
44
+ simplecov-html (0.10.2)
45
+ thor (0.20.0)
46
+ unicode-display_width (1.3.3)
47
+
48
+ PLATFORMS
49
+ ruby
50
+
51
+ DEPENDENCIES
52
+ appraisal
53
+ bundler (~> 1.16)
54
+ minitest (~> 5.0)
55
+ passenger_api!
56
+ rack-test
57
+ rake (~> 10.0)
58
+ rubocop (= 0.49.1)
59
+ simplecov
60
+
61
+ BUNDLED WITH
62
+ 1.16.2
data/README.md CHANGED
@@ -2,31 +2,69 @@
2
2
 
3
3
  PassengerAPI is a Rack application to access Passenger internal APIs.
4
4
 
5
+ [![Gem Version](https://badge.fury.io/rb/passenger_api.svg)](https://badge.fury.io/rb/passenger_api)
5
6
  [![Build Status](https://travis-ci.org/m4i/passenger_api.svg?branch=master)](https://travis-ci.org/m4i/passenger_api)
6
7
  [![Test Coverage](https://codeclimate.com/github/m4i/passenger_api/badges/coverage.svg)](https://codeclimate.com/github/m4i/passenger_api/coverage)
7
8
  [![Code Climate](https://codeclimate.com/github/m4i/passenger_api/badges/gpa.svg)](https://codeclimate.com/github/m4i/passenger_api)
8
9
 
9
- ## Installation
10
+ ## Usage
10
11
 
11
- Add this line to your application's Gemfile:
12
+ Run PassengerAPI:
12
13
 
13
- ```ruby
14
- gem 'passenger_api'
14
+ ```
15
+ gem install passenger_api
16
+ passenger_api
15
17
  ```
16
18
 
17
- ## Usage
19
+ or
20
+
21
+ ```
22
+ docker run --rm -v /tmp:/tmp -p 3000:3000 m4i0/passenger_api
23
+ ```
18
24
 
19
- Add this line to your application's config.ru:
25
+ Run your application:
20
26
 
21
- ```ruby
22
- map('/passenger') { run PassengerAPI.new }
27
+ ```
28
+ passenger start -p 3001
23
29
  ```
24
30
 
25
31
  Then, access API.
26
32
 
27
33
  ```
28
- $ passenger start -d
29
- $ curl localhost:3000/passenger/pool.txt
34
+ $ curl -s localhost:3000/ping.json | jq .
35
+ [
36
+ {
37
+ "instance": {
38
+ "instance_dir": {
39
+ "created_at": 1527877456,
40
+ "created_at_monotonic_usec": 8184689115911,
41
+ "major_version": 4,
42
+ "minor_version": 0,
43
+ "path": "/tmp/passenger.VWzMe1k"
44
+ },
45
+ "instance_id": "p9npsg-ojQFlj-pTG7Y9",
46
+ "integration_mode": "standalone",
47
+ "name": "XELqenPb",
48
+ "passenger_version": "5.3.1",
49
+ "server_software": "nginx/1.14.0 Phusion_Passenger/5.3.1",
50
+ "standalone_engine": "nginx",
51
+ "watchdog_pid": 186,
52
+ "core_pid": 189,
53
+ "state": "good"
54
+ },
55
+ "status": 200,
56
+ "header": {
57
+ "Status": "200 OK",
58
+ "Content-Type": "application/json",
59
+ "Date": "Fri, 01 Jun 2018 18:29:08 +0000",
60
+ "Connection": "keep-alive",
61
+ "Content-Length": "18"
62
+ },
63
+ "body": "{ \"status\": \"ok\" }"
64
+ }
65
+ ]
66
+
67
+ $ curl -s localhost:3000/pool.txt | jq '.[].body' -r
30
68
  ----------- General information -----------
31
69
  Max pool size : 6
32
70
  App groups : 1
@@ -39,6 +77,46 @@ Requests in top-level queue : 0
39
77
  Requests in queue: 0
40
78
  * PID: 25915 Sessions: 1 Processed: 3 Uptime: 30s
41
79
  CPU: 0% Memory : 7M Last used: 0s ago
80
+
81
+ $ curl -s localhost:3000/pool.xml | jq '.[].body' -r | xmllint --format -
82
+ <?xml version="1.0" encoding="iso8859-1"?>
83
+ <info version="3">
84
+ <passenger_version>5.3.1</passenger_version>
85
+ <group_count>1</group_count>
86
+ <process_count>1</process_count>
87
+ <max>6</max>
88
+ <capacity_used>1</capacity_used>
89
+ <get_wait_list_size>0</get_wait_list_size>
90
+ <supergroups>
91
+ (snip)
92
+ </supergroups>
93
+ </info>
94
+ ```
95
+
96
+ Multiple instances:
97
+
98
+ ```
99
+ $ docker run -d --rm -v /tmp/a:/tmp/a phusion/passenger-ruby25 passenger start --instance-registry-dir /tmp/a
100
+ $ docker run -d --rm -v /tmp/b:/tmp/b phusion/passenger-ruby25 passenger start --instance-registry-dir /tmp/b
101
+ $ docker run -d --rm -v /tmp/c:/tmp/c phusion/passenger-ruby25 passenger start --instance-registry-dir /tmp/c
102
+ $ curl -sH 'X-Passenger-Instance-Registry-Dir: /tmp/*' localhost:3000/ping.json | jq .
103
+ [
104
+ {
105
+ (snip)
106
+ "path": "/tmp/b/passenger.1kGFpF5"
107
+ (snip)
108
+ },
109
+ {
110
+ (snip)
111
+ "path": "/tmp/a/passenger.P5HNi8e"
112
+ (snip)
113
+ },
114
+ {
115
+ (snip)
116
+ "path": "/tmp/c/passenger.6oU9Cgi"
117
+ (snip)
118
+ }
119
+ ]
42
120
  ```
43
121
 
44
122
  Passenger internal APIs are undocumented. If you want to know about them, please see https://github.com/phusion/passenger/issues/1407.
@@ -55,7 +133,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/m4i/pa
55
133
 
56
134
  ## License
57
135
 
58
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
136
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
59
137
 
60
138
  ## Code of Conduct
61
139
 
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'passenger_api'
4
+
5
+ run PassengerAPI.new
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ rackup = File.expand_path('../config.ru', __dir__)
5
+ ARGV.unshift(*%W[start --instance-registry-dir /var/run --rackup #{rackup}])
6
+ load Gem.bin_path('passenger', 'passenger')
@@ -1,38 +1,66 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'passenger_api/request'
4
3
  require 'passenger_api/version'
5
4
 
6
- class PassengerAPI
7
- def initialize
8
- require 'passenger_api/ext'
9
- end
5
+ require 'json'
6
+ require 'net/http'
10
7
 
8
+ require 'rack/request'
9
+
10
+ unless defined?(PhusionPassenger)
11
+ require 'phusion_passenger'
12
+ PhusionPassenger.locate_directories
13
+ end
14
+ PhusionPassenger.require_passenger_lib('admin_tools/instance_registry')
15
+
16
+ class PassengerAPI
11
17
  def call(env)
12
- to_rack_response(call_api(build_argv(Request.new(env))))
18
+ rack_request = Rack::Request.new(env)
19
+ case rack_request.path
20
+ when '/health'
21
+ [200, { 'Content-Type' => 'text/plain' }, ["OK\n"]]
22
+ else
23
+ proxy_api(rack_request)
24
+ end
13
25
  end
14
26
 
15
27
  private
16
28
 
17
- def build_argv(req)
18
- argv = [req.method, req.path]
19
- argv << '--data' << req.body unless req.body.empty?
20
- argv
21
- end
29
+ def proxy_api(rack_request)
30
+ dir = rack_request.get_header('HTTP_X_PASSENGER_INSTANCE_REGISTRY_DIR')
31
+ instances = PhusionPassenger::AdminTools::InstanceRegistry.new(dir).list
32
+ net_http_request = convert_rack_request_to_net_http_request(rack_request)
22
33
 
23
- def call_api(argv)
24
- argv += ['--show-headers']
25
- catch :response do
26
- PhusionPassenger::Config::ApiCallCommand.new(argv).run
34
+ responses = instances.map do |instance|
35
+ build_response(instance, call_api(instance, net_http_request))
27
36
  end
37
+
38
+ [200, { 'Content-Type' => 'application/json' }, [responses.to_json]]
39
+ end
40
+
41
+ def build_response(instance, net_http_response)
42
+ {
43
+ instance: instance.as_json.merge(state: instance.state),
44
+ status: net_http_response.code.to_i,
45
+ header: net_http_response.each_capitalized.to_h,
46
+ body: net_http_response.body,
47
+ }
28
48
  end
29
49
 
30
- def to_rack_response(res)
31
- # for Ruby 1.8.7
32
- # headers = res.each_capitalized.to_h
33
- headers = {}
34
- res.each_capitalized { |n, v| headers[n] = v }
50
+ def call_api(instance, net_http_request)
51
+ net_http_request.basic_auth('admin', instance.full_admin_password)
52
+ instance.http_request('agents.s/core_api', net_http_request)
53
+ end
35
54
 
36
- [res.code, headers, [res.body]]
55
+ def convert_rack_request_to_net_http_request(rack_request)
56
+ klass = Net::HTTP.const_get(rack_request.request_method.capitalize)
57
+ header = {}
58
+ if rack_request.content_type
59
+ header['Content-Type'] = rack_request.content_type
60
+ end
61
+ net_http_request = klass.new(rack_request.fullpath, header)
62
+ body = rack_request.body.read
63
+ net_http_request.body = body unless body.empty?
64
+ net_http_request
37
65
  end
38
66
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class PassengerAPI
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -15,18 +15,21 @@ Gem::Specification.new do |spec|
15
15
  spec.homepage = 'https://github.com/m4i/passenger_api'
16
16
  spec.license = 'MIT'
17
17
 
18
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
- f.match(%r{^(test|spec|features)/})
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
22
  end
21
23
  spec.bindir = 'exe'
22
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
25
  spec.require_paths = ['lib']
24
26
 
25
- spec.required_ruby_version = '>= 1.8.7'
27
+ spec.required_ruby_version = '>= 2.2.2'
26
28
 
27
- spec.add_dependency 'passenger', '>= 5.0.10'
29
+ spec.add_dependency 'passenger', '>= 5.0.22'
30
+ spec.add_dependency 'rack'
28
31
 
29
- spec.add_development_dependency 'bundler', '~> 1.15'
32
+ spec.add_development_dependency 'bundler', '~> 1.16'
30
33
  spec.add_development_dependency 'rake', '~> 10.0'
31
34
  spec.add_development_dependency 'minitest', '~> 5.0'
32
35
  spec.add_development_dependency 'appraisal'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: passenger_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masaki Takeuchi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-16 00:00:00.000000000 Z
11
+ date: 2018-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: passenger
@@ -16,28 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 5.0.10
19
+ version: 5.0.22
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 5.0.10
26
+ version: 5.0.22
27
+ - !ruby/object:Gem::Dependency
28
+ name: rack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '1.15'
47
+ version: '1.16'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '1.15'
54
+ version: '1.16'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -111,7 +125,8 @@ dependencies:
111
125
  description: PassengerAPI is a Rack application to access Passenger internal APIs.
112
126
  email:
113
127
  - m.ishihara@gmail.com
114
- executables: []
128
+ executables:
129
+ - passenger_api
115
130
  extensions: []
116
131
  extra_rdoc_files: []
117
132
  files:
@@ -121,15 +136,17 @@ files:
121
136
  - ".travis.yml"
122
137
  - Appraisals
123
138
  - CODE_OF_CONDUCT.md
139
+ - Dockerfile
124
140
  - Gemfile
141
+ - Gemfile.lock
125
142
  - LICENSE.txt
126
143
  - README.md
127
144
  - Rakefile
128
145
  - bin/console
129
146
  - bin/setup
147
+ - config.ru
148
+ - exe/passenger_api
130
149
  - lib/passenger_api.rb
131
- - lib/passenger_api/ext.rb
132
- - lib/passenger_api/request.rb
133
150
  - lib/passenger_api/version.rb
134
151
  - passenger_api.gemspec
135
152
  homepage: https://github.com/m4i/passenger_api
@@ -144,7 +161,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
144
161
  requirements:
145
162
  - - ">="
146
163
  - !ruby/object:Gem::Version
147
- version: 1.8.7
164
+ version: 2.2.2
148
165
  required_rubygems_version: !ruby/object:Gem::Requirement
149
166
  requirements:
150
167
  - - ">="
@@ -152,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
169
  version: '0'
153
170
  requirements: []
154
171
  rubyforge_project:
155
- rubygems_version: 2.6.11
172
+ rubygems_version: 2.7.6
156
173
  signing_key:
157
174
  specification_version: 4
158
175
  summary: A Rack application to access Passenger internal APIs
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- unless defined?(PhusionPassenger)
4
- require 'phusion_passenger'
5
- PhusionPassenger.locate_directories
6
- end
7
- PhusionPassenger.require_passenger_lib 'config/api_call_command'
8
-
9
- module PhusionPassenger
10
- module Config
11
- class ApiCallCommand
12
- private
13
-
14
- def print_headers(response)
15
- throw :response, response
16
- end
17
- end
18
- end
19
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class PassengerAPI
4
- class Request
5
- def initialize(env)
6
- @env = env
7
- end
8
-
9
- def method
10
- @env['REQUEST_METHOD']
11
- end
12
-
13
- def path
14
- path = @env['PATH_INFO']
15
- path = '/' if path.empty?
16
- path += "?#{@env['QUERY_STRING']}" unless @env['QUERY_STRING'].empty?
17
- path
18
- end
19
-
20
- def body
21
- @_body ||= @env['rack.input'].read
22
- end
23
- end
24
- end