mongrel_status 0.1

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.
Files changed (8) hide show
  1. data/COPYING +504 -0
  2. data/LICENSE +504 -0
  3. data/README +154 -0
  4. data/Rakefile +30 -0
  5. data/lib/init.rb +30 -0
  6. data/test/test_empty.rb +7 -0
  7. data/tools/rakehelp.rb +111 -0
  8. metadata +68 -0
data/README ADDED
@@ -0,0 +1,154 @@
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
4
+ web applications. It is not particular to any framework, and is intended to
5
+ be just enough to get a web application running behind a more complete and robust
6
+ web server.
7
+
8
+ What makes Mongrel so fast is the careful use of a C extension to provide fast
9
+ HTTP 1.1 protocol parsing and fast URI lookup. This combination makes the server
10
+ scream without too many portability issues.
11
+
12
+ == Status
13
+
14
+ The 0.3.6 release supports Ruby On Rails much better than previously, and also
15
+ sports the beginning of a command and plugin infrastructure. There is now a more
16
+ complete CGIWrapper that handles most of the CGI usage, but still doesn't do the
17
+ MIME decoding or file upload/send (it leaves that to CGI). Finally, there's a
18
+ great mongrel_rails_service script for running under Win32 as a service.
19
+
20
+ After you've installed (either with gem install mongrel or via source) you should
21
+ have the mongrel_rails command available in your PATH. Then you just do the following:
22
+
23
+ > cd myrailsapp
24
+ > mongrel_rails start
25
+
26
+ This will start it in the foreground so you can play with it. It runs your application
27
+ in production mode. To get help do:
28
+
29
+ > mongrel_rails start -h
30
+
31
+ Finally, you can then start in background mode (probably won't work in win32):
32
+
33
+ > mongrel_rails start -d
34
+
35
+ And you can stop it whenever you like with:
36
+
37
+ > mongrel_rails stop
38
+
39
+ All of which should be done from your application's directory. It writes the
40
+ PID of the process you ran into log/mongrel.pid.
41
+
42
+ There are also many more new options for configuring the rails runner including
43
+ changing to a different directory, adding more MIME types, and setting processor
44
+ threads and timeouts.
45
+
46
+
47
+ === Win32 Service Support
48
+
49
+ Mongrel now has support for running as a Win32 service right out of the
50
+ box. The support is still rough but works well enough that we decided
51
+ to release it. You can thank Luis Lavena for working on this and making
52
+ it so nice.
53
+
54
+ After you do the gem install, find a Rails application you want to run
55
+ and do:
56
+
57
+ $ mongrel_rails_service install -n myapp \
58
+ -r c:\my\path\to\myapp -p 4000 -e production
59
+ $ mongrel_rails_service start -n myapp
60
+
61
+ Now hit the port and poof, works. *Stopping the service is a little problematic right now.*
62
+
63
+ If you run into an app that's not running right, my suggestion is to run it with
64
+ the regular mongrel_rails runner:
65
+
66
+ $ cd c:\my\path\to\myapp
67
+ $ mongrel_rails start -p 4500
68
+
69
+ Since that will spit out error messages and stuff to the console. *Use CTRL-Pause/Break to stop.*
70
+
71
+
72
+ == Install
73
+
74
+ It doesn't explicitly require Camping, but if you want to run the examples/camping/
75
+ examples then you'll need to install Camping 1.2 at least (and redcloth I think).
76
+ These are all available from RubyGems.
77
+
78
+ The library consists of a C extension so you'll need a C compiler or at least a friend
79
+ who can build it for you.
80
+
81
+ Finally, the source includes a setup.rb for those who hate RubyGems.
82
+
83
+
84
+ == Usage
85
+
86
+ The examples/simpletest.rb file has the following code as the simplest
87
+ example:
88
+
89
+ require 'mongrel'
90
+
91
+ class SimpleHandler < Mongrel::HttpHandler
92
+ def process(request, response)
93
+ response.start(200) do |head,out|
94
+ head["Content-Type"] = "text/plain"
95
+ out.write("hello!\n")
96
+ end
97
+ end
98
+ end
99
+
100
+ h = Mongrel::HttpServer.new("0.0.0.0", "3000")
101
+ h.register("/test", SimpleHandler.new)
102
+ h.register("/files", Mongrel::DirHandler.new("."))
103
+ h.run.join
104
+
105
+ If you run this and access port 3000 with a browser it will say
106
+ "hello!". If you access it with any url other than "/test" it will
107
+ give a simple 404. Check out the Mongrel::Error404Handler for a
108
+ basic way to give a more complex 404 message.
109
+
110
+ This also shows the DirHandler with directory listings. This is still
111
+ rough but it should work for basic hosting. *File extension to mime
112
+ type mapping is missing though.*
113
+
114
+
115
+ == Speed
116
+
117
+ Like previous releases 0.3.1 continues the trend of making things
118
+ as fast as possible. It currently might be a little slower than
119
+ other releases but should hold up pretty good against at least
120
+ WEBrick (especially when running Rails).
121
+
122
+ As before you can control the number of processor threads (and thus
123
+ ActiveRecord database connections) with:
124
+
125
+ h = Mongrel::HttpServer.new("0.0.0.0", "3000", 40)
126
+
127
+ Which will make 40 thread processors. Right now the optimal setting is up in
128
+ the air, but 20 seemed to be about the sweet spot on my systems. The
129
+ limited processors also means that you can use ActiveRecord as-is and it will
130
+ create a matching database connection for each processor thread. More on
131
+ this in future releases.
132
+
133
+
134
+ == The Future
135
+
136
+ With the core of Mongrel completed I'm now turning to the next set of features
137
+ to make Mongrel useful for hosting web applications in a heavily utilized
138
+ production environment. Right now I'm looking at:
139
+
140
+ * An idea I've had for an insane caching handler which could speed up quite a
141
+ few deployments.
142
+
143
+ Overall though the goal of Mongrel is to be just enough HTTP to serve a Ruby
144
+ web application that sits behind a more complete web server. Everything
145
+ in the next will focus on actually hosting the major web frameworks for Ruby:
146
+
147
+ * Camping -- because it's already done (thanks Why).
148
+ * Ruby on Rails -- that's where my bread is buttered right now.
149
+ * Nitro -- Nitro folks have already hooked this up and started using it. Nice.
150
+ * ????? -- Others people might be interested in.
151
+
152
+ == Contact
153
+
154
+ E-mail zedshaw at zedshaw.com and I'll help. Comments about the API are welcome.
data/Rakefile ADDED
@@ -0,0 +1,30 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/clean'
4
+ require 'rake/gempackagetask'
5
+ require 'rake/rdoctask'
6
+ require 'tools/rakehelp'
7
+ require 'fileutils'
8
+ include FileUtils
9
+
10
+ setup_tests
11
+ setup_clean ["pkg", "lib/*.bundle", "*.gem", ".config"]
12
+
13
+ setup_rdoc ['README', 'LICENSE', 'COPYING', 'lib/**/*.rb', 'doc/**/*.rdoc']
14
+
15
+ desc "Does a full compile, test run"
16
+ task :default => [:test, :package]
17
+
18
+ version="0.1"
19
+ summary = "A sample plugin that reports the status of mongrel."
20
+ test_file = "test/test_empty.rb"
21
+ author="Zed A. Shaw"
22
+ name="mongrel_status"
23
+ scripts=[]
24
+
25
+ setup_gem(name, version, author, summary, scripts, test_file) do |spec|
26
+ spec.add_dependency('mongrel', '>= 0.3.9')
27
+ spec.add_dependency('gem_plugin', '>= 0.1')
28
+ spec.autorequire = 'init.rb'
29
+ end
30
+
data/lib/init.rb ADDED
@@ -0,0 +1,30 @@
1
+ require 'mongrel'
2
+ require 'gem_plugin'
3
+
4
+ class Status < GemPlugin::Plugin "/commands"
5
+ include Mongrel::Command::Base
6
+
7
+ def configure
8
+ options [
9
+ ['-c', '--chdir PATH', "Change to dir before starting (will be expanded)", :@cwd, Dir.pwd],
10
+ ['-P', '--pid FILE', "Where to write the PID", :@pid_file, "log/mongrel.pid"]
11
+ ]
12
+ end
13
+
14
+ def validate
15
+ @cwd = File.expand_path(@cwd)
16
+ valid_dir? @cwd, "Invalid path to change to during daemon mode: #@cwd"
17
+
18
+ @pid_file = File.join(@cwd,@pid_file)
19
+ valid_exists? @pid_file, "PID file #@pid_file does not exist. Not running?"
20
+
21
+ return @valid
22
+ end
23
+
24
+
25
+ def run
26
+ pid = open(@pid_file) {|f| f.read }
27
+ puts "Mongrel status:"
28
+ puts "PID: #{pid}"
29
+ end
30
+ end
@@ -0,0 +1,7 @@
1
+ require 'test/unit'
2
+
3
+ class EmptyTest < Test::Unit::TestCase
4
+ def test_nothing
5
+ end
6
+ end
7
+
data/tools/rakehelp.rb ADDED
@@ -0,0 +1,111 @@
1
+
2
+ def make(makedir)
3
+ Dir.chdir(makedir) do
4
+ sh(PLATFORM =~ /win32/ ? 'nmake' : 'make')
5
+ end
6
+ end
7
+
8
+
9
+ def extconf(dir)
10
+ Dir.chdir(dir) do ruby "extconf.rb" end
11
+ end
12
+
13
+
14
+ def setup_tests
15
+ Rake::TestTask.new do |t|
16
+ t.libs << "test"
17
+ t.test_files = FileList['test/test*.rb']
18
+ t.verbose = true
19
+ end
20
+ end
21
+
22
+
23
+ def setup_clean otherfiles
24
+ files = ['build/*', '**/*.o', '**/*.so', '**/*.a', 'lib/*-*', '**/*.log'] + otherfiles
25
+ CLEAN.include(files)
26
+ end
27
+
28
+
29
+ def setup_rdoc files
30
+ Rake::RDocTask.new do |rdoc|
31
+ rdoc.rdoc_dir = 'doc/rdoc'
32
+ rdoc.options << '--line-numbers'
33
+ rdoc.rdoc_files.add(files)
34
+ end
35
+ end
36
+
37
+
38
+ def setup_extension(dir, extension)
39
+ ext = "ext/#{dir}"
40
+ ext_so = "#{ext}/#{extension}.#{Config::CONFIG['DLEXT']}"
41
+ ext_files = FileList[
42
+ "#{ext}/*.c",
43
+ "#{ext}/*.h",
44
+ "#{ext}/extconf.rb",
45
+ "#{ext}/Makefile",
46
+ "lib"
47
+ ]
48
+
49
+ task "lib" do
50
+ directory "lib"
51
+ end
52
+
53
+ desc "Builds just the #{extension} extension"
54
+ task extension.to_sym => ["#{ext}/Makefile", ext_so ]
55
+
56
+ file "#{ext}/Makefile" => ["#{ext}/extconf.rb"] do
57
+ extconf "#{ext}"
58
+ end
59
+
60
+ file ext_so => ext_files do
61
+ make "#{ext}"
62
+ cp ext_so, "lib"
63
+ end
64
+ end
65
+
66
+
67
+ def base_gem_spec(pkg_name, pkg_version, author, summary, executables, test_file)
68
+ pkg_version = pkg_version
69
+ pkg_name = pkg_name
70
+ pkg_file_name = "#{pkg_name}-#{pkg_version}"
71
+ Gem::Specification.new do |s|
72
+ s.name = pkg_name
73
+ s.version = pkg_version
74
+ s.required_ruby_version = '>= 1.8.3'
75
+ s.platform = Gem::Platform::RUBY
76
+ s.author = author
77
+ s.summary = summary
78
+ s.test_file = test_file
79
+ s.has_rdoc = true
80
+ s.extra_rdoc_files = [ "README" ]
81
+
82
+ s.files = %w(COPYING LICENSE README Rakefile) +
83
+ Dir.glob("{bin,doc/rdoc,test,lib}/**/*") +
84
+ Dir.glob("ext/**/*.{h,c,rb}") +
85
+ Dir.glob("examples/**/*.rb") +
86
+ Dir.glob("tools/*.rb")
87
+
88
+ s.require_path = "lib"
89
+ s.extensions = FileList["ext/**/extconf.rb"].to_a
90
+
91
+ s.executables = executables
92
+ s.bindir = "bin"
93
+ end
94
+ end
95
+
96
+ def setup_gem(pkg_name, pkg_version, author, summary, executables, test_file)
97
+ spec = base_gem_spec(pkg_name, pkg_version, author, summary, executables, test_file)
98
+ yield spec if block_given?
99
+
100
+ Rake::GemPackageTask.new(spec) do |p|
101
+ p.gem_spec = spec
102
+ p.need_tar = true
103
+ end
104
+ end
105
+
106
+ def setup_win32_gem(pkg_name, pkg_version, author, summary, executables, test_file)
107
+ spec = base_gem_spec(pkg_name, pkg_version, author, summary, executables, test_file)
108
+ yield spec if block_given?
109
+
110
+ Gem::Builder.new(spec).build
111
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.11
3
+ specification_version: 1
4
+ name: mongrel_status
5
+ version: !ruby/object:Gem::Version
6
+ version: "0.1"
7
+ date: 2006-03-06 00:00:00 -05:00
8
+ summary: A sample plugin that reports the status of mongrel.
9
+ require_paths:
10
+ - lib
11
+ email:
12
+ homepage:
13
+ rubyforge_project:
14
+ description:
15
+ autorequire: init.rb
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.8.3
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ authors:
29
+ - Zed A. Shaw
30
+ files:
31
+ - COPYING
32
+ - LICENSE
33
+ - README
34
+ - Rakefile
35
+ - test/test_empty.rb
36
+ - lib/init.rb
37
+ - tools/rakehelp.rb
38
+ test_files:
39
+ - test/test_empty.rb
40
+ rdoc_options: []
41
+
42
+ extra_rdoc_files:
43
+ - README
44
+ executables: []
45
+
46
+ extensions: []
47
+
48
+ requirements: []
49
+
50
+ dependencies:
51
+ - !ruby/object:Gem::Dependency
52
+ name: mongrel
53
+ version_requirement:
54
+ version_requirements: !ruby/object:Gem::Version::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: 0.3.9
59
+ version:
60
+ - !ruby/object:Gem::Dependency
61
+ name: gem_plugin
62
+ version_requirement:
63
+ version_requirements: !ruby/object:Gem::Version::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0.1"
68
+ version: