nginxtra 1.2.6.7 → 1.2.6.8
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/nginxtra +1 -1
- data/bin/nginxtra_rails +1 -1
- data/lib/nginxtra.rb +1 -0
- data/lib/nginxtra/actions/install.rb +0 -38
- data/lib/nginxtra/actions/print.rb +23 -0
- data/lib/nginxtra/actions/start.rb +0 -6
- data/lib/nginxtra/cli.rb +22 -9
- data/lib/nginxtra/config.rb +106 -11
- data/lib/nginxtra/config_converter.rb +33 -2
- data/lib/nginxtra/version.rb +1 -1
- metadata +33 -33
data/bin/nginxtra
CHANGED
data/bin/nginxtra_rails
CHANGED
data/lib/nginxtra.rb
CHANGED
@@ -2,6 +2,7 @@ require "nginxtra/action"
|
|
2
2
|
require "nginxtra/actions/compile"
|
3
3
|
require "nginxtra/actions/convert"
|
4
4
|
require "nginxtra/actions/install"
|
5
|
+
require "nginxtra/actions/print"
|
5
6
|
require "nginxtra/actions/reload"
|
6
7
|
require "nginxtra/actions/restart"
|
7
8
|
require "nginxtra/actions/start"
|
@@ -6,23 +6,11 @@ module Nginxtra
|
|
6
6
|
class Install
|
7
7
|
include Nginxtra::Action
|
8
8
|
|
9
|
-
# Run the installation of nginxtra, but only after first
|
10
|
-
# prompting if the user wants the install. This will do nothing
|
11
|
-
# if run with --non-interactive mode.
|
12
|
-
def optional_install
|
13
|
-
return installation_skipped if non_interactive?
|
14
|
-
return up_to_date unless should_install?
|
15
|
-
return unless requesting_install?
|
16
|
-
install
|
17
|
-
end
|
18
|
-
|
19
9
|
# Run the installation of nginxtra.
|
20
10
|
def install
|
21
11
|
return up_to_date unless should_install?
|
22
12
|
check_if_nginx_is_installed
|
23
13
|
create_etc_script
|
24
|
-
remember_config_location
|
25
|
-
remember_working_directory
|
26
14
|
update_last_install
|
27
15
|
end
|
28
16
|
|
@@ -76,26 +64,6 @@ export GEM_PATH="#{ENV["GEM_PATH"]}"
|
|
76
64
|
@thor.say "nginxtra installation is up to date"
|
77
65
|
end
|
78
66
|
|
79
|
-
# Notify to the user that installation is being skipped.
|
80
|
-
def installation_skipped
|
81
|
-
@thor.say "skipping nginxtra installation"
|
82
|
-
end
|
83
|
-
|
84
|
-
# Remember the last config location, and use it unless the
|
85
|
-
# config is explicitly passed in.
|
86
|
-
def remember_config_location
|
87
|
-
# Absolute path somehow turns the path to a binary string when
|
88
|
-
# output to Yaml... so make it a string so it stays ascii
|
89
|
-
# readable.
|
90
|
-
Nginxtra::Status[:remembered_config] = Nginxtra::Config.loaded_config_path.to_s
|
91
|
-
end
|
92
|
-
|
93
|
-
# Remember the last working directory, and use it unless the
|
94
|
-
# working direcotry is explicitly passed in.
|
95
|
-
def remember_working_directory
|
96
|
-
Nginxtra::Status[:remembered_workingdir] = File.expand_path "."
|
97
|
-
end
|
98
|
-
|
99
67
|
# Mark the last installed version and last installed time (the
|
100
68
|
# former being used to determine if nginxtra has been installed
|
101
69
|
# yet).
|
@@ -104,12 +72,6 @@ export GEM_PATH="#{ENV["GEM_PATH"]}"
|
|
104
72
|
Nginxtra::Status[:last_install_time] = Time.now
|
105
73
|
end
|
106
74
|
|
107
|
-
# Ask the user if they wish to install. Return whether the user
|
108
|
-
# requests the install.
|
109
|
-
def requesting_install?
|
110
|
-
@thor.yes? "Would you like to install nginxtra?"
|
111
|
-
end
|
112
|
-
|
113
75
|
# Determine if the install should proceed. This will be true if
|
114
76
|
# the force option was used, or if this version of nginxtra
|
115
77
|
# differs from the last version installed.
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Nginxtra
|
2
|
+
module Actions
|
3
|
+
class Print
|
4
|
+
include Nginxtra::Action
|
5
|
+
|
6
|
+
def print
|
7
|
+
if @thor.options["list"]
|
8
|
+
@thor.say "Known config files:\n #{@config.files.sort.join "\n "}"
|
9
|
+
elsif @thor.options["compile-options"]
|
10
|
+
@thor.say "Compilation options:\n #{@config.compile_options}"
|
11
|
+
elsif @config.files.include?(file)
|
12
|
+
@thor.say @config.file_contents(file)
|
13
|
+
else
|
14
|
+
@thor.say "No config file by the name '#{file}' exists!"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def file
|
19
|
+
@thor.options["file"]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -12,7 +12,6 @@ module Nginxtra
|
|
12
12
|
def start
|
13
13
|
without_force do
|
14
14
|
compile
|
15
|
-
install
|
16
15
|
end
|
17
16
|
|
18
17
|
return no_need_to_start unless should_start?
|
@@ -26,11 +25,6 @@ module Nginxtra
|
|
26
25
|
Nginxtra::Actions::Compile.new(@thor, @config).compile
|
27
26
|
end
|
28
27
|
|
29
|
-
# Invoke nginxtra installation, but only if the user allows it.
|
30
|
-
def install
|
31
|
-
Nginxtra::Actions::Install.new(@thor, @config).optional_install
|
32
|
-
end
|
33
|
-
|
34
28
|
# Save nginx config files to the proper config file path.
|
35
29
|
def save_config_files
|
36
30
|
files = @config.files
|
data/lib/nginxtra/cli.rb
CHANGED
@@ -26,7 +26,7 @@ module Nginxtra
|
|
26
26
|
nginxtra.conf.rb). The result will be output to nginxtra.conf.rb in the current
|
27
27
|
directory, unless an override value is specified with the --config option."
|
28
28
|
method_option "nginx-bin", :type => :string, :banner => "Point to the compiled nginx to retrieve compile options", :aliases => "-n"
|
29
|
-
method_option "nginx-conf", :type => :string, :banner => "Point to the nginx.conf file to retrieve the existing configuration", :aliases => "-", :default => "nginx.conf"
|
29
|
+
method_option "nginx-conf", :type => :string, :banner => "Point to the nginx.conf file to retrieve the existing configuration", :aliases => "-F", :default => "nginx.conf"
|
30
30
|
method_option "ignore-nginx-bin", :type => :boolean, :banner => "Ignore the nginx binary, and assume default compile time options", :aliases => "-N"
|
31
31
|
method_option "output", :type => :boolean, :banner => "Output to standard out instead of to a file", :aliases => "-o"
|
32
32
|
method_option "input", :type => :boolean, :banner => "Read nginx.conf from standard in instead of a file", :aliases => "-i"
|
@@ -36,6 +36,22 @@ module Nginxtra
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
+
desc "print", "Output nginxtra.conf.rb as it is processed as nginx.conf"
|
40
|
+
long_desc "
|
41
|
+
Output the contents of nginx.conf, as it is defined in nginxtra.conf.rb. If the
|
42
|
+
--file is provided, something other than nginx.conf can be output. The --list
|
43
|
+
option can be provided to list known config files. The --compile-options option
|
44
|
+
can be provided to list compile time options being passed to nginx."
|
45
|
+
method_option "compile-options", :type => :boolean, :banner => "Show compile options being used", :aliases => "-C"
|
46
|
+
method_option "file", :type => :string, :banner => "The config file that is printed", :aliases => "-F", :default => "nginx.conf"
|
47
|
+
method_option "list", :type => :boolean, :banner => "List known files", :aliases => "-l"
|
48
|
+
def print
|
49
|
+
Nginxtra::Error.protect self do
|
50
|
+
set_working_dir!
|
51
|
+
Nginxtra::Actions::Print.new(self, prepare_config!).print
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
39
55
|
desc "compile", "Compiles nginx based on nginxtra.conf.rb"
|
40
56
|
long_desc "
|
41
57
|
Compile nginx with the compilation options specified in nginxtra.conf.rb. If it
|
@@ -66,12 +82,11 @@ module Nginxtra
|
|
66
82
|
long_desc "
|
67
83
|
Start nginx based on nginxtra.conf.rb. If nginx has not yet been compiled for
|
68
84
|
the given compilation options or the current nginx version, it will be compiled.
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
compile or install task should be invoked if those need to be forced."
|
85
|
+
The configuration for nginx will automatically be handled by nginxtra so it
|
86
|
+
matches what is defined in nginxtra.conf.rb. If it is already running, this
|
87
|
+
will do nothing, unless --force is passed. Note that compilation will NOT be
|
88
|
+
forced with the --force option and should be invoked separately if it needs to
|
89
|
+
be forced."
|
75
90
|
def start
|
76
91
|
Nginxtra::Error.protect self do
|
77
92
|
set_working_dir!
|
@@ -136,8 +151,6 @@ module Nginxtra
|
|
136
151
|
def set_working_dir!
|
137
152
|
if options["workingdir"]
|
138
153
|
Dir.chdir options["workingdir"]
|
139
|
-
elsif Nginxtra::Status[:remembered_workingdir]
|
140
|
-
Dir.chdir Nginxtra::Status[:remembered_workingdir]
|
141
154
|
end
|
142
155
|
end
|
143
156
|
|
data/lib/nginxtra/config.rb
CHANGED
@@ -168,6 +168,11 @@ module Nginxtra
|
|
168
168
|
# returned.
|
169
169
|
def path
|
170
170
|
path = File.absolute_path "."
|
171
|
+
config = File.join path, FILENAME
|
172
|
+
return config if File.exists? config
|
173
|
+
config = File.join path, "config", FILENAME
|
174
|
+
return config if File.exists? config
|
175
|
+
path = File.dirname path
|
171
176
|
|
172
177
|
begin
|
173
178
|
config = File.join path, FILENAME
|
@@ -191,8 +196,6 @@ module Nginxtra
|
|
191
196
|
def require!(config_path = nil)
|
192
197
|
if config_path
|
193
198
|
config_path = File.absolute_path config_path
|
194
|
-
elsif Nginxtra::Status[:remembered_config]
|
195
|
-
config_path = File.absolute_path Nginxtra::Status[:remembered_config]
|
196
199
|
else
|
197
200
|
config_path = path
|
198
201
|
end
|
@@ -310,6 +313,56 @@ module Nginxtra
|
|
310
313
|
end
|
311
314
|
end
|
312
315
|
|
316
|
+
# Extension point for other gems or libraries that want to define
|
317
|
+
# inline partials. Please see the partial method for usage.
|
318
|
+
class Extension
|
319
|
+
class << self
|
320
|
+
# Determine if there has been a partial defined for the given
|
321
|
+
# nginx config file, with the given partial name.
|
322
|
+
def partial?(file, name)
|
323
|
+
file = file.to_sym
|
324
|
+
name = name.to_sym
|
325
|
+
@extensions && @extensions[file] && @extensions[file][name]
|
326
|
+
end
|
327
|
+
|
328
|
+
# Define or retrieve the partial for the given nginx config
|
329
|
+
# file and partial name. If a block is provided, it is set as
|
330
|
+
# the partial, otherwise the partial currently defined for it
|
331
|
+
# will be retrieved. The block is expected to take 2
|
332
|
+
# arguments... the arguments hash, and then the block passed
|
333
|
+
# in to this definition. Either may be ignored if so desired.
|
334
|
+
#
|
335
|
+
# Example usage:
|
336
|
+
# Nginxtra::Config::Extension.partial "nginx.conf", "my_app" do |args, block|
|
337
|
+
# my_app(args[:port] || 80)
|
338
|
+
# some_other_setting "on"
|
339
|
+
# block.call
|
340
|
+
# end
|
341
|
+
#
|
342
|
+
# The partial will only be valid for the given config file.
|
343
|
+
# It is completely nestable, and other partials may be invoked
|
344
|
+
# as well.
|
345
|
+
def partial(file, name, &block)
|
346
|
+
file = file.to_sym
|
347
|
+
name = name.to_sym
|
348
|
+
@extensions ||= {}
|
349
|
+
@extensions[file] ||= {}
|
350
|
+
|
351
|
+
if block
|
352
|
+
@extensions[file][name] = block
|
353
|
+
else
|
354
|
+
@extensions[file][name]
|
355
|
+
end
|
356
|
+
end
|
357
|
+
|
358
|
+
# Clear all partials so far defined. This is mainly for test,
|
359
|
+
# but could be called if resetting is so desired.
|
360
|
+
def clear_partials!
|
361
|
+
@extensions = {}
|
362
|
+
end
|
363
|
+
end
|
364
|
+
end
|
365
|
+
|
313
366
|
# Represents a config file being defined by nginxtra.conf.rb.
|
314
367
|
class ConfigFile
|
315
368
|
def initialize(filename, config, &block)
|
@@ -385,15 +438,51 @@ module Nginxtra
|
|
385
438
|
@end_of_block = true
|
386
439
|
end
|
387
440
|
|
441
|
+
# Convenience method to use the "break" keyword, as seen in if
|
442
|
+
# blocks of nginx configurations.
|
443
|
+
def _break(*args, &block)
|
444
|
+
process_config_block_or_line "break", args, block
|
445
|
+
end
|
446
|
+
|
447
|
+
# Convenience method to invoke an if block in the nginx
|
448
|
+
# configuration. Parenthesis are added around the arguments of
|
449
|
+
# this method.
|
450
|
+
#
|
451
|
+
# Example usage:
|
452
|
+
# nginxtra.config do
|
453
|
+
# _if "some", "~", "thing" do
|
454
|
+
# _return 404
|
455
|
+
# end
|
456
|
+
# end
|
457
|
+
#
|
458
|
+
# Which will produce the following config:
|
459
|
+
# if (some ~ thing) {
|
460
|
+
# return 404;
|
461
|
+
# }
|
462
|
+
def _if(*args, &block)
|
463
|
+
config_block "if (#{args.join " "})", &block
|
464
|
+
end
|
465
|
+
|
466
|
+
# Convenience method to use the "return" keyword, as seen in if
|
467
|
+
# blocks of nginx configurations.
|
468
|
+
def _return(*args, &block)
|
469
|
+
process_config_block_or_line "return", args, block
|
470
|
+
end
|
471
|
+
|
388
472
|
# Process the given template. Optionally, include options (as
|
389
473
|
# yielded values) available to the template. The yielder passed
|
390
474
|
# in will be invoked (if given) if the template invokes yield.
|
391
475
|
def process_template!(template, options = {}, yielder = nil)
|
392
|
-
|
393
|
-
if
|
394
|
-
|
395
|
-
|
396
|
-
|
476
|
+
if template.respond_to? :call
|
477
|
+
block = Proc.new { instance_eval &yielder if yielder }
|
478
|
+
instance_exec options, block, &template
|
479
|
+
else
|
480
|
+
process_template_with_yields! template do |x|
|
481
|
+
if x
|
482
|
+
options[x.to_sym]
|
483
|
+
else
|
484
|
+
instance_eval &yielder if yielder
|
485
|
+
end
|
397
486
|
end
|
398
487
|
end
|
399
488
|
end
|
@@ -444,16 +533,22 @@ module Nginxtra
|
|
444
533
|
|
445
534
|
private
|
446
535
|
def partial?(partial_name)
|
536
|
+
return true if Nginxtra::Config::Extension.partial? @filename, partial_name
|
537
|
+
|
447
538
|
@config.partial_paths.any? do |path|
|
448
539
|
File.exists? File.join(path, "#{@filename}/#{partial_name}.rb")
|
449
540
|
end
|
450
541
|
end
|
451
542
|
|
452
543
|
def invoke_partial(partial_name, args, block)
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
544
|
+
if Nginxtra::Config::Extension.partial? @filename, partial_name
|
545
|
+
partial_path = Nginxtra::Config::Extension.partial @filename, partial_name
|
546
|
+
else
|
547
|
+
partial_path = @config.partial_paths.map do |path|
|
548
|
+
File.join path, "#{@filename}/#{partial_name}.rb"
|
549
|
+
end.find do |path|
|
550
|
+
File.exists? path
|
551
|
+
end
|
457
552
|
end
|
458
553
|
|
459
554
|
if args.empty?
|
@@ -114,6 +114,7 @@ module Nginxtra
|
|
114
114
|
end
|
115
115
|
|
116
116
|
class Token
|
117
|
+
KEYWORDS = ["break", "if", "return"].freeze
|
117
118
|
TERMINAL_CHARACTERS = ["{", "}", ";"].freeze
|
118
119
|
attr_reader :value
|
119
120
|
|
@@ -123,6 +124,18 @@ module Nginxtra
|
|
123
124
|
@ready = false
|
124
125
|
end
|
125
126
|
|
127
|
+
def is_if?
|
128
|
+
@value == "if"
|
129
|
+
end
|
130
|
+
|
131
|
+
def if_start!
|
132
|
+
@value.gsub! /^\(/, ""
|
133
|
+
end
|
134
|
+
|
135
|
+
def if_end!
|
136
|
+
@value.gsub! /\)$/, ""
|
137
|
+
end
|
138
|
+
|
126
139
|
def terminal_character?
|
127
140
|
TERMINAL_CHARACTERS.include? @value
|
128
141
|
end
|
@@ -156,11 +169,19 @@ module Nginxtra
|
|
156
169
|
@instance || @ready || terminal_character?
|
157
170
|
end
|
158
171
|
|
172
|
+
def to_line_start
|
173
|
+
if KEYWORDS.include? @value
|
174
|
+
"_#{@value}"
|
175
|
+
else
|
176
|
+
@value
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
159
180
|
def to_s
|
160
181
|
if @value =~ /^\d+$/
|
161
182
|
@value
|
162
183
|
else
|
163
|
-
%{"#{@value}"}
|
184
|
+
%{"#{@value.gsub("\\") { "\\\\" }}"}
|
164
185
|
end
|
165
186
|
end
|
166
187
|
|
@@ -224,6 +245,10 @@ module Nginxtra
|
|
224
245
|
end
|
225
246
|
|
226
247
|
private
|
248
|
+
def is_if?
|
249
|
+
@tokens.first.is_if?
|
250
|
+
end
|
251
|
+
|
227
252
|
def passenger?
|
228
253
|
["passenger_root", "passenger_ruby", "passenger_enabled"].include? @tokens.first.value
|
229
254
|
end
|
@@ -272,13 +297,19 @@ module Nginxtra
|
|
272
297
|
end
|
273
298
|
|
274
299
|
def print_first
|
275
|
-
@output.print @tokens.first.
|
300
|
+
@output.print @tokens.first.to_line_start
|
276
301
|
end
|
277
302
|
|
278
303
|
def print_args
|
279
304
|
args = @tokens[1..-2]
|
280
305
|
return if args.empty?
|
281
306
|
@output.print " "
|
307
|
+
|
308
|
+
if is_if?
|
309
|
+
args.first.if_start!
|
310
|
+
args.last.if_end!
|
311
|
+
end
|
312
|
+
|
282
313
|
@output.print args.map(&:to_s).join(", ")
|
283
314
|
end
|
284
315
|
|
data/lib/nginxtra/version.rb
CHANGED
metadata
CHANGED
@@ -1,38 +1,41 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: nginxtra
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.6.8
|
4
5
|
prerelease:
|
5
|
-
version: 1.2.6.7
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Mike Virata-Stone
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2013-02-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
16
15
|
name: thor
|
17
|
-
|
18
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
19
17
|
none: false
|
20
|
-
requirements:
|
18
|
+
requirements:
|
21
19
|
- - ~>
|
22
|
-
- !ruby/object:Gem::Version
|
20
|
+
- !ruby/object:Gem::Version
|
23
21
|
version: 0.16.0
|
24
22
|
type: :runtime
|
25
|
-
|
26
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.16.0
|
30
|
+
description: This gem is intended to provide an easy to use configuration file that
|
31
|
+
will automatically be used to compile nginx and configure the configuration.
|
27
32
|
email: reasonnumber@gmail.com
|
28
|
-
executables:
|
33
|
+
executables:
|
29
34
|
- nginxtra
|
30
35
|
- nginxtra_rails
|
31
36
|
extensions: []
|
32
|
-
|
33
37
|
extra_rdoc_files: []
|
34
|
-
|
35
|
-
files:
|
38
|
+
files:
|
36
39
|
- bin/nginxtra
|
37
40
|
- bin/nginxtra_rails
|
38
41
|
- lib/nginxtra.rb
|
@@ -40,6 +43,7 @@ files:
|
|
40
43
|
- lib/nginxtra/actions/compile.rb
|
41
44
|
- lib/nginxtra/actions/convert.rb
|
42
45
|
- lib/nginxtra/actions/install.rb
|
46
|
+
- lib/nginxtra/actions/print.rb
|
43
47
|
- lib/nginxtra/actions/rails/server.rb
|
44
48
|
- lib/nginxtra/actions/reload.rb
|
45
49
|
- lib/nginxtra/actions/restart.rb
|
@@ -411,30 +415,26 @@ files:
|
|
411
415
|
- vendor/nginx/src/os/unix/rfork_thread.S
|
412
416
|
homepage: http://reasonnumber.com/nginxtra
|
413
417
|
licenses: []
|
414
|
-
|
415
418
|
post_install_message:
|
416
419
|
rdoc_options: []
|
417
|
-
|
418
|
-
require_paths:
|
420
|
+
require_paths:
|
419
421
|
- lib
|
420
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
422
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
421
423
|
none: false
|
422
|
-
requirements:
|
423
|
-
- -
|
424
|
-
- !ruby/object:Gem::Version
|
425
|
-
version:
|
426
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
424
|
+
requirements:
|
425
|
+
- - ! '>='
|
426
|
+
- !ruby/object:Gem::Version
|
427
|
+
version: '0'
|
428
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
427
429
|
none: false
|
428
|
-
requirements:
|
429
|
-
- -
|
430
|
-
- !ruby/object:Gem::Version
|
431
|
-
version:
|
430
|
+
requirements:
|
431
|
+
- - ! '>='
|
432
|
+
- !ruby/object:Gem::Version
|
433
|
+
version: '0'
|
432
434
|
requirements: []
|
433
|
-
|
434
435
|
rubyforge_project:
|
435
436
|
rubygems_version: 1.8.24
|
436
437
|
signing_key:
|
437
438
|
specification_version: 3
|
438
439
|
summary: Wrapper of nginx for easy install and use.
|
439
440
|
test_files: []
|
440
|
-
|