mongrel 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/README +4 -3
  2. data/Rakefile +7 -5
  3. data/bin/mongrel_rails +5 -4
  4. data/bin/mongrel_rails_service +237 -0
  5. data/bin/mongrel_rails_svc +194 -0
  6. data/doc/rdoc/classes/Mongrel.html +1 -4
  7. data/doc/rdoc/classes/Mongrel/Const.html +13 -3
  8. data/doc/rdoc/classes/Mongrel/HeaderOut.html +10 -10
  9. data/doc/rdoc/classes/Mongrel/HeaderOut.src/{M000033.html → M000028.html} +4 -4
  10. data/doc/rdoc/classes/Mongrel/HeaderOut.src/{M000034.html → M000029.html} +7 -7
  11. data/doc/rdoc/classes/Mongrel/HttpRequest.html +5 -5
  12. data/doc/rdoc/classes/Mongrel/HttpRequest.src/M000041.html +39 -0
  13. data/doc/rdoc/classes/Mongrel/HttpResponse.html +36 -36
  14. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000034.html +21 -0
  15. data/doc/rdoc/classes/Mongrel/HttpResponse.src/{M000041.html → M000035.html} +6 -6
  16. data/doc/rdoc/classes/Mongrel/HttpResponse.src/{M000042.html → M000036.html} +5 -5
  17. data/doc/rdoc/classes/Mongrel/HttpResponse.src/{M000043.html → M000037.html} +5 -5
  18. data/doc/rdoc/classes/Mongrel/HttpResponse.src/{M000044.html → M000038.html} +6 -6
  19. data/doc/rdoc/classes/Mongrel/HttpResponse.src/{M000045.html → M000039.html} +6 -6
  20. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000040.html +7 -8
  21. data/doc/rdoc/classes/Mongrel/HttpServer.html +47 -28
  22. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000022.html +33 -0
  23. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000023.html +57 -0
  24. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000024.html +46 -0
  25. data/doc/rdoc/classes/Mongrel/HttpServer.src/{M000031.html → M000025.html} +4 -4
  26. data/doc/rdoc/classes/Mongrel/HttpServer.src/{M000032.html → M000026.html} +4 -4
  27. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000027.html +19 -0
  28. data/doc/rdoc/classes/Mongrel/{HttpHandler.html → StopServer.html} +4 -33
  29. data/doc/rdoc/classes/Mongrel/URIClassifier.html +22 -23
  30. data/doc/rdoc/classes/Mongrel/URIClassifier.src/{M000035.html → M000030.html} +0 -0
  31. data/doc/rdoc/classes/Mongrel/URIClassifier.src/{M000036.html → M000031.html} +0 -0
  32. data/doc/rdoc/classes/Mongrel/URIClassifier.src/{M000037.html → M000032.html} +0 -0
  33. data/doc/rdoc/classes/Mongrel/URIClassifier.src/{M000038.html → M000033.html} +0 -0
  34. data/doc/rdoc/created.rid +1 -1
  35. data/doc/rdoc/files/README.html +9 -7
  36. data/doc/rdoc/files/lib/mongrel_rb.html +3 -3
  37. data/doc/rdoc/fr_class_index.html +1 -4
  38. data/doc/rdoc/fr_method_index.html +20 -37
  39. data/examples/mongrel_simple_ctrl.rb +92 -0
  40. data/examples/mongrel_simple_service.rb +116 -0
  41. data/examples/simpletest.rb +3 -1
  42. data/ext/http11/http11_parser.c +176 -263
  43. data/lib/mongrel.rb +56 -343
  44. data/lib/mongrel/cgi.rb +147 -0
  45. data/lib/mongrel/handlers.rb +180 -0
  46. metadata +28 -46
  47. data/doc/rdoc/classes/Mongrel/CGIWrapper.html +0 -346
  48. data/doc/rdoc/classes/Mongrel/CGIWrapper.src/M000047.html +0 -24
  49. data/doc/rdoc/classes/Mongrel/CGIWrapper.src/M000048.html +0 -48
  50. data/doc/rdoc/classes/Mongrel/CGIWrapper.src/M000049.html +0 -34
  51. data/doc/rdoc/classes/Mongrel/CGIWrapper.src/M000050.html +0 -27
  52. data/doc/rdoc/classes/Mongrel/CGIWrapper.src/M000051.html +0 -26
  53. data/doc/rdoc/classes/Mongrel/CGIWrapper.src/M000052.html +0 -18
  54. data/doc/rdoc/classes/Mongrel/CGIWrapper.src/M000053.html +0 -18
  55. data/doc/rdoc/classes/Mongrel/CGIWrapper.src/M000054.html +0 -18
  56. data/doc/rdoc/classes/Mongrel/CGIWrapper.src/M000055.html +0 -19
  57. data/doc/rdoc/classes/Mongrel/DirHandler.html +0 -283
  58. data/doc/rdoc/classes/Mongrel/DirHandler.src/M000022.html +0 -20
  59. data/doc/rdoc/classes/Mongrel/DirHandler.src/M000023.html +0 -42
  60. data/doc/rdoc/classes/Mongrel/DirHandler.src/M000024.html +0 -40
  61. data/doc/rdoc/classes/Mongrel/DirHandler.src/M000025.html +0 -31
  62. data/doc/rdoc/classes/Mongrel/DirHandler.src/M000026.html +0 -38
  63. data/doc/rdoc/classes/Mongrel/DirHandler.src/M000027.html +0 -18
  64. data/doc/rdoc/classes/Mongrel/Error404Handler.html +0 -171
  65. data/doc/rdoc/classes/Mongrel/Error404Handler.src/M000056.html +0 -18
  66. data/doc/rdoc/classes/Mongrel/Error404Handler.src/M000057.html +0 -18
  67. data/doc/rdoc/classes/Mongrel/HttpHandler.src/M000039.html +0 -17
  68. data/doc/rdoc/classes/Mongrel/HttpRequest.src/M000058.html +0 -31
  69. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000046.html +0 -20
  70. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000028.html +0 -38
  71. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000029.html +0 -64
  72. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000030.html +0 -23
