nginx-puma 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/README.md +39 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/nginx/puma.rb +143 -0
- data/lib/nginx/puma/patch/puma/dsl.rb +18 -0
- data/lib/nginx/puma/version.rb +5 -0
- data/nginx-puma.gemspec +26 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5335002f67de558f2f8796e282409f0f19f60004
|
4
|
+
data.tar.gz: b6141d5377a3c21ad2f262c60a3db3e75376999d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 42ac2ddb66731e00083b23cb7b0f5378cb87e9037e86d7ffcc730a41f1bb17921bd216ebe57ed3b481b1fd396f4a54c316b362df9b51d821a6cedde664631b7f
|
7
|
+
data.tar.gz: d3a83a9b820d9f408e9257ac57464ca7447b38112c91fca123f9302bbf6addb67fe8e4d85abd5340be4870270e716e27aeb07c03089592a6fd13da87cea7e727
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
nginx-puma
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.2.2
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Nginx::Puma
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/nginx/puma`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'nginx-puma'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install nginx-puma
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it ( https://github.com/[my-github-username]/nginx-puma/fork )
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "nginx/puma"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/nginx/puma.rb
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
require "nginx/puma/patch/puma/dsl"
|
2
|
+
require "nginx/puma/version"
|
3
|
+
require "active_support/core_ext/string/strip"
|
4
|
+
require "securerandom"
|
5
|
+
|
6
|
+
module Nginx
|
7
|
+
module Puma
|
8
|
+
class SocketFileName
|
9
|
+
def initialize path
|
10
|
+
@path = path
|
11
|
+
end
|
12
|
+
def to_s
|
13
|
+
path
|
14
|
+
end
|
15
|
+
def to_nginx
|
16
|
+
"unix:#{@path}"
|
17
|
+
end
|
18
|
+
def to_puma
|
19
|
+
"unix://#{@path}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
class << self
|
23
|
+
def instance
|
24
|
+
@instance ||= SecureRandom.hex(6)
|
25
|
+
end
|
26
|
+
def run
|
27
|
+
use :Puma
|
28
|
+
ensure_shutdown
|
29
|
+
hijack_puma_binding
|
30
|
+
create_config
|
31
|
+
run_nginx
|
32
|
+
puts "Running NGinx"
|
33
|
+
end
|
34
|
+
def use const
|
35
|
+
raise RuntimeError.new unless Object.const_defined? const
|
36
|
+
end
|
37
|
+
def ensure_shutdown
|
38
|
+
at_exit do
|
39
|
+
if File.exists? "#{base_dir}/#{pid_file}"
|
40
|
+
pid = File.read("#{base_dir}/#{pid_file}").strip.to_i
|
41
|
+
Process.kill "TERM", pid
|
42
|
+
File.unlink "#{base_dir}/#{pid_file}" rescue nil
|
43
|
+
end
|
44
|
+
if File.exists? "#{base_dir}/#{conf_file}"
|
45
|
+
File.unlink "#{base_dir}/#{conf_file}" rescue nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
def hijack_puma_binding
|
50
|
+
@listens = puma_listeners_of_type(:tcp).map do |bind|
|
51
|
+
bind.sub(/:\/\//,':')
|
52
|
+
end
|
53
|
+
unbind_puma_from :tcp
|
54
|
+
bind_puma_to puma_sock.to_puma
|
55
|
+
end
|
56
|
+
def create_config
|
57
|
+
@config = <<-CONFIG.strip_heredoc
|
58
|
+
pid #{pid_file};
|
59
|
+
events {}
|
60
|
+
http {
|
61
|
+
upstream app {
|
62
|
+
server #{puma_sock.to_nginx} fail_timeout=0;
|
63
|
+
}
|
64
|
+
server {
|
65
|
+
#{listeners}
|
66
|
+
client_max_body_size 1G;
|
67
|
+
keepalive_timeout 5;
|
68
|
+
server_tokens off;
|
69
|
+
access_log #{base_dir}/app_access.log;
|
70
|
+
error_log #{base_dir}/app_error.log;
|
71
|
+
root #{public_path};
|
72
|
+
try_files $uri/index.html $uri.html $uri @app;
|
73
|
+
location @app {
|
74
|
+
proxy_pass http://app;
|
75
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
76
|
+
proxy_set_header Host $http_host;
|
77
|
+
proxy_redirect off;
|
78
|
+
}
|
79
|
+
location ~ ^/(assets)/ {
|
80
|
+
root #{public_path};
|
81
|
+
gzip_static on;
|
82
|
+
expires max;
|
83
|
+
add_header Cache-Control public;
|
84
|
+
access_log /dev/null;
|
85
|
+
}
|
86
|
+
}
|
87
|
+
}
|
88
|
+
CONFIG
|
89
|
+
@config = @config.split("\n").map{|x|x.gsub(/^[ ]+/,'')}.join(' ').gsub(" }","}").gsub("{ ","{").gsub("; ",";")
|
90
|
+
File.write "#{base_dir}/#{conf_file}",@config
|
91
|
+
end
|
92
|
+
def run_nginx
|
93
|
+
`#{start_command}`
|
94
|
+
end
|
95
|
+
def public_path
|
96
|
+
Rails.root.join('public').to_s rescue File.expand_path("./public")
|
97
|
+
end
|
98
|
+
def listens
|
99
|
+
@listens.empty? ? ['0.0.0.0:9292'] : @listens
|
100
|
+
end
|
101
|
+
def listeners
|
102
|
+
listens.collect do |listen|
|
103
|
+
"listen #{listen} default;"
|
104
|
+
end.join("\n")
|
105
|
+
end
|
106
|
+
def puma_listeners_of_type type
|
107
|
+
puma_binds.select do |bind|
|
108
|
+
bind =~ /^#{type}/
|
109
|
+
end
|
110
|
+
end
|
111
|
+
def unbind_puma_from type
|
112
|
+
binds = puma_binds
|
113
|
+
binds = binds.reject do |bind|
|
114
|
+
bind =~ /^#{type}/
|
115
|
+
end.uniq
|
116
|
+
puma_binds = binds
|
117
|
+
end
|
118
|
+
def bind_puma_to sock
|
119
|
+
binds = puma_binds
|
120
|
+
binds << sock
|
121
|
+
puma_binds = binds.uniq
|
122
|
+
end
|
123
|
+
def puma_binds
|
124
|
+
::Puma.cli_config.options[:binds]
|
125
|
+
end
|
126
|
+
def start_command
|
127
|
+
"nginx -p #{base_dir} -c #{conf_file}&"
|
128
|
+
end
|
129
|
+
def puma_sock
|
130
|
+
@socket_file_name ||= SocketFileName.new "/tmp/puma_#{instance}.sock"
|
131
|
+
end
|
132
|
+
def base_dir
|
133
|
+
"/tmp"
|
134
|
+
end
|
135
|
+
def pid_file
|
136
|
+
"nginx_#{instance}.pid"
|
137
|
+
end
|
138
|
+
def conf_file
|
139
|
+
"nginx_#{instance}.conf"
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Nginx
|
2
|
+
module Puma
|
3
|
+
module Patch
|
4
|
+
module Puma
|
5
|
+
module DSL
|
6
|
+
def reverse_proxy proxy_type
|
7
|
+
case proxy_type
|
8
|
+
when :nginx
|
9
|
+
::Nginx::Puma.run
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
::Puma::DSL.send(:include,::Nginx::Puma::Patch::Puma::DSL)
|
data/nginx-puma.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'nginx/puma/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "nginx-puma"
|
8
|
+
spec.version = Nginx::Puma::VERSION
|
9
|
+
spec.authors = ["Mathias Kaufmann"]
|
10
|
+
spec.email = ["me@stei.gr"]
|
11
|
+
|
12
|
+
spec.summary = %q{Helper to start NGinx in front of Puma.}
|
13
|
+
spec.description = %q{Helper to start NGinx in front of Puma.}
|
14
|
+
spec.homepage = "https://runtime.stei.gr/puma/nginx"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "activesupport"
|
22
|
+
spec.add_dependency "puma"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nginx-puma
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mathias Kaufmann
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: puma
|
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'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.8'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.8'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: Helper to start NGinx in front of Puma.
|
70
|
+
email:
|
71
|
+
- me@stei.gr
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".ruby-gemset"
|
78
|
+
- ".ruby-version"
|
79
|
+
- ".travis.yml"
|
80
|
+
- Gemfile
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
85
|
+
- lib/nginx/puma.rb
|
86
|
+
- lib/nginx/puma/patch/puma/dsl.rb
|
87
|
+
- lib/nginx/puma/version.rb
|
88
|
+
- nginx-puma.gemspec
|
89
|
+
homepage: https://runtime.stei.gr/puma/nginx
|
90
|
+
licenses: []
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.4.6
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: Helper to start NGinx in front of Puma.
|
112
|
+
test_files: []
|