nginxtra 1.2.0.1 → 1.2.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/VERSION +1 -1
  2. data/bin/nginxtra +1 -1
  3. data/lib/nginxtra.rb +2 -0
  4. data/lib/nginxtra/action.rb +1 -1
  5. data/lib/nginxtra/actions/convert.rb +67 -0
  6. data/lib/nginxtra/actions/install.rb +3 -0
  7. data/lib/nginxtra/cli.rb +20 -0
  8. data/lib/nginxtra/config_converter.rb +324 -0
  9. data/lib/nginxtra/error.rb +3 -0
  10. data/src/nginx/CHANGES +45 -0
  11. data/src/nginx/CHANGES.ru +46 -0
  12. data/src/nginx/src/core/nginx.h +2 -2
  13. data/src/nginx/src/core/ngx_resolver.c +14 -2
  14. data/src/nginx/src/event/ngx_event.c +18 -21
  15. data/src/nginx/src/event/ngx_event.h +0 -6
  16. data/src/nginx/src/event/ngx_event_accept.c +90 -13
  17. data/src/nginx/src/event/ngx_event_openssl.c +1 -0
  18. data/src/nginx/src/http/modules/ngx_http_fastcgi_module.c +26 -4
  19. data/src/nginx/src/http/modules/ngx_http_flv_module.c +1 -1
  20. data/src/nginx/src/http/modules/ngx_http_geo_module.c +62 -74
  21. data/src/nginx/src/http/modules/ngx_http_geoip_module.c +130 -30
  22. data/src/nginx/src/http/modules/ngx_http_gzip_static_module.c +1 -1
  23. data/src/nginx/src/http/modules/ngx_http_mp4_module.c +1 -1
  24. data/src/nginx/src/http/modules/ngx_http_realip_module.c +45 -93
  25. data/src/nginx/src/http/modules/ngx_http_scgi_module.c +2 -0
  26. data/src/nginx/src/http/modules/ngx_http_stub_status_module.c +1 -1
  27. data/src/nginx/src/http/modules/ngx_http_uwsgi_module.c +2 -0
  28. data/src/nginx/src/http/modules/perl/nginx.pm +1 -1
  29. data/src/nginx/src/http/ngx_http_core_module.c +104 -0
  30. data/src/nginx/src/http/ngx_http_core_module.h +3 -0
  31. data/src/nginx/src/http/ngx_http_parse.c +20 -0
  32. data/src/nginx/src/http/ngx_http_request.c +26 -15
  33. data/src/nginx/src/http/ngx_http_script.c +0 -1
  34. data/src/nginx/src/http/ngx_http_upstream_round_robin.c +72 -170
  35. data/src/nginx/src/http/ngx_http_upstream_round_robin.h +1 -0
  36. data/src/nginx/src/os/unix/ngx_errno.h +2 -0
  37. metadata +6 -4
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.0.1
1
+ 1.2.1.2
data/bin/nginxtra CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
  require "rubygems"
3
- gem "nginxtra", "= 1.2.0.1"
3
+ gem "nginxtra", "= 1.2.1.2"
4
4
  require "nginxtra"
5
5
  Nginxtra::CLI.start
data/lib/nginxtra.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "nginxtra/action"
2
2
  require "nginxtra/actions/compile"
3
+ require "nginxtra/actions/convert"
3
4
  require "nginxtra/actions/install"
4
5
  require "nginxtra/actions/reload"
5
6
  require "nginxtra/actions/restart"
@@ -8,5 +9,6 @@ require "nginxtra/actions/status"
8
9
  require "nginxtra/actions/stop"
9
10
  require "nginxtra/cli"
10
11
  require "nginxtra/config"
12
+ require "nginxtra/config_converter"
11
13
  require "nginxtra/error"
12
14
  require "nginxtra/status"
@@ -40,7 +40,7 @@ module Nginxtra
40
40
  end
41
41
 
42
42
  def sudo(force = false)
43
- "sudo " if (force || @config.require_root?) && Process.uid != 0
43
+ "sudo " if (force || (@config && @config.require_root?)) && Process.uid != 0
44
44
  end
45
45
  end
46
46
  end
