nginx_utils 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +6 -14
- data/.travis.yml +1 -6
- data/bin/nginx_utils +2 -0
- data/lib/nginx_utils/logreader.rb +4 -7
- data/lib/nginx_utils/status.rb +3 -3
- data/lib/nginx_utils/version.rb +1 -1
- data/lib/nginx_utils/virtual_host.rb +12 -12
- data/spec/nginx_utils/cli_spec.rb +0 -13
- data/spec/nginx_utils/virtual_host_spec.rb +127 -48
- data/spec/spec_helper.rb +14 -0
- data/spec/support/spec_utils.rb +15 -0
- data/template/virtual_host.erb +0 -1
- metadata +13 -11
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
ZGJiMzBmMzY2OTY3M2IzMmRiMjliMTMxNDhmMjNlODNkMmEwZmU4MjU4ZTY3
|
10
|
-
Mjc5ZDNhMTg4NWM5ODYzMmI0Y2VjMThjMTM4NTcwY2M1MjcwOGE4ZmQ2MTcw
|
11
|
-
ODRmOGJlNWFiZmU2YzFmMmQyZjY4ODU3YzFjNzA3MDJkYjNiYWU=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
ZTY3Mzg5N2Q4NGZlOTNiZDc0NjA1OTFkOWM4ZTRkMDI5NGNhYTEzYjA5OTFl
|
14
|
-
Y2Q1ZTY5OTVhZTA4MjUxYmJiZmY2NTgwYjhkMTU2Mjg3MzkzYTE3OGRlNjBl
|
15
|
-
N2RkNGJiNTZjYjQ2N2I1NGU4MDQwYWJhYzRjZGVmMmU3NzY3ZTU=
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cf5488e608925ed21642a11030049b886a369d63
|
4
|
+
data.tar.gz: ea2d9f31581ed7adedea3771e36af73058ee3225
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4c5cab54b88e8a94344c9ec2165b7aa25e63bb0144df44c6438c0339fbb22b2d67c9925fee74104f64a3a783a686b6c38cf4ef210a33d131b22392854beea26e
|
7
|
+
data.tar.gz: 1c224216d8b3684e562e206fbd623eb3ba1aa9be65a540134ba95110dd85c96d628657fd28a9ad2ca94b5780431e1023c73dd8dfdcb9df95240166016dd010de
|
data/.travis.yml
CHANGED
data/bin/nginx_utils
CHANGED
@@ -8,14 +8,11 @@ module NginxUtils
|
|
8
8
|
@log = File.open(log)
|
9
9
|
|
10
10
|
if options[:parser]
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
else
|
15
|
-
raise ArgumentError, "invalid argument"
|
16
|
-
end
|
11
|
+
raise ArgumentError, "invalid argument" unless options[:parser].is_a? Regexp
|
12
|
+
@format = :custom
|
13
|
+
@parser = options[:parser]
|
17
14
|
else
|
18
|
-
@format = options
|
15
|
+
@format = options.fetch(:format, :ltsv)
|
19
16
|
end
|
20
17
|
end
|
21
18
|
|
data/lib/nginx_utils/status.rb
CHANGED
@@ -4,9 +4,9 @@ module NginxUtils
|
|
4
4
|
module Status
|
5
5
|
class << self
|
6
6
|
def get(options={})
|
7
|
-
host = options
|
8
|
-
port = options
|
9
|
-
path = options
|
7
|
+
host = options.fetch(:host, "localhost")
|
8
|
+
port = options.fetch(:port, 80)
|
9
|
+
path = options.fetch(:path, "/nginx_status")
|
10
10
|
|
11
11
|
req = Net::HTTP::Get.new(path)
|
12
12
|
res = Net::HTTP.start(host, port){|http| http.request(req)}
|
data/lib/nginx_utils/version.rb
CHANGED
@@ -20,10 +20,10 @@ module NginxUtils
|
|
20
20
|
case options[:vhost_type].to_sym
|
21
21
|
when :unicorn then
|
22
22
|
@vhost_type = :unicorn
|
23
|
-
@destination = options
|
23
|
+
@destination = options.fetch(:destination, "127.0.0.1:8080")
|
24
24
|
when :proxy then
|
25
25
|
@vhost_type = :proxy
|
26
|
-
@destination = options
|
26
|
+
@destination = options.fetch(:destination, "127.0.0.1:8080")
|
27
27
|
when :passenger then
|
28
28
|
@vhost_type = :passenger
|
29
29
|
else
|
@@ -38,13 +38,13 @@ module NginxUtils
|
|
38
38
|
|
39
39
|
def set_common_params(options)
|
40
40
|
# Arguments: prefix, server_name, root, index, auth_basic, auth_basic_user_file in options
|
41
|
-
@prefix = options
|
42
|
-
@server_name = options
|
43
|
-
@root = options
|
44
|
-
@index = options
|
41
|
+
@prefix = options.fetch(:prefix, "/usr/local/nginx")
|
42
|
+
@server_name = options.fetch(:server_name, "example.com")
|
43
|
+
@root = options.fetch(:root, File.join(@prefix, "vhosts", @server_name, "html"))
|
44
|
+
@index = options.fetch(:index, ["index.html", "index.htm"].join(" "))
|
45
45
|
@auth_basic = options[:auth_basic]
|
46
46
|
if @auth_basic
|
47
|
-
@auth_basic_user_file = options
|
47
|
+
@auth_basic_user_file = options.fetch(:auth_basic_user_file, File.join(@prefix, "vhosts", @server_name, "etc", "users"))
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -55,16 +55,16 @@ module NginxUtils
|
|
55
55
|
@http = false if options[:only_https]
|
56
56
|
@https = false if options[:only_http]
|
57
57
|
if @https
|
58
|
-
@ssl_certificate = options
|
59
|
-
@ssl_certificate_key = options
|
58
|
+
@ssl_certificate = options.fetch(:ssl_certificate, File.join(@prefix, "vhosts", @server_name, "ssl.crt", "server.crt"))
|
59
|
+
@ssl_certificate_key = options.fetch(:ssl_certificate_key, File.join(@prefix, "vhosts", @server_name, "ssl.key", "server.key"))
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
63
|
def set_log_params(options)
|
64
64
|
# Arguments: log_dir, access_log_format, error_log_level in options
|
65
|
-
@log_dir = options
|
66
|
-
@access_log_format = options
|
67
|
-
@error_log_level = options
|
65
|
+
@log_dir = options.fetch(:log_dir, File.join(@prefix, "vhosts", @server_name, "logs"))
|
66
|
+
@access_log_format = options.fetch(:access_log_format, :ltsv)
|
67
|
+
@error_log_level = options.fetch(:error_log_level, :info)
|
68
68
|
end
|
69
69
|
|
70
70
|
def config
|
@@ -1,21 +1,8 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
3
|
require "spec_helper"
|
4
|
-
require "stringio"
|
5
4
|
|
6
5
|
describe NginxUtils::CLI do
|
7
|
-
def capture(stream)
|
8
|
-
begin
|
9
|
-
stream = stream.to_s
|
10
|
-
eval "$#{stream} = StringIO.new"
|
11
|
-
yield
|
12
|
-
result = eval("$#{stream}").string
|
13
|
-
ensure
|
14
|
-
eval("$#{stream} = #{stream.upcase}")
|
15
|
-
end
|
16
|
-
result
|
17
|
-
end
|
18
|
-
|
19
6
|
describe "#status" do
|
20
7
|
let(:result) {
|
21
8
|
{
|
@@ -179,67 +179,146 @@ describe NginxUtils::VirtualHost do
|
|
179
179
|
end
|
180
180
|
|
181
181
|
describe "#config" do
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
182
|
+
context "for unicron" do
|
183
|
+
subject {
|
184
|
+
virtual_host = NginxUtils::VirtualHost.new(
|
185
|
+
vhost_type: :unicorn,
|
186
|
+
destination: "/usr/local/rails/app/tmp/unicorn.sock",
|
187
|
+
prefix: "/opt/nginx",
|
188
|
+
server_name: "nginx_utils.example.com",
|
189
|
+
index: "index.rb",
|
190
|
+
log_dir: "/var/log",
|
191
|
+
access_log_format: "combined",
|
192
|
+
error_log_level: "error",
|
193
|
+
auth_basic: "Auth"
|
194
|
+
)
|
195
|
+
virtual_host.config
|
196
|
+
}
|
197
|
+
|
198
|
+
it "upstream block should be defined" do
|
199
|
+
should match(/upstream backend-unicorn/)
|
200
|
+
end
|
200
201
|
|
201
|
-
|
202
|
-
|
203
|
-
|
202
|
+
it "http block should be defined" do
|
203
|
+
should match(/listen 80;/)
|
204
|
+
end
|
204
205
|
|
205
|
-
|
206
|
-
|
207
|
-
|
206
|
+
it "https block should be defined" do
|
207
|
+
should match(/listen 443 ssl;/)
|
208
|
+
end
|
208
209
|
|
209
|
-
|
210
|
-
|
211
|
-
|
210
|
+
it "unix domain socket should be defined" do
|
211
|
+
should match(/server unix:\/usr\/local\/rails\/app\/tmp\/unicorn\.sock;/)
|
212
|
+
end
|
212
213
|
|
213
|
-
|
214
|
-
|
215
|
-
|
214
|
+
it "server_name should be defined" do
|
215
|
+
should match(/server_name nginx_utils.example.com;/)
|
216
|
+
end
|
216
217
|
|
217
|
-
|
218
|
-
|
219
|
-
|
218
|
+
it "index should be defined" do
|
219
|
+
should match(/index index.rb;/)
|
220
|
+
end
|
220
221
|
|
221
|
-
|
222
|
-
|
223
|
-
|
222
|
+
it "access_log should be defined" do
|
223
|
+
should match(/access_log \/var\/log\/access.log combined;/)
|
224
|
+
end
|
224
225
|
|
225
|
-
|
226
|
-
|
227
|
-
|
226
|
+
it "error_log should be defined" do
|
227
|
+
should match(/error_log \/var\/log\/error.log error;/)
|
228
|
+
end
|
228
229
|
|
229
|
-
|
230
|
-
|
231
|
-
|
230
|
+
it "auth_basic should be defined" do
|
231
|
+
should match(/auth_basic "Auth";/)
|
232
|
+
end
|
233
|
+
|
234
|
+
it "auth_basic_user_file should be defined" do
|
235
|
+
should match(/auth_basic_user_file \/opt\/nginx\/vhosts\/nginx_utils\.example\.com\/etc\/users;/)
|
236
|
+
end
|
237
|
+
|
238
|
+
it "try_files should be defined" do
|
239
|
+
should match(/try_files/)
|
240
|
+
end
|
232
241
|
|
233
|
-
|
234
|
-
|
242
|
+
it "proxy_pass should be defined" do
|
243
|
+
should match(/proxy_pass http:\/\/backend-unicorn;/)
|
244
|
+
end
|
235
245
|
end
|
236
246
|
|
237
|
-
|
238
|
-
|
247
|
+
context "for passenger" do
|
248
|
+
subject {
|
249
|
+
virtual_host = NginxUtils::VirtualHost.new(
|
250
|
+
vhost_type: :passenger,
|
251
|
+
only_https: true
|
252
|
+
)
|
253
|
+
virtual_host.config
|
254
|
+
}
|
255
|
+
|
256
|
+
it "upstream block should not defined" do
|
257
|
+
should_not match(/upstream backend-unicorn/)
|
258
|
+
end
|
259
|
+
|
260
|
+
it "http block should not defined" do
|
261
|
+
should_not match(/listen 80/)
|
262
|
+
end
|
263
|
+
|
264
|
+
it "auth_basic should not defined" do
|
265
|
+
should_not match(/auth_basic/)
|
266
|
+
end
|
267
|
+
|
268
|
+
it "proxy_pass should not defined" do
|
269
|
+
should_not match(/proxy_pass/)
|
270
|
+
end
|
271
|
+
|
272
|
+
it "https block should be defined" do
|
273
|
+
should match(/listen 443 ssl/)
|
274
|
+
end
|
275
|
+
|
276
|
+
it "server_name should be default" do
|
277
|
+
should match(/server_name example.com;/)
|
278
|
+
end
|
279
|
+
|
280
|
+
it "index should be default" do
|
281
|
+
should match(/index index.html index.htm;/)
|
282
|
+
end
|
283
|
+
|
284
|
+
it "passenger_enabled should be defined" do
|
285
|
+
should match(/passenger_enabled on/)
|
286
|
+
end
|
239
287
|
end
|
240
288
|
|
241
|
-
|
242
|
-
|
289
|
+
context "for proxy" do
|
290
|
+
subject {
|
291
|
+
virtual_host = NginxUtils::VirtualHost.new(
|
292
|
+
vhost_type: :proxy,
|
293
|
+
destination: "192.168.10.241:8080",
|
294
|
+
only_http: true
|
295
|
+
)
|
296
|
+
virtual_host.config
|
297
|
+
}
|
298
|
+
|
299
|
+
it "upstream block should not defined" do
|
300
|
+
should_not match(/upstream backend-unicorn/)
|
301
|
+
end
|
302
|
+
|
303
|
+
it "http block should defined" do
|
304
|
+
should match(/listen 80/)
|
305
|
+
end
|
306
|
+
|
307
|
+
it "https block should not defined" do
|
308
|
+
should_not match(/listen 443 ssl/)
|
309
|
+
end
|
310
|
+
|
311
|
+
it "proxy_pass should defined" do
|
312
|
+
should match(/proxy_pass http:\/\/192\.168\.10\.241:8080/)
|
313
|
+
end
|
314
|
+
|
315
|
+
it "proxy_redirect should defined" do
|
316
|
+
should match(/proxy_redirect default/)
|
317
|
+
end
|
318
|
+
|
319
|
+
it "passenger_enabled should be defined" do
|
320
|
+
should_not match(/passenger_enabled on/)
|
321
|
+
end
|
243
322
|
end
|
244
323
|
end
|
245
324
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,8 +2,22 @@ require "simplecov"
|
|
2
2
|
require "coveralls"
|
3
3
|
Coveralls.wear!
|
4
4
|
|
5
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
6
|
+
SimpleCov::Formatter::HTMLFormatter,
|
7
|
+
Coveralls::SimpleCov::Formatter
|
8
|
+
]
|
9
|
+
|
5
10
|
SimpleCov.start do
|
6
11
|
add_filter "spec"
|
12
|
+
add_filter ".bundle"
|
7
13
|
end
|
8
14
|
|
9
15
|
require "nginx_utils"
|
16
|
+
|
17
|
+
support_files = File.join(File.expand_path("..", __FILE__), "support/*.rb")
|
18
|
+
Dir[support_files].each {|f| require f}
|
19
|
+
|
20
|
+
RSpec.configure do |config|
|
21
|
+
config.order = "random"
|
22
|
+
config.include(SpecUtils)
|
23
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "stringio"
|
2
|
+
|
3
|
+
module SpecUtils
|
4
|
+
def capture(stream)
|
5
|
+
begin
|
6
|
+
stream = stream.to_s
|
7
|
+
eval "$#{stream} = StringIO.new"
|
8
|
+
yield
|
9
|
+
result = eval("$#{stream}").string
|
10
|
+
ensure
|
11
|
+
eval("$#{stream} = #{stream.upcase}")
|
12
|
+
end
|
13
|
+
result
|
14
|
+
end
|
15
|
+
end
|
data/template/virtual_host.erb
CHANGED
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nginx_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- i2bskn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
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
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
@@ -42,28 +42,28 @@ dependencies:
|
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
description: The various utilities on nginx
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- spec/nginx_utils/status_spec.rb
|
97
97
|
- spec/nginx_utils/virtual_host_spec.rb
|
98
98
|
- spec/spec_helper.rb
|
99
|
+
- spec/support/spec_utils.rb
|
99
100
|
- template/virtual_host.erb
|
100
101
|
homepage: https://github.com/i2bskn/nginx_utils
|
101
102
|
licenses:
|
@@ -107,17 +108,17 @@ require_paths:
|
|
107
108
|
- lib
|
108
109
|
required_ruby_version: !ruby/object:Gem::Requirement
|
109
110
|
requirements:
|
110
|
-
- -
|
111
|
+
- - '>='
|
111
112
|
- !ruby/object:Gem::Version
|
112
113
|
version: '0'
|
113
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
115
|
requirements:
|
115
|
-
- -
|
116
|
+
- - '>='
|
116
117
|
- !ruby/object:Gem::Version
|
117
118
|
version: '0'
|
118
119
|
requirements: []
|
119
120
|
rubyforge_project:
|
120
|
-
rubygems_version: 2.
|
121
|
+
rubygems_version: 2.1.6
|
121
122
|
signing_key:
|
122
123
|
specification_version: 4
|
123
124
|
summary: Nginx utilities
|
@@ -128,3 +129,4 @@ test_files:
|
|
128
129
|
- spec/nginx_utils/status_spec.rb
|
129
130
|
- spec/nginx_utils/virtual_host_spec.rb
|
130
131
|
- spec/spec_helper.rb
|
132
|
+
- spec/support/spec_utils.rb
|