mongrel 1.1.5-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +4 -0
- data/CHANGELOG +18 -0
- data/COPYING +55 -0
- data/LICENSE +55 -0
- data/Manifest +69 -0
- data/README +74 -0
- data/TODO +5 -0
- data/bin/mongrel_rails +283 -0
- data/examples/builder.rb +29 -0
- data/examples/camping/README +3 -0
- data/examples/camping/blog.rb +294 -0
- data/examples/camping/tepee.rb +149 -0
- data/examples/httpd.conf +474 -0
- data/examples/mime.yaml +3 -0
- data/examples/mongrel.conf +9 -0
- data/examples/mongrel_simple_ctrl.rb +92 -0
- data/examples/mongrel_simple_service.rb +116 -0
- data/examples/monitrc +57 -0
- data/examples/random_thrash.rb +19 -0
- data/examples/simpletest.rb +52 -0
- data/examples/webrick_compare.rb +20 -0
- data/ext/http11/ext_help.h +14 -0
- data/ext/http11/extconf.rb +6 -0
- data/ext/http11/http11.c +402 -0
- data/ext/http11/http11_parser.c +1221 -0
- data/ext/http11/http11_parser.h +49 -0
- data/ext/http11/http11_parser.java.rl +170 -0
- data/ext/http11/http11_parser.rl +152 -0
- data/ext/http11/http11_parser_common.rl +54 -0
- data/ext/http11_java/Http11Service.java +13 -0
- data/ext/http11_java/org/jruby/mongrel/Http11.java +266 -0
- data/ext/http11_java/org/jruby/mongrel/Http11Parser.java +572 -0
- data/lib/http11.so +0 -0
- data/lib/mongrel.rb +355 -0
- data/lib/mongrel/camping.rb +107 -0
- data/lib/mongrel/cgi.rb +181 -0
- data/lib/mongrel/command.rb +222 -0
- data/lib/mongrel/configurator.rb +388 -0
- data/lib/mongrel/const.rb +110 -0
- data/lib/mongrel/debug.rb +203 -0
- data/lib/mongrel/gems.rb +22 -0
- data/lib/mongrel/handlers.rb +468 -0
- data/lib/mongrel/header_out.rb +28 -0
- data/lib/mongrel/http_request.rb +155 -0
- data/lib/mongrel/http_response.rb +163 -0
- data/lib/mongrel/init.rb +10 -0
- data/lib/mongrel/mime_types.yml +616 -0
- data/lib/mongrel/rails.rb +185 -0
- data/lib/mongrel/stats.rb +89 -0
- data/lib/mongrel/tcphack.rb +18 -0
- data/lib/mongrel/uri_classifier.rb +76 -0
- data/mongrel-public_cert.pem +20 -0
- data/mongrel.gemspec +242 -0
- data/setup.rb +1585 -0
- data/test/mime.yaml +3 -0
- data/test/mongrel.conf +1 -0
- data/test/test_cgi_wrapper.rb +26 -0
- data/test/test_command.rb +86 -0
- data/test/test_conditional.rb +107 -0
- data/test/test_configurator.rb +88 -0
- data/test/test_debug.rb +25 -0
- data/test/test_handlers.rb +126 -0
- data/test/test_http11.rb +156 -0
- data/test/test_redirect_handler.rb +45 -0
- data/test/test_request_progress.rb +100 -0
- data/test/test_response.rb +127 -0
- data/test/test_stats.rb +35 -0
- data/test/test_uriclassifier.rb +261 -0
- data/test/test_ws.rb +115 -0
- data/test/testhelp.rb +79 -0
- data/tools/trickletest.rb +45 -0
- metadata +197 -0
- metadata.gz.sig +1 -0
data.tar.gz.sig
ADDED
data/CHANGELOG
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
|
2
|
+
v1.1.5. Fix bug where num_processors is not actually set from mongrel_rails.
|
3
|
+
|
4
|
+
v1.1.4. Fix camping handler. Correct treatment of @throttle parameter.
|
5
|
+
|
6
|
+
v1.1.3. Fix security flaw of DirHandler; reported on mailing list.
|
7
|
+
|
8
|
+
v1.1.2. Fix worker termination bug; fix JRuby 1.0.3 load order issue; fix require issue on systems without Rubygems.
|
9
|
+
|
10
|
+
v1.1.1. Fix mongrel_rails restart bug; fix bug with Rack status codes.
|
11
|
+
|
12
|
+
v1.1. Pure Ruby URIClassifier. More modular architecture. JRuby support. Move C URIClassifier into mongrel_experimental project.
|
13
|
+
|
14
|
+
v1.0.4. Backport fixes for versioning inconsistency, mongrel_rails bug, and DirHandler bug.
|
15
|
+
|
16
|
+
v1.0.3. Fix user-switching bug; make people upgrade to the latest from the RC.
|
17
|
+
|
18
|
+
v1.0.2. Signed gem; many minor bugfixes and patches.
|
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/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
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
bin/mongrel_rails
|
2
|
+
CHANGELOG
|
3
|
+
COPYING
|
4
|
+
examples/builder.rb
|
5
|
+
examples/camping/blog.rb
|
6
|
+
examples/camping/README
|
7
|
+
examples/camping/tepee.rb
|
8
|
+
examples/httpd.conf
|
9
|
+
examples/mime.yaml
|
10
|
+
examples/mongrel.conf
|
11
|
+
examples/mongrel_simple_ctrl.rb
|
12
|
+
examples/mongrel_simple_service.rb
|
13
|
+
examples/monitrc
|
14
|
+
examples/random_thrash.rb
|
15
|
+
examples/simpletest.rb
|
16
|
+
examples/webrick_compare.rb
|
17
|
+
ext/http11/ext_help.h
|
18
|
+
ext/http11/extconf.rb
|
19
|
+
ext/http11/http11.c
|
20
|
+
ext/http11/http11_parser.c
|
21
|
+
ext/http11/http11_parser.h
|
22
|
+
ext/http11/http11_parser.java.rl
|
23
|
+
ext/http11/http11_parser.rl
|
24
|
+
ext/http11/http11_parser_common.rl
|
25
|
+
ext/http11_java/Http11Service.java
|
26
|
+
ext/http11_java/org/jruby/mongrel/Http11.java
|
27
|
+
ext/http11_java/org/jruby/mongrel/Http11Parser.java
|
28
|
+
lib/mongrel/camping.rb
|
29
|
+
lib/mongrel/cgi.rb
|
30
|
+
lib/mongrel/command.rb
|
31
|
+
lib/mongrel/configurator.rb
|
32
|
+
lib/mongrel/const.rb
|
33
|
+
lib/mongrel/debug.rb
|
34
|
+
lib/mongrel/gems.rb
|
35
|
+
lib/mongrel/handlers.rb
|
36
|
+
lib/mongrel/header_out.rb
|
37
|
+
lib/mongrel/http_request.rb
|
38
|
+
lib/mongrel/http_response.rb
|
39
|
+
lib/mongrel/init.rb
|
40
|
+
lib/mongrel/mime_types.yml
|
41
|
+
lib/mongrel/rails.rb
|
42
|
+
lib/mongrel/stats.rb
|
43
|
+
lib/mongrel/tcphack.rb
|
44
|
+
lib/mongrel/uri_classifier.rb
|
45
|
+
lib/mongrel.rb
|
46
|
+
LICENSE
|
47
|
+
Manifest
|
48
|
+
mongrel-public_cert.pem
|
49
|
+
mongrel.gemspec
|
50
|
+
README
|
51
|
+
setup.rb
|
52
|
+
test/mime.yaml
|
53
|
+
test/mongrel.conf
|
54
|
+
test/test_cgi_wrapper.rb
|
55
|
+
test/test_command.rb
|
56
|
+
test/test_conditional.rb
|
57
|
+
test/test_configurator.rb
|
58
|
+
test/test_debug.rb
|
59
|
+
test/test_handlers.rb
|
60
|
+
test/test_http11.rb
|
61
|
+
test/test_redirect_handler.rb
|
62
|
+
test/test_request_progress.rb
|
63
|
+
test/test_response.rb
|
64
|
+
test/test_stats.rb
|
65
|
+
test/test_uriclassifier.rb
|
66
|
+
test/test_ws.rb
|
67
|
+
test/testhelp.rb
|
68
|
+
TODO
|
69
|
+
tools/trickletest.rb
|
data/README
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
= Mongrel: Simple Fast Mostly Ruby Web Server
|
2
|
+
|
3
|
+
Mongrel is a small library that provides a very fast HTTP 1.1 server for Ruby web applications. It is not particular to any framework, and is intended to be just enough to get a web application running behind a more complete and robust web server.
|
4
|
+
|
5
|
+
What makes Mongrel so fast is the careful use of an Ragel extension to provide fast, accurate HTTP 1.1 protocol parsing. This makes the server scream without too many portability issues.
|
6
|
+
|
7
|
+
See http://mongrel.rubyforge.org for more information.
|
8
|
+
|
9
|
+
== License
|
10
|
+
|
11
|
+
Mongrel is copyright 2007 Zed A. Shaw and contributors. It is licensed under the Ruby license and the GPL2. See the include LICENSE file for details.
|
12
|
+
|
13
|
+
== Quick Start
|
14
|
+
|
15
|
+
The easiest way to get started with Mongrel is to install it via RubyGems and then run a Ruby on Rails application. You can do this easily:
|
16
|
+
|
17
|
+
$ gem install mongrel
|
18
|
+
|
19
|
+
Now you should have the mongrel_rails command available in your PATH, so just do the following:
|
20
|
+
|
21
|
+
$ cd myrailsapp
|
22
|
+
$ mongrel_rails start
|
23
|
+
|
24
|
+
This will start it in the foreground so you can play with it. It runs your application in production mode. To get help do:
|
25
|
+
|
26
|
+
$ mongrel_rails start -h
|
27
|
+
|
28
|
+
Finally, you can then start in background mode:
|
29
|
+
|
30
|
+
$ mongrel_rails start -d
|
31
|
+
|
32
|
+
And you can stop it whenever you like with:
|
33
|
+
|
34
|
+
$ mongrel_rails stop
|
35
|
+
|
36
|
+
All of which should be done from your application's directory. It writes the PID of the process you ran into log/mongrel.pid.
|
37
|
+
|
38
|
+
There are also many more new options for configuring the rails runner including changing to a different directory, adding more MIME types, and setting processor threads and timeouts.
|
39
|
+
|
40
|
+
== Install
|
41
|
+
|
42
|
+
It doesn't explicitly require Camping, but if you want to run the examples/camping/ examples then you'll need to install Camping 1.2 at least (and redcloth I think). These are all available from RubyGems.
|
43
|
+
|
44
|
+
The library consists of a C extension so you'll need a C compiler or at least a friend who can build it for you.
|
45
|
+
|
46
|
+
Finally, the source includes a setup.rb for those who hate RubyGems.
|
47
|
+
|
48
|
+
== Usage
|
49
|
+
|
50
|
+
The examples/simpletest.rb file has the following code as the simplest example:
|
51
|
+
|
52
|
+
require 'mongrel'
|
53
|
+
|
54
|
+
class SimpleHandler < Mongrel::HttpHandler
|
55
|
+
def process(request, response)
|
56
|
+
response.start(200) do |head,out|
|
57
|
+
head["Content-Type"] = "text/plain"
|
58
|
+
out.write("hello!\n")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
h = Mongrel::HttpServer.new("0.0.0.0", "3000")
|
64
|
+
h.register("/test", SimpleHandler.new)
|
65
|
+
h.register("/files", Mongrel::DirHandler.new("."))
|
66
|
+
h.run.join
|
67
|
+
|
68
|
+
If you run this and access port 3000 with a browser it will say "hello!". If you access it with any url other than "/test" it will give a simple 404. Check out the Mongrel::Error404Handler for a basic way to give a more complex 404 message.
|
69
|
+
|
70
|
+
This also shows the DirHandler with directory listings. This is still rough but it should work for basic hosting. *File extension to mime type mapping is missing though.*
|
71
|
+
|
72
|
+
== Contact
|
73
|
+
|
74
|
+
E-mail the Mongrel list at http://rubyforge.org/mailman/listinfo/mongrel-users and someone will help you. Comments about the API are welcome.
|
data/TODO
ADDED
data/bin/mongrel_rails
ADDED
@@ -0,0 +1,283 @@
|
|
1
|
+
# Copyright (c) 2005 Zed A. Shaw
|
2
|
+
# You can redistribute it and/or modify it under the same terms as Ruby.
|
3
|
+
#
|
4
|
+
# Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html
|
5
|
+
# for more information.
|
6
|
+
|
7
|
+
require 'yaml'
|
8
|
+
require 'etc'
|
9
|
+
|
10
|
+
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
|
11
|
+
require 'mongrel'
|
12
|
+
require 'mongrel/rails'
|
13
|
+
|
14
|
+
Mongrel::Gems.require 'gem_plugin'
|
15
|
+
|
16
|
+
# require 'ruby-debug'
|
17
|
+
# Debugger.start
|
18
|
+
|
19
|
+
module Mongrel
|
20
|
+
class Start < GemPlugin::Plugin "/commands"
|
21
|
+
include Mongrel::Command::Base
|
22
|
+
|
23
|
+
def configure
|
24
|
+
options [
|
25
|
+
["-e", "--environment ENV", "Rails environment to run as", :@environment, ENV['RAILS_ENV'] || "development"],
|
26
|
+
["-d", "--daemonize", "Run daemonized in the background", :@daemon, false],
|
27
|
+
['-p', '--port PORT', "Which port to bind to", :@port, 3000],
|
28
|
+
['-a', '--address ADDR', "Address to bind to", :@address, "0.0.0.0"],
|
29
|
+
['-l', '--log FILE', "Where to write log messages", :@log_file, "log/mongrel.log"],
|
30
|
+
['-P', '--pid FILE', "Where to write the PID", :@pid_file, "log/mongrel.pid"],
|
31
|
+
['-n', '--num-processors INT', "Number of processors active before clients denied", :@num_processors, 1024],
|
32
|
+
['-o', '--timeout TIME', "Time to wait (in seconds) before killing a stalled thread", :@timeout, 60],
|
33
|
+
['-t', '--throttle TIME', "Time to pause (in hundredths of a second) between accepting clients", :@throttle, 0],
|
34
|
+
['-m', '--mime PATH', "A YAML file that lists additional MIME types", :@mime_map, nil],
|
35
|
+
['-c', '--chdir PATH', "Change to dir before starting (will be expanded)", :@cwd, Dir.pwd],
|
36
|
+
['-r', '--root PATH', "Set the document root (default 'public')", :@docroot, "public"],
|
37
|
+
['-B', '--debug', "Enable debugging mode", :@debug, false],
|
38
|
+
['-C', '--config PATH', "Use a config file", :@config_file, nil],
|
39
|
+
['-S', '--script PATH', "Load the given file as an extra config script", :@config_script, nil],
|
40
|
+
['-G', '--generate PATH', "Generate a config file for use with -C", :@generate, nil],
|
41
|
+
['', '--user USER', "User to run as", :@user, nil],
|
42
|
+
['', '--group GROUP', "Group to run as", :@group, nil],
|
43
|
+
['', '--prefix PATH', "URL prefix for Rails app", :@prefix, nil]
|
44
|
+
]
|
45
|
+
end
|
46
|
+
|
47
|
+
def validate
|
48
|
+
if @config_file
|
49
|
+
valid_exists?(@config_file, "Config file not there: #@config_file")
|
50
|
+
return false unless @valid
|
51
|
+
@config_file = File.expand_path(@config_file)
|
52
|
+
load_config
|
53
|
+
return false unless @valid
|
54
|
+
end
|
55
|
+
|
56
|
+
@cwd = File.expand_path(@cwd)
|
57
|
+
valid_dir? @cwd, "Invalid path to change to during daemon mode: #@cwd"
|
58
|
+
|
59
|
+
# Change there to start, then we'll have to come back after daemonize
|
60
|
+
Dir.chdir(@cwd)
|
61
|
+
|
62
|
+
valid?(@prefix[0] == ?/ && @prefix[-1] != ?/, "Prefix must begin with / and not end in /") if @prefix
|
63
|
+
valid_dir? File.dirname(@log_file), "Path to log file not valid: #@log_file"
|
64
|
+
valid_dir? File.dirname(@pid_file), "Path to pid file not valid: #@pid_file"
|
65
|
+
valid_dir? @docroot, "Path to docroot not valid: #@docroot"
|
66
|
+
valid_exists? @mime_map, "MIME mapping file does not exist: #@mime_map" if @mime_map
|
67
|
+
valid_exists? @config_file, "Config file not there: #@config_file" if @config_file
|
68
|
+
valid_dir? File.dirname(@generate), "Problem accessing directory to #@generate" if @generate
|
69
|
+
valid_user? @user if @user
|
70
|
+
valid_group? @group if @group
|
71
|
+
|
72
|
+
return @valid
|
73
|
+
end
|
74
|
+
|
75
|
+
def run
|
76
|
+
if @generate
|
77
|
+
@generate = File.expand_path(@generate)
|
78
|
+
STDERR.puts "** Writing config to \"#@generate\"."
|
79
|
+
open(@generate, "w") {|f| f.write(settings.to_yaml) }
|
80
|
+
STDERR.puts "** Finished. Run \"mongrel_rails start -C #@generate\" to use the config file."
|
81
|
+
exit 0
|
82
|
+
end
|
83
|
+
|
84
|
+
config = Mongrel::Rails::RailsConfigurator.new(settings) do
|
85
|
+
if defaults[:daemon]
|
86
|
+
if File.exist? defaults[:pid_file]
|
87
|
+
log "!!! PID file #{defaults[:pid_file]} already exists. Mongrel could be running already. Check your #{defaults[:log_file]} for errors."
|
88
|
+
log "!!! Exiting with error. You must stop mongrel and clear the .pid before I'll attempt a start."
|
89
|
+
exit 1
|
90
|
+
end
|
91
|
+
|
92
|
+
daemonize
|
93
|
+
log "Daemonized, any open files are closed. Look at #{defaults[:pid_file]} and #{defaults[:log_file]} for info."
|
94
|
+
log "Settings loaded from #{@config_file} (they override command line)." if @config_file
|
95
|
+
end
|
96
|
+
|
97
|
+
log "Starting Mongrel listening at #{defaults[:host]}:#{defaults[:port]}"
|
98
|
+
|
99
|
+
listener do
|
100
|
+
mime = {}
|
101
|
+
if defaults[:mime_map]
|
102
|
+
log "Loading additional MIME types from #{defaults[:mime_map]}"
|
103
|
+
mime = load_mime_map(defaults[:mime_map], mime)
|
104
|
+
end
|
105
|
+
|
106
|
+
if defaults[:debug]
|
107
|
+
log "Installing debugging prefixed filters. Look in log/mongrel_debug for the files."
|
108
|
+
debug "/"
|
109
|
+
end
|
110
|
+
|
111
|
+
log "Starting Rails with #{defaults[:environment]} environment..."
|
112
|
+
log "Mounting Rails at #{defaults[:prefix]}..." if defaults[:prefix]
|
113
|
+
uri defaults[:prefix] || "/", :handler => rails(:mime => mime, :prefix => defaults[:prefix])
|
114
|
+
log "Rails loaded."
|
115
|
+
|
116
|
+
log "Loading any Rails specific GemPlugins"
|
117
|
+
load_plugins
|
118
|
+
|
119
|
+
if defaults[:config_script]
|
120
|
+
log "Loading #{defaults[:config_script]} external config script"
|
121
|
+
run_config(defaults[:config_script])
|
122
|
+
end
|
123
|
+
|
124
|
+
setup_rails_signals
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
config.run
|
129
|
+
config.log "Mongrel #{Mongrel::Const::MONGREL_VERSION} available at #{@address}:#{@port}"
|
130
|
+
|
131
|
+
if config.defaults[:daemon]
|
132
|
+
config.write_pid_file
|
133
|
+
else
|
134
|
+
config.log "Use CTRL-C to stop."
|
135
|
+
end
|
136
|
+
|
137
|
+
config.join
|
138
|
+
|
139
|
+
if config.needs_restart
|
140
|
+
if RUBY_PLATFORM !~ /mswin/
|
141
|
+
cmd = "ruby #{__FILE__} start #{original_args.join(' ')}"
|
142
|
+
config.log "Restarting with arguments: #{cmd}"
|
143
|
+
config.stop(false, true)
|
144
|
+
config.remove_pid_file
|
145
|
+
|
146
|
+
if config.defaults[:daemon]
|
147
|
+
system cmd
|
148
|
+
else
|
149
|
+
STDERR.puts "Can't restart unless in daemon mode."
|
150
|
+
exit 1
|
151
|
+
end
|
152
|
+
else
|
153
|
+
config.log "Win32 does not support restarts. Exiting."
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def load_config
|
159
|
+
settings = {}
|
160
|
+
begin
|
161
|
+
settings = YAML.load_file(@config_file)
|
162
|
+
ensure
|
163
|
+
STDERR.puts "** Loading settings from #{@config_file} (they override command line)." unless @daemon || settings[:daemon]
|
164
|
+
end
|
165
|
+
|
166
|
+
settings[:includes] ||= ["mongrel"]
|
167
|
+
|
168
|
+
# Config file settings will override command line settings
|
169
|
+
settings.each do |key, value|
|
170
|
+
key = key.to_s
|
171
|
+
if config_keys.include?(key)
|
172
|
+
key = 'address' if key == 'host'
|
173
|
+
self.instance_variable_set("@#{key}", value)
|
174
|
+
else
|
175
|
+
failure "Unknown configuration setting: #{key}"
|
176
|
+
@valid = false
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def config_keys
|
182
|
+
@config_keys ||=
|
183
|
+
%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)
|
184
|
+
end
|
185
|
+
|
186
|
+
def settings
|
187
|
+
config_keys.inject({}) do |hash, key|
|
188
|
+
value = self.instance_variable_get("@#{key}")
|
189
|
+
key = 'host' if key == 'address'
|
190
|
+
hash[key.to_sym] ||= value
|
191
|
+
hash
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
def Mongrel::send_signal(signal, pid_file)
|
197
|
+
pid = open(pid_file).read.to_i
|
198
|
+
print "Sending #{signal} to Mongrel at PID #{pid}..."
|
199
|
+
begin
|
200
|
+
Process.kill(signal, pid)
|
201
|
+
rescue Errno::ESRCH
|
202
|
+
puts "Process does not exist. Not running."
|
203
|
+
end
|
204
|
+
|
205
|
+
puts "Done."
|
206
|
+
end
|
207
|
+
|
208
|
+
|
209
|
+
class Stop < GemPlugin::Plugin "/commands"
|
210
|
+
include Mongrel::Command::Base
|
211
|
+
|
212
|
+
def configure
|
213
|
+
options [
|
214
|
+
['-c', '--chdir PATH', "Change to dir before starting (will be expanded).", :@cwd, "."],
|
215
|
+
['-f', '--force', "Force the shutdown (kill -9).", :@force, false],
|
216
|
+
['-w', '--wait SECONDS', "Wait SECONDS before forcing shutdown", :@wait, "0"],
|
217
|
+
['-P', '--pid FILE', "Where the PID file is located.", :@pid_file, "log/mongrel.pid"]
|
218
|
+
]
|
219
|
+
end
|
220
|
+
|
221
|
+
def validate
|
222
|
+
@cwd = File.expand_path(@cwd)
|
223
|
+
valid_dir? @cwd, "Invalid path to change to during daemon mode: #@cwd"
|
224
|
+
|
225
|
+
Dir.chdir @cwd
|
226
|
+
|
227
|
+
valid_exists? @pid_file, "PID file #@pid_file does not exist. Not running?"
|
228
|
+
return @valid
|
229
|
+
end
|
230
|
+
|
231
|
+
def run
|
232
|
+
if @force
|
233
|
+
@wait.to_i.times do |waiting|
|
234
|
+
exit(0) if not File.exist? @pid_file
|
235
|
+
sleep 1
|
236
|
+
end
|
237
|
+
|
238
|
+
Mongrel::send_signal("KILL", @pid_file) if File.exist? @pid_file
|
239
|
+
else
|
240
|
+
Mongrel::send_signal("TERM", @pid_file)
|
241
|
+
end
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
|
246
|
+
class Restart < GemPlugin::Plugin "/commands"
|
247
|
+
include Mongrel::Command::Base
|
248
|
+
|
249
|
+
def configure
|
250
|
+
options [
|
251
|
+
['-c', '--chdir PATH', "Change to dir before starting (will be expanded)", :@cwd, '.'],
|
252
|
+
['-s', '--soft', "Do a soft restart rather than a process exit restart", :@soft, false],
|
253
|
+
['-P', '--pid FILE', "Where the PID file is located", :@pid_file, "log/mongrel.pid"]
|
254
|
+
]
|
255
|
+
end
|
256
|
+
|
257
|
+
def validate
|
258
|
+
@cwd = File.expand_path(@cwd)
|
259
|
+
valid_dir? @cwd, "Invalid path to change to during daemon mode: #@cwd"
|
260
|
+
|
261
|
+
Dir.chdir @cwd
|
262
|
+
|
263
|
+
valid_exists? @pid_file, "PID file #@pid_file does not exist. Not running?"
|
264
|
+
return @valid
|
265
|
+
end
|
266
|
+
|
267
|
+
def run
|
268
|
+
if @soft
|
269
|
+
Mongrel::send_signal("HUP", @pid_file)
|
270
|
+
else
|
271
|
+
Mongrel::send_signal("USR2", @pid_file)
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
|
278
|
+
GemPlugin::Manager.instance.load "mongrel" => GemPlugin::INCLUDE, "rails" => GemPlugin::EXCLUDE
|
279
|
+
|
280
|
+
|
281
|
+
if not Mongrel::Command::Registry.instance.run ARGV
|
282
|
+
exit 1
|
283
|
+
end
|