@@ -0,0 +1,67 @@
1
+ require "stringio"
2
+
3
+ module Nginxtra
4
+ module Actions
5
+ class Convert
6
+ include Nginxtra::Action
7
+
8
+ def convert
9
+ @streams_to_close = []
10
+ converter = Nginxtra::ConfigConverter.new output
11
+ converter.convert :config => config, :binary_status => binary_status
12
+ save_if_necessary!
13
+ ensure
14
+ close_streams!
15
+ end
16
+
17
+ private
18
+ def output
19
+ if @thor.options["output"]
20
+ STDOUT
21
+ elsif @thor.options["config"]
22
+ @output = @thor.options["config"]
23
+ @stringio = StringIO.new
24
+ else
25
+ @output = "nginxtra.conf.rb"
26
+ @stringio = StringIO.new
27
+ end
28
+ end
29
+
30
+ def save_if_necessary!
31
+ return unless @output && @stringio
32
+ @thor.create_file @output, @stringio.string
33
+ end
34
+
35
+ def config
36
+ if @thor.options["input"]
37
+ STDIN
38
+ elsif @thor.options["nginx-conf"]
39
+ open_file @thor.options["nginx-conf"]
40
+ end
41
+ end
42
+
43
+ def binary_status
44
+ return if @thor.options["ignore-nginx-bin"]
45
+
46
+ if @thor.options["nginx-bin"]
47
+ @thor.run "#{@thor.options["nginx-bin"]} -V 2>&1", :capture => true
48
+ else
49
+ # TODO: Figure out the nginx binary location and call -V
50
+ raise "The auto detection of nginx binary is not yet implemented. Please use the --nginx-bin option for now."
51
+ end
52
+ end
53
+
54
+ def open_file(path)
55
+ raise "Missing config file #{path}" unless File.exists? path
56
+
57
+ File.open(path, "r").tap do |stream|
58
+ @streams_to_close << stream
59
+ end
60
+ end
61
+
62
+ def close_streams!
63
+ @streams_to_close.each &:close
64
+ end
65
+ end
66
+ end
67
+ end
@@ -11,6 +11,9 @@ 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).
14
17
  return up_to_date unless should_install?
15
18
  return unless requesting_install?
16
19
  install
data/lib/nginxtra/cli.rb CHANGED
@@ -9,6 +9,26 @@ module Nginxtra
9
9
  class_option "config", :type => :string, :banner => "Specify the configuration file to use", :aliases => "-c"
10
10
  class_option "basedir", :type => :string, :banner => "Specify the directory to store nginx files", :aliases => "-b"
11
11
 
12
+ desc "convert", "Convert an nginx.conf file to an nginxtra.conf.rb"
13
+ long_desc "
14
+ Parse nginx.conf and convert it to an equivalent nginxtra.conf.rb file. Expects
15
+ nginx.conf to be in the current folder, but a different file can be specified
16
+ with the --nginx-conf option. Parses the compile time options using the nginx
17
+ binary parsed from /etc/init.d/nginx, which can be overridden with the
18
+ --nginx-bin option. This task will fail if the binary cannot be determined,
19
+ unless the --ignore-nginx-bin option is used, which will cause the compile time
20
+ options to be ignored (and the defaults will be used in the resulting
21
+ nginxtra.conf.rb). The result will be output to nginxtra.conf.rb in the current
22
+ directory, unless an override value is specified with the --config option."
23
+ method_option "nginx-bin", :type => :string, :banner => "Point to the compiled nginx to retrieve compile options", :aliases => "-n"
24
+ method_option "nginx-conf", :type => :string, :banner => "Point to the nginx.conf file to retrieve the existing configuration", :aliases => "-", :default => "nginx.conf"
25
+ method_option "ignore-nginx-bin", :type => :boolean, :banner => "Ignore the nginx binary, and assume default compile time options", :aliases => "-N"
26
+ method_option "output", :type => :boolean, :banner => "Output to standard out instead of to a file", :aliases => "-o"
27
+ method_option "input", :type => :boolean, :banner => "Read nginx.conf from standard in instead of a file", :aliases => "-i"
28
+ def convert
29
+ Nginxtra::Actions::Convert.new(self, nil).convert
30
+ end
31
+
12
32
  desc "compile", "Compiles nginx based on nginxtra.conf.rb"
13
33
  long_desc "
14
34
  Compile nginx with the compilation options specified in nginxtra.conf.rb. If it
