mongrel-maglev- 1.1.9.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/COPYING +55 -0
  2. data/History.txt +69 -0
  3. data/LICENSE +55 -0
  4. data/Manifest.txt +69 -0
  5. data/Rakefile +8 -0
  6. data/TODO +5 -0
  7. data/bin/mongrel_rails +284 -0
  8. data/examples/builder.rb +29 -0
  9. data/examples/camping/README +3 -0
  10. data/examples/camping/blog.rb +294 -0
  11. data/examples/camping/tepee.rb +149 -0
  12. data/examples/httpd.conf +474 -0
  13. data/examples/mime.yaml +3 -0
  14. data/examples/mongrel.conf +9 -0
  15. data/examples/monitrc +57 -0
  16. data/examples/random_thrash.rb +19 -0
  17. data/examples/simpletest.rb +52 -0
  18. data/examples/webrick_compare.rb +20 -0
  19. data/ext/http11/Http11Service.java +13 -0
  20. data/ext/http11/ext_help.h +15 -0
  21. data/ext/http11/extconf.rb +6 -0
  22. data/ext/http11/http11.c +534 -0
  23. data/ext/http11/http11_parser.c +1243 -0
  24. data/ext/http11/http11_parser.h +49 -0
  25. data/ext/http11/http11_parser.java.rl +159 -0
  26. data/ext/http11/http11_parser.rl +153 -0
  27. data/ext/http11/http11_parser_common.rl +54 -0
  28. data/ext/http11/org/jruby/mongrel/Http11.java +241 -0
  29. data/ext/http11/org/jruby/mongrel/Http11Parser.java +486 -0
  30. data/lib/mongrel.rb +366 -0
  31. data/lib/mongrel/camping.rb +107 -0
  32. data/lib/mongrel/cgi.rb +181 -0
  33. data/lib/mongrel/command.rb +220 -0
  34. data/lib/mongrel/configurator.rb +388 -0
  35. data/lib/mongrel/const.rb +110 -0
  36. data/lib/mongrel/debug.rb +203 -0
  37. data/lib/mongrel/gems.rb +22 -0
  38. data/lib/mongrel/handlers.rb +468 -0
  39. data/lib/mongrel/header_out.rb +28 -0
  40. data/lib/mongrel/http_request.rb +155 -0
  41. data/lib/mongrel/http_response.rb +166 -0
  42. data/lib/mongrel/init.rb +10 -0
  43. data/lib/mongrel/mime_types.yml +616 -0
  44. data/lib/mongrel/rails.rb +185 -0
  45. data/lib/mongrel/stats.rb +89 -0
  46. data/lib/mongrel/tcphack.rb +18 -0
  47. data/lib/mongrel/uri_classifier.rb +76 -0
  48. data/setup.rb +1585 -0
  49. data/tasks/gem.rake +28 -0
  50. data/tasks/native.rake +25 -0
  51. data/tasks/ragel.rake +20 -0
  52. data/test/mime.yaml +3 -0
  53. data/test/mongrel.conf +1 -0
  54. data/test/test_cgi_wrapper.rb +26 -0
  55. data/test/test_command.rb +86 -0
  56. data/test/test_conditional.rb +107 -0
  57. data/test/test_configurator.rb +87 -0
  58. data/test/test_debug.rb +25 -0
  59. data/test/test_handlers.rb +135 -0
  60. data/test/test_http11.rb +156 -0
  61. data/test/test_redirect_handler.rb +44 -0
  62. data/test/test_request_progress.rb +99 -0
  63. data/test/test_response.rb +127 -0
  64. data/test/test_stats.rb +35 -0
  65. data/test/test_uriclassifier.rb +261 -0
  66. data/test/test_ws.rb +115 -0
  67. data/test/testhelp.rb +71 -0
  68. data/tools/trickletest.rb +45 -0
  69. metadata +186 -0