data/README CHANGED
@@ -11,9 +11,10 @@ scream without too many portability issues.
11
11
 
12
12
  == Status
13
13
 
14
- The 0.3.2 release supports Ruby On Rails much better than previously, and also
15
- sports the beginning of a command and plugin infrastructure. This last part
16
- isn't documented yet.
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).
17
18
 
18
19
  After you've installed (either with gem install mongrel or via source) you should
19
20
  have the mongrel_rails command available in your PATH. Then you just do the following:
data/Rakefile CHANGED
@@ -30,22 +30,24 @@ end
30
30
 
31
31
  setup_extension("http11", "http11")
32
32
 
33
- version="0.3.5"
33
+ version="0.3.6"
34
34
  summary = "A small fast HTTP library and server that runs Rails, Camping, and Nitro apps."
35
35
  test_file = "test/test_ws.rb"
36
36
  author="Zed A. Shaw"
37
37
  name="mongrel"
38
+ scripts=['mongrel_rails']
38
39
 
39
- setup_gem(name, version, author, summary, ['mongrel_rails'], test_file) do |spec|
40
+ setup_gem(name, version, author, summary, scripts, test_file) do |spec|
40
41
  spec.add_dependency('daemons', '>= 0.4.2')
41
42
  end
42
43
 
43
44
  desc "Build a binary gem for Win32"
44
- task :win32_gem => [:clean, :compile, :test, :package_win32]
45
+ task :win32_gem => [:clean, :compile, :test, :rerdoc, :package_win32]
45
46
 
47
+ scripts_win32 = scripts + ['mongrel_rails_service','mongrel_rails_svc']
46
48
  task :package_win32 do
47
- setup_win32_gem(name, version, version, summary, ['mongrel_rails'], test_file) do |spec|
48
- spec.add_dependency('daemons', '>= 0.4.2')
49
+ setup_win32_gem(name, version, version, summary, scripts_win32, test_file) do |spec|
50
+ spec.add_dependency('win32-service', '>= 0.5.0')
49
51
  spec.files << 'ext/http11/http11.so'
50
52
  spec.extensions = []
51
53
  spec.platform = Gem::Platform::WIN32
@@ -1,6 +1,5 @@
1
1
  require 'rubygems'
2
2
  require 'mongrel'
3
- require 'daemons/daemonize'
4
3
  require 'mongrel/command'
5
4
 
6
5
 
@@ -77,7 +76,9 @@ class StartCommand < Mongrel::Command::Command
77
76
 
78
77
  def daemonize
79
78
  # save this for later since daemonize will hose it
80
- if @daemon
79
+ if @daemon and RUBY_PLATFORM !~ /mswin/
80
+ require 'daemons/daemonize'
81
+
81
82
  puts "Started Mongrel server in #@environment mode at #@address:#@port"