@@ -0,0 +1,324 @@
1
+ module Nginxtra
2
+ class ConfigConverter
3
+ def initialize(output)
4
+ @converted = false
5
+ @output = output
6
+ @indentation = Nginxtra::ConfigConverter::Indentation.new
7
+ end
8
+
9
+ def convert(options)
10
+ raise Nginxtra::Error::ConvertFailed.new("The convert method can only be called once!") if converted?
11
+ header
12
+ compile_options options[:binary_status]
13
+ config_file options[:config]
14
+ footer
15
+ converted!
16
+ end
17
+
18
+ private
19
+ def header
20
+ @output.puts "nginxtra.config do"
21
+ @indentation + 1
22
+ end
23
+
24
+ def compile_options(status)
25
+ return unless status
26
+ options = (status[/^configure arguments:\s*(.*)$/, 1] || "").strip
27
+ return if options.empty?
28
+ options = options.split /\s+/
29
+ process_passenger_compile_options! options
30
+
31
+ options.each do |option|
32
+ next if invalid_compile_option? option
33
+ @output.print @indentation
34
+ @output.puts %{compile_option "#{option}"}
35
+ end
36
+ end
37
+
38
+ def process_passenger_compile_options!(options)
39
+ return if options.select { |x| x =~ /^--add-module.*\/passenger.*/ }.empty?
40
+ @output.print @indentation
41
+ @output.puts "require_passenger!"
42
+
43
+ options.delete_if do |x|
44
+ next true if x =~ /^--add-module.*\/passenger.*/
45
+ ["--with-http_ssl_module", "--with-http_gzip_static_module", "--with-cc-opt=-Wno-error"].include? x
46
+ end
47
+ end
48
+
49
+ def invalid_compile_option?(option)
50
+ return true if option =~ /--prefix=/
51
+ return true if option =~ /--sbin-path=/
52
+ return true if option =~ /--conf-path=/
53
+ return true if option =~ /--pid-path=/
54
+ false
55
+ end
56
+
57
+ def config_file(input)
58
+ return unless input
59
+ @output.print @indentation
60
+ @output.puts %{file "nginx.conf" do}
61
+ @indentation + 1
62
+ line = Nginxtra::ConfigConverter::Line.new @indentation, @output
63
+
64
+ each_token(input) do |token|
65
+ line << token
66
+
67
+ if line.terminated?
68
+ line.puts
69
+ line = Nginxtra::ConfigConverter::Line.new @indentation, @output
70
+ end
71
+ end
72
+
73
+ raise Nginxtra::Error::ConvertFailed.new("Unexpected end of file!") unless line.empty?
74
+ @indentation - 1
75
+ @output.print @indentation
76
+ @output.puts "end"
77
+ end
78
+
79
+ def each_token(input)
80
+ token = Nginxtra::ConfigConverter::Token.new
81
+
82
+ while c = input.read(1)
83
+ if c == "#"
84
+ chomp_comment input
85
+ else
86
+ token << c
87
+ end
88
+
89
+ yield token.instance while token.ready?
90
+ end
91
+
92
+ yield token.instance while token.ready?
93
+ raise Nginxtra::Error::ConvertFailed.new("Unexpected end of file in mid token!") unless token.value.empty?
94
+ end
95
+
96
+ def chomp_comment(input)
97
+ while c = input.read(1)
98
+ break if c == "\n"
99
+ end
100
+ end
101
+
102
+ def footer
103
+ @indentation - 1
104
+ @output.puts "end"
105
+ raise Nginxtra::Error::ConvertFailed.new("Missing end blocks!") unless @indentation.done?
106
+ end
107
+
108
+ def converted!
109
+ @converted = true
110
+ end
111
+
112
+ def converted?
113
+ @converted
114
+ end
115
+
116
+ class Token
117
+ TERMINAL_CHARACTERS = ["{", "}", ";"].freeze
118
+ attr_reader :value
119
+
120
+ def initialize(value = nil)
121
+ @instance = true if value
122
+ @value = value || ""
123
+ @ready = false
124
+ end
125
+
126
+ def terminal_character?
127
+ TERMINAL_CHARACTERS.include? @value
128
+ end
129
+
130
+ def end?
131
+ @value == ";"
132
+ end
133
+
134
+ def block_start?
135
+ @value == "{"
136
+ end
137
+
138
+ def block_end?
139
+ @value == "}"
140
+ end
141
+
142
+ def instance
143
+ raise Nginxtra::Error::ConvertFailed.new("Whoops!") unless ready?
144
+ token = Nginxtra::ConfigConverter::Token.new @value
145
+ reset!
146
+ token
147
+ end
148
+
149
+ def <<(c)
150
+ return space! if c =~ /\s/
151
+ return terminal_character!(c) if TERMINAL_CHARACTERS.include? c
152
+ @value << c
153
+ end
154
+
155
+ def ready?
156
+ @instance || @ready || terminal_character?
157
+ end
158
+
159
+ def to_s
160
+ if @value =~ /^\d+$/
161
+ @value
162
+ else
163
+ %{"#{@value}"}
164
+ end
165
+ end
166
+
167
+ private
168
+ def space!
169
+ return if @value.empty?
170
+ @ready = true
171
+ end
172
+
173
+ def terminal_character!(c)
174
+ if @value.empty?
175
+ @value = c
176
+ else
177
+ @next = c
178
+ end
179
+
180
+ @ready = true
181
+ end
182
+
183
+ def reset!
184
+ if @next
185
+ @value = @next
186
+ else
187
+ @value = ""
188
+ end
189
+
190
+ @next = nil
191
+ @ready = false
192
+ end
193
+ end
194
+
195
+ class Line
196
+ def initialize(indentation, output)
197
+ @indentation = indentation
198
+ @output = output
199
+ @tokens = []
200
+ end
201
+
202
+ def <<(token)
203
+ @tokens << token
204
+ end
205
+
206
+ def empty?
207
+ @tokens.empty?
208
+ end
209
+
210
+ def terminated?
211
+ @tokens.last.terminal_character?
212
+ end
213
+
214
+ def puts
215
+ if @tokens.last.end?
216
+ puts_line
217
+ elsif @tokens.last.block_start?
218
+ puts_block_start
219
+ elsif @tokens.last.block_end?
220
+ puts_block_end
221
+ else
222
+ raise Nginxtra::Error::ConvertFailed.new "Can't puts invalid line!"
223
+ end
224
+ end
225
+
226
+ private
227
+ def passenger?
228
+ ["passenger_root", "passenger_ruby", "passenger_enabled"].include? @tokens.first.value
229
+ end
230
+
231
+ def puts_line
232
+ raise Nginxtra::Error::ConvertFailed.new("line must have a first label!") unless @tokens.length > 1
233
+ return puts_passenger if passenger?
234
+ print_indentation
235
+ print_first
236
+ print_args
237
+ print_newline
238
+ end
239
+
240
+ def puts_passenger
241
+ print_indentation
242
+
243
+ if @tokens.first.value == "passenger_root"
244
+ print_newline "passenger_root!"
245
+ elsif @tokens.first.value == "passenger_ruby"
246
+ print_newline "passenger_ruby!"
247
+ elsif @tokens.first.value == "passenger_enabled"
248
+ print_newline "passenger_on!"
249
+ else
250
+ raise Nginxtra::Error::ConvertFailed.new("Whoops!")
251
+ end
252
+ end
253
+
254
+ def puts_block_start
255
+ raise Nginxtra::Error::ConvertFailed.new("Block start must have a first label!") unless @tokens.length > 1
256
+ print_indentation
257
+ print_first
258
+ print_args
259
+ print_newline(" do")
260
+ indent
261
+ end
262
+
263
+ def puts_block_end
264
+ raise Nginxtra::Error::ConvertFailed.new("Block end can't have labels!") unless @tokens.length == 1
265
+ unindent
266
+ print_indentation
267
+ print_newline("end")
268
+ end
269
+
270
+ def print_indentation
271
+ @output.print @indentation.to_s
272
+ end
273
+
274
+ def print_first
275
+ @output.print @tokens.first.value
276
+ end
277
+
278
+ def print_args
279
+ args = @tokens[1..-2]
280
+ return if args.empty?
281
+ @output.print " "
282
+ @output.print args.map(&:to_s).join(", ")
283
+ end
284
+
285
+ def print_newline(value = "")
286
+ @output.puts value
287
+ end
288
+
289
+ def indent
290
+ @indentation + 1
291
+ end
292
+
293
+ def unindent
294
+ @indentation - 1
295
+ end
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
+ end
324
+ end