data/COPYING ADDED
@@ -0,0 +1,55 @@
1
+ Mongrel Web Server (Mongrel) is copyrighted free software by Zed A. Shaw
2
+ <zedshaw at zedshaw dot com> You can redistribute it and/or modify it under
3
+ either the terms of the GPL or the conditions below:
4
+
5
+ 1. You may make and give away verbatim copies of the source form of the
6
+ software without restriction, provided that you duplicate all of the
7
+ original copyright notices and associated disclaimers.
8
+
9
+ 2. You may modify your copy of the software in any way, provided that
10
+ you do at least ONE of the following:
11
+
12
+ a) place your modifications in the Public Domain or otherwise make them
13
+ Freely Available, such as by posting said modifications to Usenet or an
14
+ equivalent medium, or by allowing the author to include your
15
+ modifications in the software.
16
+
17
+ b) use the modified software only within your corporation or
18
+ organization.
19
+
20
+ c) rename any non-standard executables so the names do not conflict with
21
+ standard executables, which must also be provided.
22
+
23
+ d) make other distribution arrangements with the author.
24
+
25
+ 3. You may distribute the software in object code or executable
26
+ form, provided that you do at least ONE of the following:
27
+
28
+ a) distribute the executables and library files of the software,
29
+ together with instructions (in the manual page or equivalent) on where
30
+ to get the original distribution.
31
+
32
+ b) accompany the distribution with the machine-readable source of the
33
+ software.
34
+
35
+ c) give non-standard executables non-standard names, with
36
+ instructions on where to get the original software distribution.
37
+
38
+ d) make other distribution arrangements with the author.
39
+
40
+ 4. You may modify and include the part of the software into any other
41
+ software (possibly commercial). But some files in the distribution
42
+ are not written by the author, so that they are not under this terms.
43
+
44
+ 5. The scripts and library files supplied as input to or produced as
45
+ output from the software do not automatically fall under the
46
+ copyright of the software, but belong to whomever generated them,
47
+ and may be sold commercially, and may be aggregated with this
48
+ software.
49
+
50
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
51
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
52
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
53
+ PURPOSE.
54
+
55
+
data/History.txt ADDED
@@ -0,0 +1,69 @@
1
+ === 1.2.0.beta.1 / 2010-07-??
2
+
3
+ Improvements:
4
+
5
+ * Ruby 1.9 early compatbility: Merged commits form Eric Wong and Matt Aimonetti.
6
+ * Better RubyGems support thanks to added env she-bang to mongrel_rails executable.
7
+ * Smartly load http11 extension using fat-binary approach.
8
+ * Better detection of Windows platform (usage of RbConfig::CONFIG instead of RUBY_PLATFORM)
9
+
10
+ Bugfixes:
11
+
12
+ * Fixed proper version reporting under 1.9
13
+ * Consider MinGW as valid Windows platform.
14
+ * Properly drop PID when daemonizing (EngineYard patched 1.1.5.1).
15
+
16
+ Reorganization:
17
+
18
+ * Rake task project reorganization and reformat using Hoe.
19
+ * Compile extension using rake-compiler
20
+ * Upgraded http11_parser to work with Ragel 6.2
21
+ * Deprecated obsolete Windows service example scripts (from 2006!)
22
+ * Relocate Http11 JRuby extension to share http11 C extension folder and name.
23
+
24
+ === 1.1.5 / 2008-05-22
25
+
26
+ * Fix bug where num_processors is not actually set from mongrel_rails.
27
+
28
+
29
+ === 1.1.4 / 2008-02-29
30
+
31
+ * Fix camping handler. Correct treatment of @throttle parameter.
32
+
33
+
34
+ === 1.1.3 / 2007-12-29
35
+
36
+ * Fix security flaw of DirHandler; reported on mailing list.
37
+
38
+
39
+ === 1.1.2 / 2007-12-15
40
+
41
+ * Fix worker termination bug; fix JRuby 1.0.3 load order issue; fix require issue on systems without Rubygems.
42
+
43
+
44
+ === 1.1.1 / 2007-11-12
45
+
46
+ * Fix mongrel_rails restart bug; fix bug with Rack status codes.
47
+
48
+
49
+ === 1.1 / 2007-11-01
50
+
51
+ * Pure Ruby URIClassifier.
52
+ * More modular architecture.
53
+ * JRuby support.
54
+ * Move C URIClassifier into mongrel_experimental project.
55
+
56
+
57
+ === 1.0.4 / 2007-10-29
58
+
59
+ * Backport fixes for versioning inconsistency, mongrel_rails bug, and DirHandler bug.
60
+
61
+
62
+ === 1.0.3
63
+
64
+ * Fix user-switching bug; make people upgrade to the latest from the RC.
65
+
66
+
67
+ === 1.0.2
68
+
69
+ * Signed gem; many minor bugfixes and patches.
data/LICENSE ADDED
@@ -0,0 +1,55 @@
1
+ Mongrel Web Server (Mongrel) is copyrighted free software by Zed A. Shaw
2
+ <zedshaw at zedshaw dot com> and contributors. You can redistribute it
3
+ and/or modify it under either the terms of the GPL2 or the conditions below:
4
+
5
+ 1. You may make and give away verbatim copies of the source form of the
6
+ software without restriction, provided that you duplicate all of the
7
+ original copyright notices and associated disclaimers.
8
+
9
+ 2. You may modify your copy of the software in any way, provided that
10
+ you do at least ONE of the following:
11
+
12
+ a) place your modifications in the Public Domain or otherwise make them
13
+ Freely Available, such as by posting said modifications to Usenet or an
14
+ equivalent medium, or by allowing the author to include your
15
+ modifications in the software.
16
+
17
+ b) use the modified software only within your corporation or
18
+ organization.
19
+
20
+ c) rename any non-standard executables so the names do not conflict with
21
+ standard executables, which must also be provided.
22
+
23
+ d) make other distribution arrangements with the author.
24
+
25
+ 3. You may distribute the software in object code or executable
26
+ form, provided that you do at least ONE of the following:
27
+
28
+ a) distribute the executables and library files of the software,
29
+ together with instructions (in the manual page or equivalent) on where
30
+ to get the original distribution.
31
+
32
+ b) accompany the distribution with the machine-readable source of the
33
+ software.
34
+
35
+ c) give non-standard executables non-standard names, with
36
+ instructions on where to get the original software distribution.
37
+
38
+ d) make other distribution arrangements with the author.
39
+
40
+ 4. You may modify and include the part of the software into any other
41
+ software (possibly commercial). But some files in the distribution
42
+ are not written by the author, so that they are not under this terms.
43
+
44
+ 5. The scripts and library files supplied as input to or produced as
45
+ output from the software do not automatically fall under the
46
+ copyright of the software, but belong to whomever generated them,
47
+ and may be sold commercially, and may be aggregated with this
48
+ software.
49
+
50
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
51
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
52
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
53
+ PURPOSE.
54
+
55
+
data/Manifest.txt ADDED
@@ -0,0 +1,69 @@
1
+ COPYING
2
+ History.txt
3
+ LICENSE
4
+ Manifest.txt
5
+ README.txt
6
+ Rakefile
7
+ TODO
8
+ bin/mongrel_rails
9
+ examples/builder.rb
10
+ examples/camping/README
11
+ examples/camping/blog.rb
12
+ examples/camping/tepee.rb
13
+ examples/httpd.conf
14
+ examples/mime.yaml
15
+ examples/mongrel.conf
16
+ examples/monitrc
17
+ examples/random_thrash.rb
18
+ examples/simpletest.rb
19
+ examples/webrick_compare.rb
20
+ ext/http11/ext_help.h
21
+ ext/http11/extconf.rb
22
+ ext/http11/http11.c
23
+ ext/http11/http11_parser.c
24
+ ext/http11/http11_parser.h
25
+ ext/http11/http11_parser.java.rl
26
+ ext/http11/http11_parser.rl
27
+ ext/http11/http11_parser_common.rl
28
+ ext/http11/Http11Service.java
29
+ ext/http11/org/jruby/mongrel/Http11.java
30
+ ext/http11/org/jruby/mongrel/Http11Parser.java
31
+ lib/mongrel.rb
32
+ lib/mongrel/camping.rb
33
+ lib/mongrel/cgi.rb
34
+ lib/mongrel/command.rb
35
+ lib/mongrel/configurator.rb
36
+ lib/mongrel/const.rb
37
+ lib/mongrel/debug.rb
38
+ lib/mongrel/gems.rb
39
+ lib/mongrel/handlers.rb
40
+ lib/mongrel/header_out.rb
41
+ lib/mongrel/http_request.rb
42
+ lib/mongrel/http_response.rb
43
+ lib/mongrel/init.rb
44
+ lib/mongrel/mime_types.yml
45
+ lib/mongrel/rails.rb
46
+ lib/mongrel/stats.rb
47
+ lib/mongrel/tcphack.rb
48
+ lib/mongrel/uri_classifier.rb
49
+ setup.rb
50
+ tasks/gem.rake
51
+ tasks/native.rake
52
+ tasks/ragel.rake
53
+ test/mime.yaml
54
+ test/mongrel.conf
55
+ test/test_cgi_wrapper.rb
56
+ test/test_command.rb
57
+ test/test_conditional.rb
58
+ test/test_configurator.rb
59
+ test/test_debug.rb
60
+ test/test_handlers.rb
61
+ test/test_http11.rb
62
+ test/test_redirect_handler.rb
63
+ test/test_request_progress.rb
64
+ test/test_response.rb
65
+ test/test_stats.rb
66
+ test/test_uriclassifier.rb
67
+ test/test_ws.rb
68
+ test/testhelp.rb
69
+ tools/trickletest.rb
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ #
2
+ # NOTE: Keep this file clean.
3
+ # Add your customizations inside tasks directory.
4
+ # Thank You.
5
+ #
6
+
7
+ # load rakefile extensions (tasks)
8
+ Dir['tasks/*.rake'].sort.each { |f| load f }
data/TODO ADDED
@@ -0,0 +1,5 @@
1
+
2
+ v1.2. Rewrite and merge mongrel cluster and mongrel_rails into something small and maintainable. Remove gem_plugin entirely.
3
+
4
+ v1.1.1. See if Java is setting the server version string in the request properly.
5
+
data/bin/mongrel_rails ADDED
@@ -0,0 +1,284 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright (c) 2005 Zed A. Shaw
4
+ # You can redistribute it and/or modify it under the same terms as Ruby.
5
+ #
6
+ # Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html
7
+ # for more information.
8
+
9
+ require 'yaml'
10
+ require 'etc'
11
+
12
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
13
+ require 'mongrel'
14
+ require 'mongrel/rails'
15
+
16
+ Mongrel::Gems.require 'gem_plugin'
17
+
18
+ # require 'ruby-debug'
19
+ # Debugger.start
20
+
21
+ module Mongrel
22
+ class Start < GemPlugin::Plugin "/commands"
23
+ include Mongrel::Command::Base
24
+
25
+ def configure
26
+ options [
27
+ ["-e", "--environment ENV", "Rails environment to run as", :@environment, ENV['RAILS_ENV'] || "development"],
28
+ ["-d", "--daemonize", "Run daemonized in the background", :@daemon, false],
29
+ ['-p', '--port PORT', "Which port to bind to", :@port, 3000],
30
+ ['-a', '--address ADDR', "Address to bind to", :@address, "0.0.0.0"],
31
+ ['-l', '--log FILE', "Where to write log messages", :@log_file, "log/mongrel.log"],
32
+ ['-P', '--pid FILE', "Where to write the PID", :@pid_file, "log/mongrel.pid"],
33
+ ['-n', '--num-processors INT', "Number of processors active before clients denied", :@num_processors, 1024],
34
+ ['-o', '--timeout TIME', "Time to wait (in seconds) before killing a stalled thread", :@timeout, 60],
35
+ ['-t', '--throttle TIME', "Time to pause (in hundredths of a second) between accepting clients", :@throttle, 0],
36
+ ['-m', '--mime PATH', "A YAML file that lists additional MIME types", :@mime_map, nil],
37
+ ['-c', '--chdir PATH', "Change to dir before starting (will be expanded)", :@cwd, Dir.pwd],
38
+ ['-r', '--root PATH', "Set the document root (default 'public')", :@docroot, "public"],
39
+ ['-B', '--debug', "Enable debugging mode", :@debug, false],
40
+ ['-C', '--config PATH', "Use a config file", :@config_file, nil],
41
+ ['-S', '--script PATH', "Load the given file as an extra config script", :@config_script, nil],
42
+ ['-G', '--generate PATH', "Generate a config file for use with -C", :@generate, nil],
43
+ ['', '--user USER', "User to run as", :@user, nil],
44
+ ['', '--group GROUP', "Group to run as", :@group, nil],
45
+ ['', '--prefix PATH', "URL prefix for Rails app", :@prefix, nil]
46
+ ]
47
+ end
48
+
49
+ def validate
50
+ if @config_file
51
+ valid_exists?(@config_file, "Config file not there: #@config_file")
52
+ return false unless @valid
53
+ @config_file = File.expand_path(@config_file)
54
+ load_config
55
+ return false unless @valid
56
+ end
57
+
58
+ @cwd = File.expand_path(@cwd)
59
+ valid_dir? @cwd, "Invalid path to change to during daemon mode: #@cwd"
60
+
61
+ # Change there to start, then we'll have to come back after daemonize
62
+ Dir.chdir(@cwd)
63
+
64
+ valid?(@prefix[0] == ?/ && @prefix[-1] != ?/, "Prefix must begin with / and not end in /") if @prefix
65
+ valid_dir? File.dirname(@log_file), "Path to log file not valid: #@log_file"
66
+ valid_dir? File.dirname(@pid_file), "Path to pid file not valid: #@pid_file"
67
+ valid_dir? @docroot, "Path to docroot not valid: #@docroot"
68
+ valid_exists? @mime_map, "MIME mapping file does not exist: #@mime_map" if @mime_map
69
+ valid_exists? @config_file, "Config file not there: #@config_file" if @config_file
70
+ valid_dir? File.dirname(@generate), "Problem accessing directory to #@generate" if @generate
71
+ valid_user? @user if @user
72
+ valid_group? @group if @group
73
+
74
+ return @valid
75
+ end
76
+
77
+ def run
78
+ if @generate
79
+ @generate = File.expand_path(@generate)
80
+ STDERR.puts "** Writing config to \"#@generate\"."
81
+ open(@generate, "w") {|f| f.write(settings.to_yaml) }
82
+ STDERR.puts "** Finished. Run \"mongrel_rails start -C #@generate\" to use the config file."
83
+ exit 0
84
+ end
85
+
86
+ config = Mongrel::Rails::RailsConfigurator.new(settings) do
87
+ if defaults[:daemon]
88
+ if File.exist? defaults[:pid_file]
89
+ log "!!! PID file #{defaults[:pid_file]} already exists. Mongrel could be running already. Check your #{defaults[:log_file]} for errors."
90
+ log "!!! Exiting with error. You must stop mongrel and clear the .pid before I'll attempt a start."
91
+ exit 1
92
+ end
93
+
94
+ daemonize
95
+ write_pid_file
96
+ log "Daemonized, any open files are closed. Look at #{defaults[:pid_file]} and #{defaults[:log_file]} for info."
97
+ log "Settings loaded from #{@config_file} (they override command line)." if @config_file
98
+ end
99
+
100
+ log "Starting Mongrel listening at #{defaults[:host]}:#{defaults[:port]}"
101
+
102
+ listener do
103
+ mime = {}
104
+ if defaults[:mime_map]
105
+ log "Loading additional MIME types from #{defaults[:mime_map]}"
106
+ mime = load_mime_map(defaults[:mime_map], mime)
107
+ end
108
+
109
+ if defaults[:debug]
110
+ log "Installing debugging prefixed filters. Look in log/mongrel_debug for the files."
111
+ debug "/"
112
+ end
113
+
114
+ log "Starting Rails with #{defaults[:environment]} environment..."
115
+ log "Mounting Rails at #{defaults[:prefix]}..." if defaults[:prefix]
116
+ uri defaults[:prefix] || "/", :handler => rails(:mime => mime, :prefix => defaults[:prefix])
117
+ log "Rails loaded."
118
+
119
+ log "Loading any Rails specific GemPlugins"
120
+ load_plugins
121
+
122
+ if defaults[:config_script]
123
+ log "Loading #{defaults[:config_script]} external config script"
124
+ run_config(defaults[:config_script])
125
+ end
126
+
127
+ setup_rails_signals
128
+ end
129
+ end
130
+
131
+ config.run
132
+ config.log "Mongrel #{Mongrel::Const::MONGREL_VERSION} available at #{@address}:#{@port}"
133
+
134
+ unless config.defaults[:daemon]
135
+ config.log "Use CTRL-C to stop."
136
+ end
137
+
138
+ config.join
139
+
140
+ if config.needs_restart
141
+ unless RbConfig::CONFIG['host_os'] =~ /mingw|mswin/
142
+ cmd = "ruby #{__FILE__} start #{original_args.join(' ')}"
143
+ config.log "Restarting with arguments: #{cmd}"
144
+ config.stop(false, true)
145
+ config.remove_pid_file
146
+
147
+ if config.defaults[:daemon]
148
+ system cmd
149
+ else
150
+ STDERR.puts "Can't restart unless in daemon mode."
151
+ exit 1
152
+ end
153
+ else
154
+ config.log "Win32 does not support restarts. Exiting."
155
+ end
156
+ end
157
+ end
158
+
159
+ def load_config
160
+ settings = {}
161
+ begin
162
+ settings = YAML.load_file(@config_file)
163
+ ensure
164
+ STDERR.puts "** Loading settings from #{@config_file} (they override command line)." unless @daemon || settings[:daemon]
165
+ end
166
+
167
+ settings[:includes] ||= ["mongrel"]
168
+
169
+ # Config file settings will override command line settings
170
+ settings.each do |key, value|
171
+ key = key.to_s
172
+ if config_keys.include?(key)
173
+ key = 'address' if key == 'host'
174
+ self.instance_variable_set("@#{key}", value)
175
+ else
176
+ failure "Unknown configuration setting: #{key}"
177
+ @valid = false
178
+ end
179
+ end
180
+ end
181
+
182
+ def config_keys
183
+ @config_keys ||=
184
+ %w(address host port cwd log_file pid_file environment docroot mime_map daemon debug includes config_script num_processors timeout throttle user group prefix)
185
+ end
186
+
187
+ def settings
188
+ config_keys.inject({}) do |hash, key|
189
+ value = self.instance_variable_get("@#{key}")
190
+ key = 'host' if key == 'address'
191
+ hash[key.to_sym] ||= value
192
+ hash
193
+ end
194
+ end
195
+ end
196
+
197
+ def Mongrel::send_signal(signal, pid_file)
198
+ pid = File.read(pid_file).to_i
199
+ print "Sending #{signal} to Mongrel at PID #{pid}..."
200
+ begin
201
+ Process.kill(signal, pid)
202
+ rescue Errno::ESRCH
203
+ puts "Process does not exist. Not running."
204
+ end
205
+
206
+ puts "Done."
207
+ end
208
+
209
+
210
+ class Stop < GemPlugin::Plugin "/commands"
211
+ include Mongrel::Command::Base
212
+
213
+ def configure
214
+ options [
215
+ ['-c', '--chdir PATH', "Change to dir before starting (will be expanded).", :@cwd, "."],
216
+ ['-f', '--force', "Force the shutdown (kill -9).", :@force, false],
217
+ ['-w', '--wait SECONDS', "Wait SECONDS before forcing shutdown", :@wait, "0"],
218
+ ['-P', '--pid FILE', "Where the PID file is located.", :@pid_file, "log/mongrel.pid"]
219
+ ]
220
+ end
221
+
222
+ def validate
223
+ @cwd = File.expand_path(@cwd)
224
+ valid_dir? @cwd, "Invalid path to change to during daemon mode: #@cwd"
225
+
226
+ Dir.chdir @cwd
227
+
228
+ valid_exists? @pid_file, "PID file #@pid_file does not exist. Not running?"
229
+ return @valid
230
+ end
231
+
232
+ def run
233
+ if @force
234
+ @wait.to_i.times do |waiting|
235
+ exit(0) if not File.exist? @pid_file
236
+ sleep 1
237
+ end
238
+
239
+ Mongrel::send_signal("KILL", @pid_file) if File.exist? @pid_file
240
+ else
241
+ Mongrel::send_signal("TERM", @pid_file)
242
+ end
243
+ end
244
+ end
245
+
246
+
247
+ class Restart < GemPlugin::Plugin "/commands"
248
+ include Mongrel::Command::Base
249
+
250
+ def configure
251
+ options [
252
+ ['-c', '--chdir PATH', "Change to dir before starting (will be expanded)", :@cwd, '.'],
253
+ ['-s', '--soft', "Do a soft restart rather than a process exit restart", :@soft, false],
254
+ ['-P', '--pid FILE', "Where the PID file is located", :@pid_file, "log/mongrel.pid"]
255
+ ]
256
+ end
257
+
258
+ def validate
259
+ @cwd = File.expand_path(@cwd)
260
+ valid_dir? @cwd, "Invalid path to change to during daemon mode: #@cwd"
261
+
262
+ Dir.chdir @cwd
263
+
264
+ valid_exists? @pid_file, "PID file #@pid_file does not exist. Not running?"
265
+ return @valid
266
+ end
267
+
268
+ def run
269
+ if @soft
270
+ Mongrel::send_signal("HUP", @pid_file)
271
+ else
272
+ Mongrel::send_signal("USR2", @pid_file)
273
+ end
274
+ end
275
+ end
276
+ end
277
+
278
+
279
+ GemPlugin::Manager.instance.load "mongrel" => GemPlugin::INCLUDE, "rails" => GemPlugin::EXCLUDE
280
+
281
+
282
+ if not Mongrel::Command::Registry.instance.run ARGV
283
+ exit 1
284
+ end