82
83
  Daemonize.daemonize(log_file=File.join(@cwd, @log_file))
83
84
 
@@ -120,12 +121,14 @@ class StartCommand < Mongrel::Command::Command
120
121
  server = Mongrel::HttpServer.new(@address, @port, @num_procs.to_i, @timeout.to_i)
121
122
  server.register("/", rails)
122
123
  server.run
124
+ trap("INT") { server.stop }
123
125
 
124
126
  begin
125
127
  puts "Server ready."
126
128
  server.acceptor.join
127
129
  rescue Interrupt
128
130
  puts "Interrupted."
131
+ raise
129
132
  end
130
133
  end
131
134
 
@@ -173,6 +176,4 @@ class StopCommand < Mongrel::Command::Command
173
176
  end
174
177
 
175
178
 
176
-
177
-
178
179
  Mongrel::Command::Registry.instance.run ARGV
@@ -0,0 +1,237 @@
1
+ ###############################################
2
+ # mongrel_rails_service
3
+ #
4
+ # Control script for Rails powered by Mongrel
5
+ #
6
+ # WARNING: stop command still doesn't work with rails!
7
+ ###############################################
8
+ require 'rubygems'
9
+ require 'mongrel'
10
+ require 'mongrel/command'
11
+
12
+ require 'win32/service'
13
+ include Win32
14
+
15
+ module GenericCommand
16
+ def configure
17
+ options [
18
+ ['-n', '--name SVC_NAME', "Required name for the service to be registered/installed.", :@svc_name, nil],
19
+ ]
20
+ end
21
+
22
+ def validate
23
+ valid? @svc_name != nil, "You must specify the service name to be uninstalled."
24
+
25
+ # We should validate service existance here, right Zed?
26
+ begin
27
+ valid? Service.exists?(@svc_name), "There is no service with that name, cannot proceed."
28
+ rescue
29
+ end
30
+
31
+ return @valid
32
+ end
33
+ end
34
+
35
+ class InstallCommand < Mongrel::Command::Command
36
+
37
+ # Default every option to nil so only the defined ones get passed to service
38
+ # (which will override ServiceCommand defaults).
39
+ def configure
40
+ options [
41
+ ['-n', '--name SVC_NAME', "Required name for the service to be registered/installed.", :@svc_name, nil],
42
+ ['-d', '--display SVC_DISPLAY', "Adjust the display name of the service.", :@svc_display, nil],
43
+ ['-r', '--root PATH', "Set the root path where your rails app resides.", :@rails_root, Dir.pwd],
44
+ ['-e', '--environment ENV', "Rails environment to run as", :@environment, 'production'],
45
+ ['-b', '--binding ADDR', "Address to bind to", :@ip, nil],
46
+ ['-p', '--port PORT', "Which port to bind to", :@port, 3000],
47
+ ['-m', '--mime PATH', "A YAML file that lists additional MIME types", :@mime_map, nil],
48
+ ['-P', '--num-procs INT', "Number of processor threads to use", :@num_procs, nil],
49
+ ['-t', '--timeout SECONDS', "Timeout all requests after SECONDS time", :@timeout, nil],
50
+ ]
51
+ end
52
+
53
+ # When we validate the options, we need to make sure the --root is actually RAILS_ROOT
54
+ # of the rails application we wanted to serve, because later "as service" no error
55
+ # show to trace this.
56
+ def validate
57
+ @rails_root = File.expand_path(@rails_root)
58
+
59
+ # start with the premise of app really exist.
60
+ app_exist = true
61
+ paths = %w{app config db log public}
62
+ paths.each do |path|
63
+ if !File.directory?(@rails_root + '/' + path)
64
+ app_exist = false
65
+ break
66
+ end
67
+ end
68
+
69
+ valid? @svc_name != nil, "You must specify a valid service name to install."
70
+ valid? app_exist == true, "The root of rails app isn't valid, please verify."
71
+ valid_exists? @mime_map, "MIME mapping file does not exist: #@mime_map" if @mime_map
72
+
73
+ # We should validate service existance here, right Zed?
74
+ begin
75
+ valid? !Service.exists?(@svc_name), "The service already exist, please uninstall it first."
76
+ rescue
77
+ end
78
+
79
+ # Expand to get full path for mime-types file
80
+ @mime_map = File.Expand_path(@mime_map) if @mime_map
81
+
82
+ # default service display to service name
83
+ @svc_display = @svc_name if !@svc_display
84
+
85
+ return @valid
86
+ end
87
+
88
+ def build_params
89
+ # build the parameters that will be used when register/install the service
90
+ @params = ""
91
+
92
+ # add "service" command
93
+ @params << "service "
94
+
95
+ # rails_root, must be quoted to support long_names
96
+ @params << "-r \"#{@rails_root}\" "
97
+
98
+ # environment
99
+ @params << "-e #{@environment} " if @environment
100
+
101
+ # binding
102
+ @params << "-b #{@ip} " if @ip
103
+
104
+ # port
105
+ @params << "-p #{@port.to_i} " if @port
106
+
107
+ # mime
108
+ @params << "-m #{@mime_map} " if @mime_map
109
+
110
+ # num_procs
111
+ @params << "-P #{@num_procs.to_i} " if @num_procs
112
+
113
+ # timeout
114
+ @params << "-t #{@timeout.to_i} " if @timeout
115
+ end
116
+
117
+ def install_service
118
+ # use rbconfig to get the path to bin ruby.exe
119
+ require 'rbconfig'
120
+
121
+ # ruby.exe instead of rubyw.exe due a exception raised when stoping the service!
122
+ binary_path = ""
123
+ binary_path << '"' << Config::CONFIG['bindir'] << '/ruby.exe' << '" '
124
+
125
+ # add service_script
126
+ service_script = File.expand_path(File.dirname(__FILE__) + '/mongrel_rails_svc')
127
+ binary_path << '"' << service_script << '" '
128
+
129
+ # now add the parameters to it.
130
+ binary_path << @params
131
+
132
+ puts "Installing service with these options:"
133
+ puts "service name: " << @svc_name
134
+ puts "service display: " << @svc_display
135
+
136
+ puts "RAILS_ROOT: " << @rails_root
137
+ puts "RAILS_ENV: " << @environment if @environment
138
+ puts "binding: " << @ip if @ip
139
+ puts "port: " << @port.to_s if @port
140
+
141
+ puts "mime_map: " << @mime_map if @mime_map
142
+ puts "num_procs: " << @num_procs.to_s if @num_procs
143
+ puts "timeout: " << @timeout.to_s if @timeout
144
+
145
+ puts "ruby.exe: " << Config::CONFIG['bindir'] << '/ruby.exe'
146
+ puts "service script: " << service_script
147
+ puts
148
+
149
+ svc = Service.new
150
+ begin
151
+ svc.create_service{ |s|
152
+ s.service_name = @svc_name
153
+ s.display_name = @svc_display
154
+ s.binary_path_name = binary_path
155
+ s.dependencies = []
156
+ }
157
+ puts "#{@svc_display} service installed."
158
+ rescue ServiceError => err
159
+ puts "There was a problem installing the service:"
160
+ puts err
161
+ end
162
+ svc.close
163
+ end
164
+
165
+ def run
166
+ build_params
167
+ install_service
168
+ end
169
+ end
170
+
171
+ class DeleteCommand < Mongrel::Command::Command
172
+ include GenericCommand
173
+
174
+ def run
175
+ display_name = Service.getdisplayname(@svc_name)
176
+
177
+ begin
178
+ Service.stop(@svc_name)
179
+ rescue
180
+ end
181
+ begin
182
+ Service.delete(@svc_name)
183
+ rescue
184
+ end
185
+ puts "#{display_name} service deleted."
186
+ end
187
+ end
188
+
189
+ class StartCommand < Mongrel::Command::Command
190
+ include GenericCommand
191
+
192
+ def run
193
+ display_name = Service.getdisplayname(@svc_name)
194
+
195
+ begin
196
+ Service.start(@svc_name)
197
+ started = false
198
+ while started == false
199
+ s = Service.status(@svc_name)
200
+ started = true if s.current_state == "running"
201
+ break if started == true
202
+ puts "One moment, " + s.current_state
203
+ sleep 1
204
+ end
205
+ puts "#{display_name} service started"
206
+ rescue ServiceError => err
207
+ puts "There was a problem starting the service:"
208
+ puts err
209
+ end
210
+ end
211
+ end
212
+
213
+ class StopCommand < Mongrel::Command::Command
214
+ include GenericCommand
215
+
216
+ def run
217
+ display_name = Service.getdisplayname(@svc_name)
218
+
219
+ begin
220
+ Service.stop(@svc_name)
221
+ stopped = false
222
+ while stopped == false
223
+ s = Service.status(@svc_name)
224
+ stopped = true if s.current_state == "stopped"
225
+ break if stopped == true
226
+ puts "One moment, " + s.current_state
227
+ sleep 1
228
+ end
229
+ puts "#{display_name} service stopped"
230
+ rescue ServiceError => err
231
+ puts "There was a problem stopping the service:"
232
+ puts err
233
+ end
234
+ end
235
+ end
236
+
237
+ Mongrel::Command::Registry.instance.run ARGV
@@ -0,0 +1,194 @@
1
+ ###############################################
2
+ # mongrel_rails_svc
3
+ #
4
+ # This is where Win32::Daemon resides.
5
+ ###############################################
6
+ require 'rubygems'
7
+ require 'mongrel'
8
+
9
+ require 'optparse'
10
+
11
+ require 'win32/service'
12
+
13
+ DEBUG_LOG_FILE = File.expand_path(File.dirname(__FILE__) + '/debug.log')
14
+ #STDERR.reopen(DEBUG_LOG_FILE)
15
+
16
+ # There are need for SimpleHandler
17
+ require 'yaml'
18
+ require 'zlib'
19
+
20
+ class RailsHandler < Mongrel::HttpHandler
21
+
22
+ def initialize(dir, mime_map = {})
23
+ @files = Mongrel::DirHandler.new(dir,false)
24
+ @guard = Mutex.new
25
+
26
+ # register the requested mime types
27
+ mime_map.each {|k,v| Mongrel::DirHandler::add_mime_type(k,v) }
28
+ end
29
+
30
+ def process(request, response)
31
+ # not static, need to talk to rails
32
+ return if response.socket.closed?
33
+
34
+ if @files.can_serve(request.params["PATH_INFO"])
35
+ @files.process(request,response)
36
+ else
37
+ cgi = Mongrel::CGIWrapper.new(request, response)
38
+
39
+ begin
40
+ @guard.synchronize do
41
+ # Rails is not thread safe so must be run entirely within synchronize
42
+ Dispatcher.dispatch(cgi, ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, response.body)
43
+ end
44
+
45
+ # This finalizes the output using the proper HttpResponse way
46
+ cgi.out {""}
47
+ rescue Object => rails_error
48
+ STDERR.puts "calling Dispatcher.dispatch #{rails_error}"
49
+ STDERR.puts rails_error.backtrace.join("\n")
50
+ end
51
+ end
52
+ end
53
+
54
+ end
55
+
56
+ class SimpleHandler < Mongrel::HttpHandler
57
+ def process(request, response)
58
+ response.start do |head,out|
59
+ head["Content-Type"] = "text/html"
60
+ results = "<html><body>Your request:<br /><pre>#{request.params.to_yaml}</pre><a href=\"/files\">View the files.</a></body></html>"
61
+ if request.params["HTTP_ACCEPT_ENCODING"] == "gzip,deflate"
62
+ head["Content-Encoding"] = "deflate"
63
+ # send it back deflated
64
+ out << Zlib::Deflate.deflate(results)
65
+ else
66
+ # no gzip supported, send it back normal
67
+ out << results
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+ class RailsDaemon < Win32::Daemon
74
+ def initialize(ip, port, rails_root, docroot, environment, mime_map, num_procs, timeout)
75
+ File.open(DEBUG_LOG_FILE,"a+") { |f| f.puts("#{Time.now} - daemon_initialize entered") }
76
+
77
+ @ip = ip
78
+ @port = port
79
+ @rails_root = rails_root
80
+ @docroot = docroot
81
+ @environment = environment
82
+ @mime_map = mime_map
83
+ @num_procs = num_procs
84
+ @timeout = timeout
85
+
86
+ File.open(DEBUG_LOG_FILE,"a+") { |f| f.puts("#{Time.now} - daemon_initialize left") }
87
+ end
88
+
89
+ def load_mime_map
90
+ File.open(DEBUG_LOG_FILE,"a+") { |f| f.puts("#{Time.now} - load_mime_map entered") }
91
+
92
+ mime = {}
93
+
94
+ # configure any requested mime map
95
+ if @mime_map
96
+ puts "Loading additional MIME types from #@mime_map"
97
+ mime.merge!(YAML.load_file(@mime_map))
98
+
99
+ # check all the mime types to make sure they are the right format
100
+ mime.each {|k,v| puts "WARNING: MIME type #{k} must start with '.'" if k.index(".") != 0 }
101
+ end
102
+
103
+ File.open(DEBUG_LOG_FILE,"a+") { |f| f.puts("#{Time.now} - load_mime_map left") }
104
+
105
+ return mime
106
+ end
107
+
108
+ def configure_rails
109
+ File.open(DEBUG_LOG_FILE,"a+") { |f| f.puts("#{Time.now} - configure_rails entered") }
110
+
111
+ Dir.chdir(@rails_root)
112
+
113
+ ENV['RAILS_ENV'] = @environment
114
+ require File.join(@rails_root, 'config/environment')
115
+
116
+ # configure the rails handler
117
+ rails = RailsHandler.new(@docroot, load_mime_map)
118
+
119
+ File.open(DEBUG_LOG_FILE,"a+") { |f| f.puts("#{Time.now} - configure_rails left") }
120
+
121
+ return rails
122
+ end
123
+
124
+ def service_init
125
+ File.open(DEBUG_LOG_FILE,"a+") { |f| f.puts("#{Time.now} - service_init entered") }
126
+
127
+ @rails = configure_rails
128
+ #@rails = SimpleHandler.new
129
+
130
+ # start up mongrel with the right configurations
131
+ @server = Mongrel::HttpServer.new(@ip, @port, @num_procs.to_i, @timeout.to_i)
132
+ @server.register("/", @rails)
133
+
134
+ File.open(DEBUG_LOG_FILE,"a+") { |f| f.puts("#{Time.now} - service_init left") }
135
+ end
136
+
137
+ def service_main
138
+ File.open(DEBUG_LOG_FILE,"a+") { |f| f.puts("#{Time.now} - service_main entered") }
139
+
140
+ File.open(DEBUG_LOG_FILE,"a+") { |f| f.puts("#{Time.now} - server.run") }
141
+ @server.run
142
+
143
+ File.open(DEBUG_LOG_FILE,"a+") { |f| f.puts("#{Time.now} - while RUNNING") }
144
+ while state == RUNNING
145
+ sleep 1
146
+ end
147
+
148
+ File.open(DEBUG_LOG_FILE,"a+") { |f| f.puts("#{Time.now} - service_main left") }
149
+ end
150
+
151
+ def service_stop
152
+ File.open(DEBUG_LOG_FILE,"a+") { |f| f.puts("#{Time.now} - service_stop entered") }
153
+
154
+ #File.open(DEBUG_LOG_FILE,"a+") { |f| f.puts("#{Time.now} - server.stop") }
155
+ #@server.stop
156
+
157
+ File.open(DEBUG_LOG_FILE,"a+") { |f| f.puts("#{Time.now} - service_stop left") }
158
+ end
159
+ end
160
+
161
+
162
+ if ARGV[0] == 'service'
163
+ ARGV.shift
164
+
165
+ # default options
166
+ OPTIONS = {
167
+ :rails_root => Dir.pwd,
168
+ :environment => 'production',
169
+ :ip => '0.0.0.0',
170
+ :port => 3000,
171
+ :mime_map => nil,
172
+ :num_procs => 20,
173
+ :timeout => 120
174
+ }
175
+
176
+ ARGV.options do |opts|
177
+ opts.on('-r', '--root PATH', "Set the root path where your rails app resides.") { |OPTIONS[:rails_root]| }
178
+ opts.on('-e', '--environment ENV', "Rails environment to run as.") { |OPTIONS[:environment]| }
179
+ opts.on('-b', '--binding ADDR', "Address to bind to") { |OPTIONS[:ip]| }
180
+ opts.on('-p', '--port PORT', "Which port to bind to") { |OPTIONS[:port]| }
181
+ opts.on('-m', '--mime PATH', "A YAML file that lists additional MIME types") { |OPTIONS[:mime_map]| }
182
+ opts.on('-P', '--num-procs INT', "Number of processor threads to use") { |OPTIONS[:num_procs]| }
183
+ opts.on('-t', '--timeout SECONDS', "Timeout all requests after SECONDS time") { |OPTIONS[:timeout]| }
184
+
185
+ opts.parse!
186
+ end
187
+
188
+ OPTIONS[:docroot] = File.expand_path(OPTIONS[:rails_root] + '/public')
189
+
190
+ rails_svc = RailsDaemon.new(OPTIONS[:ip], OPTIONS[:port], OPTIONS[:rails_root], OPTIONS[:docroot], OPTIONS[:environment], OPTIONS[:mime_map], OPTIONS[:num_procs].to_i, OPTIONS[:timeout].to_i)
191
+ rails_svc.mainloop
192
+
193
+ end
194
+