nginxtra 1.2.1.2 → 1.2.1.3
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.
- data/VERSION +1 -1
- data/bin/nginxtra +1 -1
- data/lib/nginxtra/actions/convert.rb +12 -4
- data/lib/nginxtra/actions/install.rb +16 -4
- data/lib/nginxtra/actions/start.rb +1 -1
- data/lib/nginxtra/cli.rb +26 -8
- data/lib/nginxtra/config.rb +177 -12
- data/lib/nginxtra/config_converter.rb +2 -28
- data/lib/nginxtra/error.rb +41 -5
- data/lib/nginxtra/status.rb +4 -2
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.1.
|
1
|
+
1.2.1.3
|
data/bin/nginxtra
CHANGED
@@ -44,15 +44,23 @@ module Nginxtra
|
|
44
44
|
return if @thor.options["ignore-nginx-bin"]
|
45
45
|
|
46
46
|
if @thor.options["nginx-bin"]
|
47
|
-
|
47
|
+
binary = @thor.options["nginx-bin"]
|
48
48
|
else
|
49
|
-
|
50
|
-
raise "The auto detection of nginx binary is not yet implemented. Please use the --nginx-bin option for now."
|
49
|
+
binary = etc_nginx_binary
|
51
50
|
end
|
51
|
+
|
52
|
+
@thor.run "#{binary} -V 2>&1", :capture => true
|
53
|
+
end
|
54
|
+
|
55
|
+
def etc_nginx_binary
|
56
|
+
raise Nginxtra::Error::ConvertFailed.new("Cannot find nginx binary", :header => "Cannot find nginx binary!", :message => "Either point to it via --nginx-bin or ignore the binary with --ignore-nginx-bin") unless File.exists? "/etc/init.d/nginx"
|
57
|
+
binary = File.read("/etc/init.d/nginx")[/\s*DAEMON\s*=\s*(.*?)\s*$/, 1]
|
58
|
+
raise Nginxtra::Error::ConvertFailed.new("Cannot determine nginx binary", :header => "Cannot find nginx binary!", :message => "The binary location of nginx cannot be determined from /etc/init.d/nginx. Either point to it via --nginx-bin or ignore the binary with --ignore-nginx-bin") unless binary
|
59
|
+
binary
|
52
60
|
end
|
53
61
|
|
54
62
|
def open_file(path)
|
55
|
-
raise "Missing config file #{path}" unless File.exists? path
|
63
|
+
raise Nginxtra::Error::ConvertFailed.new("Missing config file #{path}") unless File.exists? path
|
56
64
|
|
57
65
|
File.open(path, "r").tap do |stream|
|
58
66
|
@streams_to_close << stream
|
@@ -11,9 +11,6 @@ module Nginxtra
|
|
11
11
|
# if run with --non-interactive mode.
|
12
12
|
def optional_install
|
13
13
|
return installation_skipped if non_interactive?
|
14
|
-
# TODO: Raise an error if nginx is determined to be installed
|
15
|
-
# (via /etc/init.d/nginx perhaps... but allow ignoring this
|
16
|
-
# check).
|
17
14
|
return up_to_date unless should_install?
|
18
15
|
return unless requesting_install?
|
19
16
|
install
|
@@ -22,11 +19,25 @@ module Nginxtra
|
|
22
19
|
# Run the installation of nginxtra.
|
23
20
|
def install
|
24
21
|
return up_to_date unless should_install?
|
22
|
+
check_if_nginx_is_installed
|
25
23
|
create_etc_script
|
26
24
|
remember_config_location
|
27
25
|
update_last_install
|
28
26
|
end
|
29
27
|
|
28
|
+
# Look for nginx installation and fail if it exists (unless
|
29
|
+
# --ignore-nginx-check is passed).
|
30
|
+
def check_if_nginx_is_installed
|
31
|
+
return unless File.exists?("/etc/init.d/nginx")
|
32
|
+
|
33
|
+
if @thor.options["ignore-nginx-check"]
|
34
|
+
@thor.say @thor.set_color("Detected nginx install, but ignoring!", :red, true)
|
35
|
+
return
|
36
|
+
end
|
37
|
+
|
38
|
+
raise Nginxtra::Error::NginxDetected.new("Uninstall nginx before installing nginxtra", :header => "It appears nginx is already installed!", :message => "Since /etc/init.d/nginx exists, you might have an existing nginx installation that will conflict with nginxtra. If you want to install nginxtra alongside nginx (at your own risk), please include the --ignore-nginx-check option to bypass this check.")
|
39
|
+
end
|
40
|
+
|
30
41
|
# Create a script in the base directory which be symlinked to
|
31
42
|
# /etc/init.d/nginxtra and then used to start and stop nginxtra
|
32
43
|
# via update-rc.d.
|
@@ -53,7 +64,8 @@ export GEM_PATH="#{ENV["GEM_PATH"]}"
|
|
53
64
|
@thor.chmod filename, 0755
|
54
65
|
end
|
55
66
|
|
56
|
-
run! %{#{sudo true}rm /etc/init.d/nginxtra
|
67
|
+
run! %{#{sudo true}rm /etc/init.d/nginxtra} if File.exists? "/etc/init.d/nginxtra"
|
68
|
+
run! %{#{sudo true}ln -s "#{File.join Nginxtra::Config.base_dir, filename}" /etc/init.d/nginxtra}
|
57
69
|
run! %{#{sudo true}update-rc.d nginxtra defaults}
|
58
70
|
end
|
59
71
|
|
@@ -34,7 +34,7 @@ module Nginxtra
|
|
34
34
|
# Save nginx config files to the proper config file path.
|
35
35
|
def save_config_files
|
36
36
|
files = @config.files
|
37
|
-
raise Nginxtra::Error::InvalidConfig.new("Missing definition for nginx.conf") unless files.include? "nginx.conf"
|
37
|
+
raise Nginxtra::Error::InvalidConfig.new("Missing definition for nginx.conf", :header => "Missing definition for nginx.conf!", :message => "You must define your nginx.conf configuration in your nginxtra.conf.rb file.") unless files.include? "nginx.conf"
|
38
38
|
|
39
39
|
@thor.inside Nginxtra::Config.config_dir do
|
40
40
|
files.each do |filename|
|
data/lib/nginxtra/cli.rb
CHANGED
@@ -5,7 +5,9 @@ module Nginxtra
|
|
5
5
|
include Thor::Actions
|
6
6
|
|
7
7
|
class_option "force", :type => :boolean, :banner => "Force a task to happen, regardless of what nginxtra thinks", :aliases => "-f"
|
8
|
+
class_option "trace", :type => :boolean, :banner => "Output stack traces on error"
|
8
9
|
class_option "non-interactive", :type => :boolean, :banner => "If nginxtra would ask a question, it instead proceeds as if 'no' were the answer", :aliases => "-I"
|
10
|
+
class_option "ignore-nginx-check", :type => :boolean, :banner => "Ignore the nginx check if installing"
|
9
11
|
class_option "config", :type => :string, :banner => "Specify the configuration file to use", :aliases => "-c"
|
10
12
|
class_option "basedir", :type => :string, :banner => "Specify the directory to store nginx files", :aliases => "-b"
|
11
13
|
|
@@ -26,7 +28,9 @@ module Nginxtra
|
|
26
28
|
method_option "output", :type => :boolean, :banner => "Output to standard out instead of to a file", :aliases => "-o"
|
27
29
|
method_option "input", :type => :boolean, :banner => "Read nginx.conf from standard in instead of a file", :aliases => "-i"
|
28
30
|
def convert
|
29
|
-
Nginxtra::
|
31
|
+
Nginxtra::Error.protect self do
|
32
|
+
Nginxtra::Actions::Convert.new(self, nil).convert
|
33
|
+
end
|
30
34
|
end
|
31
35
|
|
32
36
|
desc "compile", "Compiles nginx based on nginxtra.conf.rb"
|
@@ -37,7 +41,9 @@ module Nginxtra
|
|
37
41
|
be executed directly. However, you can force recompilation by running this task
|
38
42
|
with the --force option."
|
39
43
|
def compile
|
40
|
-
Nginxtra::
|
44
|
+
Nginxtra::Error.protect self do
|
45
|
+
Nginxtra::Actions::Compile.new(self, prepare_config!).compile
|
46
|
+
end
|
41
47
|
end
|
42
48
|
|
43
49
|
desc "install", "Installs nginxtra"
|
@@ -47,7 +53,9 @@ module Nginxtra
|
|
47
53
|
already installed with this version of nginxtra. If it was already installed,
|
48
54
|
installation will be skipped unless the --force option is given."
|
49
55
|
def install
|
50
|
-
Nginxtra::
|
56
|
+
Nginxtra::Error.protect self do
|
57
|
+
Nginxtra::Actions::Install.new(self, prepare_config!).install
|
58
|
+
end
|
51
59
|
end
|
52
60
|
|
53
61
|
desc "start", "Start nginx with configuration defined in nginxtra.conf.rb"
|
@@ -61,7 +69,9 @@ module Nginxtra
|
|
61
69
|
compilation and installation will NOT be forced with --force option. The
|
62
70
|
compile or install task should be invoked if those need to be forced."
|
63
71
|
def start
|
64
|
-
Nginxtra::
|
72
|
+
Nginxtra::Error.protect self do
|
73
|
+
Nginxtra::Actions::Start.new(self, prepare_config!).start
|
74
|
+
end
|
65
75
|
end
|
66
76
|
|
67
77
|
desc "stop", "Stop nginx"
|
@@ -70,23 +80,31 @@ module Nginxtra
|
|
70
80
|
determined to be running, this command will do nothing, unless --force is passed
|
71
81
|
(which will cause it to run the stop command regardless of the pidfile)."
|
72
82
|
def stop
|
73
|
-
Nginxtra::
|
83
|
+
Nginxtra::Error.protect self do
|
84
|
+
Nginxtra::Actions::Stop.new(self, prepare_config!).stop
|
85
|
+
end
|
74
86
|
end
|
75
87
|
|
76
88
|
desc "restart", "Restart nginx"
|
77
89
|
def restart
|
78
|
-
Nginxtra::
|
90
|
+
Nginxtra::Error.protect self do
|
91
|
+
Nginxtra::Actions::Restart.new(self, prepare_config!).restart
|
92
|
+
end
|
79
93
|
end
|
80
94
|
map "force-reload" => "restart"
|
81
95
|
|
82
96
|
desc "reload", "Reload nginx"
|
83
97
|
def reload
|
84
|
-
Nginxtra::
|
98
|
+
Nginxtra::Error.protect self do
|
99
|
+
Nginxtra::Actions::Reload.new(self, prepare_config!).reload
|
100
|
+
end
|
85
101
|
end
|
86
102
|
|
87
103
|
desc "status", "Check if nginx is running"
|
88
104
|
def status
|
89
|
-
Nginxtra::
|
105
|
+
Nginxtra::Error.protect self do
|
106
|
+
Nginxtra::Actions::Status.new(self, prepare_config!).status
|
107
|
+
end
|
90
108
|
end
|
91
109
|
|
92
110
|
private
|
data/lib/nginxtra/config.rb
CHANGED
@@ -25,6 +25,15 @@ module Nginxtra
|
|
25
25
|
self
|
26
26
|
end
|
27
27
|
|
28
|
+
# Support simple configuration in a special block. This will
|
29
|
+
# allow wholesale configuration like for rails. It supports the
|
30
|
+
# :worker_processes and :worker_connections options, which will
|
31
|
+
# affect the resulting configuration.
|
32
|
+
def simple_config(options = {}, &block)
|
33
|
+
SimpleConfig.new(self, options, &block).process!
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
28
37
|
# Notify nginxtra that root access is needed to run the daemon
|
29
38
|
# commands. Sudo will automatically be used if the current user
|
30
39
|
# isn't root.
|
@@ -68,10 +77,10 @@ module Nginxtra
|
|
68
77
|
# end
|
69
78
|
def compile_option(opt)
|
70
79
|
opt = "--#{opt}" unless opt =~ /^--/
|
71
|
-
raise Nginxtra::Error::InvalidConfig.new("The --prefix compile option is not allowed with nginxtra. It is reserved so nginxtra can control where nginx is compiled and run from.") if opt =~ /--prefix=/
|
72
|
-
raise Nginxtra::Error::InvalidConfig.new("The --sbin-path compile option is not allowed with nginxtra. It is reserved so nginxtra can control what binary is used to run nginx.") if opt =~ /--sbin-path=/
|
73
|
-
raise Nginxtra::Error::InvalidConfig.new("The --conf-path compile option is not allowed with nginxtra. It is reserved so nginxtra can control the configuration entirely via #{Nginxtra::Config::FILENAME}.") if opt =~ /--conf-path=/
|
74
|
-
raise Nginxtra::Error::InvalidConfig.new("The --pid-path compile option is not allowed with nginxtra. It is reserved so nginxtra can control where the pid file is created.") if opt =~ /--pid-path=/
|
80
|
+
raise Nginxtra::Error::InvalidConfig.new("Invalid compilation option --prefix", :header => "Invalid compilation option --prefix", :message => "The --prefix compile option is not allowed with nginxtra. It is reserved so nginxtra can control where nginx is compiled and run from.") if opt =~ /--prefix=/
|
81
|
+
raise Nginxtra::Error::InvalidConfig.new("Invalid compilation option --sbin-path", :header => "Invalid compilation option --sbin-path", :message => "The --sbin-path compile option is not allowed with nginxtra. It is reserved so nginxtra can control what binary is used to run nginx.") if opt =~ /--sbin-path=/
|
82
|
+
raise Nginxtra::Error::InvalidConfig.new("Invalid compilation option --conf-path", :header => "Invalid compilation option --conf-path", :message => "The --conf-path compile option is not allowed with nginxtra. It is reserved so nginxtra can control the configuration entirely via #{Nginxtra::Config::FILENAME}.") if opt =~ /--conf-path=/
|
83
|
+
raise Nginxtra::Error::InvalidConfig.new("Invalid compilation option --pid-path", :header => "Invalid compilation option --pid-path", :message => "The --pid-path compile option is not allowed with nginxtra. It is reserved so nginxtra can control where the pid file is created.") if opt =~ /--pid-path=/
|
75
84
|
@compile_options << opt
|
76
85
|
end
|
77
86
|
|
@@ -84,7 +93,7 @@ module Nginxtra
|
|
84
93
|
# Define a new config file with the given filename and the block
|
85
94
|
# to define it with.
|
86
95
|
def file(filename, &block)
|
87
|
-
@files[filename] = Nginxtra::Config::ConfigFile.new(&block)
|
96
|
+
@files[filename] = Nginxtra::Config::ConfigFile.new(self, &block)
|
88
97
|
end
|
89
98
|
|
90
99
|
# Retrieve the files that have been defined.
|
@@ -194,6 +203,17 @@ module Nginxtra
|
|
194
203
|
File.join base_nginx_dir, "build"
|
195
204
|
end
|
196
205
|
|
206
|
+
# Retrieve the directory where templates are loaded from.
|
207
|
+
def template_dir
|
208
|
+
File.join base_dir, "templates"
|
209
|
+
end
|
210
|
+
|
211
|
+
# Retrieve the directory within the gem where templates are
|
212
|
+
# loaded from.
|
213
|
+
def gem_template_dir
|
214
|
+
File.join gem_dir, "templates"
|
215
|
+
end
|
216
|
+
|
197
217
|
# The path to the config directory where nginx config files are
|
198
218
|
# stored (including nginx.conf).
|
199
219
|
def config_dir
|
@@ -227,7 +247,7 @@ module Nginxtra
|
|
227
247
|
# be found.
|
228
248
|
def passenger_spec
|
229
249
|
@passenger_spec ||= Gem::Specification.find_by_name("passenger").tap do |spec|
|
230
|
-
raise InvalidConfig.new("You cannot reference passenger unless the passenger gem is installed!") if spec.nil?
|
250
|
+
raise InvalidConfig.new("Missing passenger gem", :header => "Missing passenger gem!", :message => "You cannot reference passenger unless the passenger gem is installed!") if spec.nil?
|
231
251
|
end
|
232
252
|
end
|
233
253
|
|
@@ -244,14 +264,18 @@ module Nginxtra
|
|
244
264
|
|
245
265
|
# Represents a config file being defined by nginxtra.conf.rb.
|
246
266
|
class ConfigFile
|
247
|
-
def initialize(&block)
|
267
|
+
def initialize(config, &block)
|
268
|
+
@config = config
|
269
|
+
@indentation = Nginxtra::Config::Indentation.new :indent_size => 4
|
248
270
|
@file_contents = []
|
249
271
|
instance_eval &block
|
250
272
|
end
|
251
273
|
|
252
274
|
# The file contents that were defined for this config file.
|
253
275
|
def config_file_contents
|
254
|
-
@file_contents.join "\n"
|
276
|
+
result = @file_contents.join "\n"
|
277
|
+
result += "\n" unless result.empty?
|
278
|
+
result
|
255
279
|
end
|
256
280
|
|
257
281
|
# Add a new line to the config. A semicolon is added
|
@@ -263,7 +287,8 @@ module Nginxtra
|
|
263
287
|
# config_line "worker_processes 42"
|
264
288
|
# end
|
265
289
|
def config_line(contents)
|
266
|
-
@
|
290
|
+
@begin_of_block = false
|
291
|
+
bare_config_line "#{contents};"
|
267
292
|
end
|
268
293
|
|
269
294
|
# Add a new line to the config, but without a semicolon at the
|
@@ -274,7 +299,14 @@ module Nginxtra
|
|
274
299
|
# bare_config_line "a line with no semicolon"
|
275
300
|
# end
|
276
301
|
def bare_config_line(contents)
|
277
|
-
@
|
302
|
+
@begin_of_block = false
|
303
|
+
@file_contents << "#{@indentation}#{contents}"
|
304
|
+
end
|
305
|
+
|
306
|
+
# Add an empty config line to the resulting config file.
|
307
|
+
def empty_config_line
|
308
|
+
@begin_of_block = false
|
309
|
+
@file_contents << ""
|
278
310
|
end
|
279
311
|
|
280
312
|
# Add a new block to the config. This will result in outputting
|
@@ -290,9 +322,32 @@ module Nginxtra
|
|
290
322
|
# end
|
291
323
|
# end
|
292
324
|
def config_block(name)
|
293
|
-
@file_contents
|
325
|
+
empty_config_line unless @file_contents.empty? || @begin_of_block
|
326
|
+
bare_config_line "#{name} {"
|
327
|
+
@begin_of_block = true
|
328
|
+
@indentation + 1
|
294
329
|
yield if block_given?
|
295
|
-
@
|
330
|
+
@indentation - 1
|
331
|
+
bare_config_line "}"
|
332
|
+
end
|
333
|
+
|
334
|
+
# Process the given template. Optionally, include options (as
|
335
|
+
# yielded values) available to the template. The yielder passed
|
336
|
+
# in will be invoked (if given) if the template invokes yield.
|
337
|
+
def process_template!(template, options = {}, yielder = nil)
|
338
|
+
process_template_with_yields! template do |x|
|
339
|
+
if x
|
340
|
+
options[x.to_sym]
|
341
|
+
else
|
342
|
+
instance_eval &yielder if yielder
|
343
|
+
end
|
344
|
+
end
|
345
|
+
end
|
346
|
+
|
347
|
+
# Helper method for process_template! Which is expected to have
|
348
|
+
# a block passed in to handle yields from within the template.
|
349
|
+
def process_template_with_yields!(template)
|
350
|
+
instance_eval File.read(template)
|
296
351
|
end
|
297
352
|
|
298
353
|
# Arbitrary config can be specified as long as the name doesn't
|
@@ -335,6 +390,116 @@ module Nginxtra
|
|
335
390
|
config_line %{passenger_enabled on}
|
336
391
|
end
|
337
392
|
end
|
393
|
+
|
394
|
+
# A class for encapsulating simple configuration.
|
395
|
+
class SimpleConfig
|
396
|
+
def initialize(config, options = {}, &block)
|
397
|
+
@config = config
|
398
|
+
@options = options
|
399
|
+
@invoked_partials = []
|
400
|
+
instance_eval &block
|
401
|
+
end
|
402
|
+
|
403
|
+
# Process the simple config.
|
404
|
+
def process!
|
405
|
+
gem_files = find_config_files! File.join(Nginxtra::Config.gem_template_dir, "files")
|
406
|
+
override_files = find_config_files! File.join(Nginxtra::Config.template_dir, "files")
|
407
|
+
|
408
|
+
config_files = (gem_files.keys + override_files.keys).uniq.map do |x|
|
409
|
+
override_files[x] || gem_files[x]
|
410
|
+
end
|
411
|
+
|
412
|
+
process_files! config_files
|
413
|
+
end
|
414
|
+
|
415
|
+
# Find all the config files at the given path directory. The
|
416
|
+
# result will be a hash of hashes. The key on the outer hash is
|
417
|
+
# the output config file name, while the value is a hash of
|
418
|
+
# :path to the original file path, and :config_file to the
|
419
|
+
# output config file name.
|
420
|
+
def find_config_files!(path)
|
421
|
+
files_hash = {}
|
422
|
+
|
423
|
+
Dir["#{path}/**/*.rb"].select do |x|
|
424
|
+
File.file? x
|
425
|
+
end.map do |x|
|
426
|
+
file_name = x.sub /^#{Regexp.quote "#{path}"}\/(.*)\.rb$/, "\\1"
|
427
|
+
{ :path => x, :config_file => file_name }
|
428
|
+
end.each do |x|
|
429
|
+
files_hash[x[:config_file]] = x
|
430
|
+
end
|
431
|
+
|
432
|
+
files_hash
|
433
|
+
end
|
434
|
+
|
435
|
+
# Process all config files passed in, where each is a hash with
|
436
|
+
# :path to the original path of the file, and :config_file to
|
437
|
+
# the output config file name.
|
438
|
+
def process_files!(files)
|
439
|
+
files.each do |x|
|
440
|
+
path = x[:path]
|
441
|
+
file_name = x[:config_file]
|
442
|
+
options = @options
|
443
|
+
invoked_partials = @invoked_partials
|
444
|
+
|
445
|
+
yielder = proc do
|
446
|
+
invoked_partials.each do |partial|
|
447
|
+
method, args, block = partial
|
448
|
+
partial_end_path = "partials/#{file_name}/#{method}.rb"
|
449
|
+
partial_path = File.join Nginxtra::Config.gem_template_dir, partial_end_path
|
450
|
+
override_partial_path = File.join Nginxtra::Config.template_dir, partial_end_path
|
451
|
+
partial_options = {}
|
452
|
+
partial_options = args.first if args.length > 0 && args.first.kind_of?(Hash)
|
453
|
+
|
454
|
+
if File.exists? override_partial_path
|
455
|
+
process_template! override_partial_path, partial_options
|
456
|
+
elsif File.exists? partial_path
|
457
|
+
process_template! partial_path, partial_options
|
458
|
+
end
|
459
|
+
end
|
460
|
+
end
|
461
|
+
|
462
|
+
@config.file file_name do
|
463
|
+
process_template! path, options, yielder
|
464
|
+
end
|
465
|
+
end
|
466
|
+
end
|
467
|
+
|
468
|
+
def method_missing(method, *args, &block)
|
469
|
+
@invoked_partials << [method, args, block]
|
470
|
+
end
|
471
|
+
end
|
472
|
+
|
473
|
+
class Indentation
|
474
|
+
attr_reader :value
|
475
|
+
|
476
|
+
def initialize(options = {})
|
477
|
+
@value = 0
|
478
|
+
@options = options
|
479
|
+
end
|
480
|
+
|
481
|
+
def indent_size
|
482
|
+
@options[:indent_size] || 2
|
483
|
+
end
|
484
|
+
|
485
|
+
def done?
|
486
|
+
@value == 0
|
487
|
+
end
|
488
|
+
|
489
|
+
def -(amount)
|
490
|
+
self + (-amount)
|
491
|
+
end
|
492
|
+
|
493
|
+
def +(amount)
|
494
|
+
@value += amount
|
495
|
+
raise Nginxtra::Error::ConvertFailed.new("Missing block end!") if @value < 0
|
496
|
+
@value
|
497
|
+
end
|
498
|
+
|
499
|
+
def to_s
|
500
|
+
" " * indent_size * @value
|
501
|
+
end
|
502
|
+
end
|
338
503
|
end
|
339
504
|
end
|
340
505
|
|
@@ -3,7 +3,7 @@ module Nginxtra
|
|
3
3
|
def initialize(output)
|
4
4
|
@converted = false
|
5
5
|
@output = output
|
6
|
-
@indentation = Nginxtra::
|
6
|
+
@indentation = Nginxtra::Config::Indentation.new
|
7
7
|
end
|
8
8
|
|
9
9
|
def convert(options)
|
@@ -229,7 +229,7 @@ module Nginxtra
|
|
229
229
|
end
|
230
230
|
|
231
231
|
def puts_line
|
232
|
-
raise Nginxtra::Error::ConvertFailed.new("
|
232
|
+
raise Nginxtra::Error::ConvertFailed.new("Line must have a first label!") unless @tokens.length > 1
|
233
233
|
return puts_passenger if passenger?
|
234
234
|
print_indentation
|
235
235
|
print_first
|
@@ -294,31 +294,5 @@ module Nginxtra
|
|
294
294
|
@indentation - 1
|
295
295
|
end
|
296
296
|
end
|
297
|
-
|
298
|
-
class Indentation
|
299
|
-
attr_reader :value
|
300
|
-
|
301
|
-
def initialize
|
302
|
-
@value = 0
|
303
|
-
end
|
304
|
-
|
305
|
-
def done?
|
306
|
-
@value == 0
|
307
|
-
end
|
308
|
-
|
309
|
-
def -(amount)
|
310
|
-
self + (-amount)
|
311
|
-
end
|
312
|
-
|
313
|
-
def +(amount)
|
314
|
-
@value += amount
|
315
|
-
raise Nginxtra::Error::ConvertFailed.new("Missing block end!") if @value < 0
|
316
|
-
@value
|
317
|
-
end
|
318
|
-
|
319
|
-
def to_s
|
320
|
-
" " * @value
|
321
|
-
end
|
322
|
-
end
|
323
297
|
end
|
324
298
|
end
|
data/lib/nginxtra/error.rb
CHANGED
@@ -1,16 +1,52 @@
|
|
1
1
|
module Nginxtra
|
2
2
|
module Error
|
3
|
+
# Base error with all the base functionality.
|
4
|
+
class Base < StandardError
|
5
|
+
def initialize(message, options = nil)
|
6
|
+
@options = options
|
7
|
+
super(message)
|
8
|
+
end
|
9
|
+
|
10
|
+
def output(thor)
|
11
|
+
options = @options || { :header => message }
|
12
|
+
Nginxtra::Error.print_error thor, options
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Raised if config conversion fails
|
17
|
+
class ConvertFailed < Nginxtra::Error::Base; end
|
18
|
+
|
3
19
|
# Raised when an invalid configuration is specified, such as the
|
4
20
|
# --prefix compile option.
|
5
|
-
class InvalidConfig <
|
21
|
+
class InvalidConfig < Nginxtra::Error::Base; end
|
6
22
|
|
7
23
|
# Raised when the config file cannot be found.
|
8
|
-
class MissingConfig <
|
24
|
+
class MissingConfig < Nginxtra::Error::Base; end
|
25
|
+
|
26
|
+
# Raised when installing and nginx is detected to be installed.
|
27
|
+
class NginxDetected < Nginxtra::Error::Base; end
|
9
28
|
|
10
29
|
# Raised when a run command fails
|
11
|
-
class RunFailed <
|
30
|
+
class RunFailed < Nginxtra::Error::Base; end
|
12
31
|
|
13
|
-
|
14
|
-
|
32
|
+
class << self
|
33
|
+
def print_error(thor, options)
|
34
|
+
text = "" << thor.set_color(options[:header], :red, true)
|
35
|
+
text << "\n\n" << thor.set_color(options[:message], :red, false) if options[:message]
|
36
|
+
thor.print_wrapped text
|
37
|
+
end
|
38
|
+
|
39
|
+
def protect(thor)
|
40
|
+
begin
|
41
|
+
yield
|
42
|
+
rescue Nginxtra::Error::Base => e
|
43
|
+
e.output thor
|
44
|
+
raise if thor.options["trace"]
|
45
|
+
rescue => e
|
46
|
+
print_error thor, :header => "An unexpected error occurred!"
|
47
|
+
raise if thor.options["trace"]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
15
51
|
end
|
16
52
|
end
|
data/lib/nginxtra/status.rb
CHANGED
@@ -37,7 +37,7 @@ module Nginxtra
|
|
37
37
|
return if @@status
|
38
38
|
|
39
39
|
if File.exists? path
|
40
|
-
@@status = YAML.load File.read
|
40
|
+
@@status = YAML.load File.read(path)
|
41
41
|
else
|
42
42
|
@@status = {}
|
43
43
|
end
|
@@ -50,7 +50,9 @@ module Nginxtra
|
|
50
50
|
|
51
51
|
# Save the current state to disk.
|
52
52
|
def save!
|
53
|
-
File.
|
53
|
+
File.open path, "w" do |file|
|
54
|
+
file << YAML.dump(@@status)
|
55
|
+
end
|
54
56
|
end
|
55
57
|
end
|
56
58
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nginxtra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.1.
|
4
|
+
version: 1.2.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
16
|
-
requirement: &
|
16
|
+
requirement: &10532080 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: 0.15.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *10532080
|
25
25
|
description: This gem is intended to provide an easy to use configuration file that
|
26
26
|
will automatically be used to compile nginx and configure the configuration.
|
27
27
|
email: reasonnumber@gmail.com
|