rails 1.1.6 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rails might be problematic. Click here for more details.

Files changed (104) hide show
  1. data/CHANGELOG +267 -2
  2. data/MIT-LICENSE +1 -1
  3. data/README +62 -63
  4. data/Rakefile +26 -15
  5. data/bin/process/inspector +3 -0
  6. data/configs/databases/frontbase.yml +28 -0
  7. data/configs/databases/mysql.yml +3 -2
  8. data/configs/databases/oracle.yml +10 -1
  9. data/configs/databases/sqlite3.yml +3 -0
  10. data/configs/lighttpd.conf +1 -0
  11. data/configs/routes.rb +1 -0
  12. data/environments/boot.rb +4 -3
  13. data/environments/environment.rb +9 -2
  14. data/environments/production.rb +1 -1
  15. data/helpers/application.rb +5 -2
  16. data/html/404.html +27 -5
  17. data/html/500.html +27 -5
  18. data/html/javascripts/controls.js +41 -23
  19. data/html/javascripts/dragdrop.js +105 -76
  20. data/html/javascripts/effects.js +293 -163
  21. data/html/javascripts/prototype.js +897 -389
  22. data/lib/breakpoint.rb +31 -1
  23. data/lib/breakpoint_client.rb +5 -5
  24. data/lib/code_statistics.rb +1 -1
  25. data/lib/commands/performance/profiler.rb +25 -9
  26. data/lib/commands/plugin.rb +69 -23
  27. data/lib/commands/process/inspector.rb +68 -0
  28. data/lib/commands/process/reaper.rb +88 -69
  29. data/lib/commands/process/spawner.rb +148 -33
  30. data/lib/commands/runner.rb +27 -6
  31. data/lib/commands/server.rb +18 -9
  32. data/lib/commands/servers/base.rb +19 -0
  33. data/lib/commands/servers/lighttpd.rb +20 -18
  34. data/lib/commands/servers/mongrel.rb +65 -0
  35. data/lib/console_sandbox.rb +2 -2
  36. data/lib/dispatcher.rb +67 -11
  37. data/lib/fcgi_handler.rb +52 -34
  38. data/lib/initializer.rb +190 -111
  39. data/lib/rails/version.rb +2 -2
  40. data/lib/rails_generator/base.rb +82 -24
  41. data/lib/rails_generator/commands.rb +87 -25
  42. data/lib/rails_generator/generated_attribute.rb +42 -0
  43. data/lib/rails_generator/generators/applications/app/app_generator.rb +13 -10
  44. data/lib/rails_generator/generators/components/controller/controller_generator.rb +1 -2
  45. data/lib/rails_generator/generators/components/mailer/mailer_generator.rb +10 -8
  46. data/lib/rails_generator/generators/components/mailer/templates/fixture.rhtml +1 -1
  47. data/lib/rails_generator/generators/components/mailer/templates/unit_test.rb +4 -4
  48. data/lib/rails_generator/generators/components/mailer/templates/view.rhtml +1 -1
  49. data/lib/rails_generator/generators/components/migration/templates/migration.rb +1 -1
  50. data/lib/rails_generator/generators/components/model/USAGE +19 -12
  51. data/lib/rails_generator/generators/components/model/model_generator.rb +4 -0
  52. data/lib/rails_generator/generators/components/model/templates/fixtures.yml +8 -2
  53. data/lib/rails_generator/generators/components/model/templates/migration.rb +3 -1
  54. data/lib/rails_generator/generators/components/observer/USAGE +15 -0
  55. data/lib/rails_generator/generators/components/observer/observer_generator.rb +16 -0
  56. data/lib/rails_generator/generators/components/observer/templates/observer.rb +2 -0
  57. data/lib/rails_generator/generators/components/observer/templates/unit_test.rb +10 -0
  58. data/lib/rails_generator/generators/components/plugin/plugin_generator.rb +4 -0
  59. data/lib/rails_generator/generators/components/plugin/templates/uninstall.rb +1 -0
  60. data/lib/rails_generator/generators/components/resource/resource_generator.rb +76 -0
  61. data/lib/rails_generator/generators/components/resource/templates/USAGE +18 -0
  62. data/lib/rails_generator/generators/components/resource/templates/controller.rb +2 -0
  63. data/lib/rails_generator/generators/components/resource/templates/fixtures.yml +11 -0
  64. data/lib/rails_generator/generators/components/resource/templates/functional_test.rb +20 -0
  65. data/lib/rails_generator/generators/components/resource/templates/helper.rb +2 -0
  66. data/lib/rails_generator/generators/components/resource/templates/migration.rb +13 -0
  67. data/lib/rails_generator/generators/components/resource/templates/model.rb +2 -0
  68. data/lib/rails_generator/generators/components/resource/templates/unit_test.rb +10 -0
  69. data/lib/rails_generator/generators/components/scaffold/scaffold_generator.rb +10 -1
  70. data/lib/rails_generator/generators/components/scaffold/templates/functional_test.rb +11 -7
  71. data/lib/rails_generator/generators/components/scaffold/templates/layout.rhtml +5 -1
  72. data/lib/rails_generator/generators/components/scaffold/templates/view_edit.rhtml +2 -2
  73. data/lib/rails_generator/generators/components/scaffold/templates/view_list.rhtml +1 -1
  74. data/lib/rails_generator/generators/components/scaffold/templates/view_new.rhtml +2 -2
  75. data/lib/rails_generator/generators/components/scaffold_resource/USAGE +29 -0
  76. data/lib/rails_generator/generators/components/scaffold_resource/scaffold_resource_generator.rb +92 -0
  77. data/lib/rails_generator/generators/components/scaffold_resource/templates/controller.rb +79 -0
  78. data/lib/rails_generator/generators/components/scaffold_resource/templates/fixtures.yml +11 -0
  79. data/lib/rails_generator/generators/components/scaffold_resource/templates/functional_test.rb +57 -0
  80. data/lib/rails_generator/generators/components/scaffold_resource/templates/helper.rb +2 -0
  81. data/lib/rails_generator/generators/components/scaffold_resource/templates/layout.rhtml +17 -0
  82. data/lib/rails_generator/generators/components/scaffold_resource/templates/migration.rb +13 -0
  83. data/lib/rails_generator/generators/components/scaffold_resource/templates/model.rb +2 -0
  84. data/lib/rails_generator/generators/components/scaffold_resource/templates/style.css +74 -0
  85. data/lib/rails_generator/generators/components/scaffold_resource/templates/unit_test.rb +10 -0
  86. data/lib/rails_generator/generators/components/scaffold_resource/templates/view_edit.rhtml +19 -0
  87. data/lib/rails_generator/generators/components/scaffold_resource/templates/view_index.rhtml +24 -0
  88. data/lib/rails_generator/generators/components/scaffold_resource/templates/view_new.rhtml +18 -0
  89. data/lib/rails_generator/generators/components/scaffold_resource/templates/view_show.rhtml +10 -0
  90. data/lib/rails_generator/generators/components/session_migration/session_migration_generator.rb +7 -1
  91. data/lib/rails_generator/generators/components/session_migration/templates/migration.rb +5 -4
  92. data/lib/rails_generator/lookup.rb +1 -2
  93. data/lib/rails_generator/options.rb +6 -3
  94. data/lib/tasks/databases.rake +46 -20
  95. data/lib/tasks/documentation.rake +1 -0
  96. data/lib/tasks/framework.rake +1 -3
  97. data/lib/tasks/pre_namespace_aliases.rake +34 -27
  98. data/lib/tasks/rails.rb +2 -2
  99. data/lib/tasks/statistics.rake +6 -5
  100. data/lib/tasks/testing.rake +28 -13
  101. data/lib/tasks/tmp.rake +8 -1
  102. data/lib/test_help.rb +3 -2
  103. data/lib/webrick_server.rb +6 -8
  104. metadata +50 -9
@@ -1,5 +1,7 @@
1
+ require 'active_support'
1
2
  require 'optparse'
2
3
  require 'socket'
4
+ require 'fileutils'
3
5
 
4
6
  def daemonize #:nodoc:
5
7
  exit if fork # Parent exits, child continues.
@@ -12,63 +14,175 @@ def daemonize #:nodoc:
12
14
  STDERR.reopen STDOUT # STDOUT/ERR should better go to a logfile.
13
15
  end
14
16
 
15
- def spawn(port)
16
- print "Checking if something is already running on port #{port}..."
17
- begin
18
- srv = TCPServer.new('0.0.0.0', port)
19
- srv.close
20
- srv = nil
21
- print "NO\n "
22
- print "Starting FCGI on port: #{port}\n "
23
- system("#{OPTIONS[:spawner]} -f #{OPTIONS[:dispatcher]} -p #{port}")
24
- rescue
25
- print "YES\n"
17
+ class Spawner
18
+ def self.record_pid(name = "#{OPTIONS[:process]}.spawner", id = Process.pid)
19
+ FileUtils.mkdir_p(OPTIONS[:pids])
20
+ File.open(File.expand_path(OPTIONS[:pids] + "/#{name}.pid"), "w+") { |f| f.write(id) }
26
21
  end
22
+
23
+ def self.spawn_all
24
+ OPTIONS[:instances].times do |i|
25
+ port = OPTIONS[:port] + i
26
+ print "Checking if something is already running on #{OPTIONS[:address]}:#{port}..."
27
+
28
+ begin
29
+ srv = TCPServer.new(OPTIONS[:address], port)
30
+ srv.close
31
+ srv = nil
32
+
33
+ puts "NO"
34
+ puts "Starting dispatcher on port: #{OPTIONS[:address]}:#{port}"
35
+
36
+ FileUtils.mkdir_p(OPTIONS[:pids])
37
+ spawn(port)
38
+ rescue
39
+ puts "YES"
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ class FcgiSpawner < Spawner
46
+ def self.spawn(port)
47
+ cmd = "#{OPTIONS[:spawner]} -f #{OPTIONS[:dispatcher]} -p #{port} -P #{OPTIONS[:pids]}/#{OPTIONS[:process]}.#{port}.pid"
48
+ cmd << " -a #{OPTIONS[:address]}" if can_bind_to_custom_address?
49
+ system(cmd)
50
+ end
51
+
52
+ def self.can_bind_to_custom_address?
53
+ @@can_bind_to_custom_address ||= /^\s-a\s/.match `#{OPTIONS[:spawner]} -h`
54
+ end
55
+ end
56
+
57
+ class MongrelSpawner < Spawner
58
+ def self.spawn(port)
59
+ cmd =
60
+ "mongrel_rails start -d " +
61
+ "-a #{OPTIONS[:address]} " +
62
+ "-p #{port} " +
63
+ "-P #{OPTIONS[:pids]}/#{OPTIONS[:process]}.#{port}.pid " +
64
+ "-e #{OPTIONS[:environment]} " +
65
+ "-c #{OPTIONS[:rails_root]} " +
66
+ "-l #{OPTIONS[:rails_root]}/log/mongrel.log"
67
+
68
+ system(cmd)
69
+ end
70
+
71
+ def self.can_bind_to_custom_address?
72
+ true
73
+ end
74
+ end
75
+
76
+
77
+ begin
78
+ require_library_or_gem 'fcgi'
79
+ rescue Exception
80
+ # FCGI not available
27
81
  end
28
-
29
- def spawn_all
30
- OPTIONS[:instances].times { |i| spawn(OPTIONS[:port] + i) }
82
+
83
+ begin
84
+ require_library_or_gem 'mongrel'
85
+ rescue Exception
86
+ # Mongrel not available
87
+ end
88
+
89
+ server = case ARGV.first
90
+ when "fcgi", "mongrel"
91
+ ARGV.shift
92
+ else
93
+ if defined?(Mongrel)
94
+ "mongrel"
95
+ elsif RUBY_PLATFORM !~ /mswin/ && !silence_stderr { `spawn-fcgi -version` }.blank? && defined?(FCGI)
96
+ "fcgi"
97
+ end
31
98
  end
32
99
 
100
+ case server
101
+ when "fcgi"
102
+ puts "=> Starting FCGI dispatchers"
103
+ spawner_class = FcgiSpawner
104
+ when "mongrel"
105
+ puts "=> Starting mongrel dispatchers"
106
+ spawner_class = MongrelSpawner
107
+ else
108
+ puts "Neither FCGI (spawn-fcgi) nor Mongrel was installed and available!"
109
+ exit(0)
110
+ end
111
+
112
+
113
+
33
114
  OPTIONS = {
34
115
  :environment => "production",
35
116
  :spawner => '/usr/bin/env spawn-fcgi',
36
117
  :dispatcher => File.expand_path(RAILS_ROOT + '/public/dispatch.fcgi'),
118
+ :pids => File.expand_path(RAILS_ROOT + "/tmp/pids"),
119
+ :rails_root => File.expand_path(RAILS_ROOT),
120
+ :process => "dispatch",
37
121
  :port => 8000,
122
+ :address => '0.0.0.0',
38
123
  :instances => 3,
39
124
  :repeat => nil
40
125
  }
41
126
 
42
127
  ARGV.options do |opts|
43
- opts.banner = "Usage: spawner [options]"
128
+ opts.banner = "Usage: spawner [platform] [options]"
44
129
 
45
130
  opts.separator ""
46
131
 
47
132
  opts.on <<-EOF
48
133
  Description:
49
- The spawner is a wrapper for spawn-fcgi that makes it easier to start multiple FCGI
50
- processes running the Rails dispatcher. The spawn-fcgi command is included with the lighttpd
51
- web server, but can be used with both Apache and lighttpd (and any other web server supporting
52
- externally managed FCGI processes).
53
-
54
- You decide a starting port (default is 8000) and the number of FCGI process instances you'd
55
- like to run. So if you pick 9100 and 3 instances, you'll start processes on 9100, 9101, and 9102.
56
-
57
- By setting the repeat option, you get a protection loop, which will attempt to restart any FCGI processes
58
- that might have been exited or outright crashed.
59
-
60
- Examples:
61
- spawner # starts instances on 8000, 8001, and 8002
62
- spawner -p 9100 -i 10 # starts 10 instances counting from 9100 to 9109
63
- spawner -p 9100 -r 5 # starts 3 instances counting from 9100 to 9102 and attempts start them every 5 seconds
134
+ The spawner is a wrapper for spawn-fcgi and mongrel that makes it
135
+ easier to start multiple processes running the Rails dispatcher. The
136
+ spawn-fcgi command is included with the lighttpd web server, but can
137
+ be used with both Apache and lighttpd (and any other web server
138
+ supporting externally managed FCGI processes). Mongrel automatically
139
+ ships with with mongrel_rails for starting dispatchers.
140
+
141
+ The first choice you need to make is whether to spawn the Rails
142
+ dispatchers as FCGI or Mongrel. By default, this spawner will prefer
143
+ Mongrel, so if that's installed, and no platform choice is made,
144
+ Mongrel is used.
145
+
146
+ Then decide a starting port (default is 8000) and the number of FCGI
147
+ process instances you'd like to run. So if you pick 9100 and 3
148
+ instances, you'll start processes on 9100, 9101, and 9102.
149
+
150
+ By setting the repeat option, you get a protection loop, which will
151
+ attempt to restart any FCGI processes that might have been exited or
152
+ outright crashed.
153
+
154
+ You can select bind address for started processes. By default these
155
+ listen on every interface. For single machine installations you would
156
+ probably want to use 127.0.0.1, hiding them form the outside world.
157
+
158
+ Examples:
159
+ spawner # starts instances on 8000, 8001, and 8002
160
+ # using Mongrel if available.
161
+ spawner fcgi # starts instances on 8000, 8001, and 8002
162
+ # using FCGI.
163
+ spawner mongrel -i 5 # starts instances on 8000, 8001, 8002,
164
+ # 8003, and 8004 using Mongrel.
165
+ spawner -p 9100 -i 10 # starts 10 instances counting from 9100 to
166
+ # 9109 using Mongrel if available.
167
+ spawner -p 9100 -r 5 # starts 3 instances counting from 9100 to
168
+ # 9102 and attempts start them every 5
169
+ # seconds.
170
+ spawner -a 127.0.0.1 # starts 3 instances binding to localhost
64
171
  EOF
65
172
 
66
173
  opts.on(" Options:")
67
174
 
175
+ opts.on("-p", "--port=number", Integer, "Starting port number (default: #{OPTIONS[:port]})") { |OPTIONS[:port]| }
176
+
177
+ if spawner_class.can_bind_to_custom_address?
178
+ opts.on("-a", "--address=ip", String, "Bind to IP address (default: #{OPTIONS[:address]})") { |OPTIONS[:address]| }
179
+ end
180
+
68
181
  opts.on("-p", "--port=number", Integer, "Starting port number (default: #{OPTIONS[:port]})") { |v| OPTIONS[:port] = v }
69
182
  opts.on("-i", "--instances=number", Integer, "Number of instances (default: #{OPTIONS[:instances]})") { |v| OPTIONS[:instances] = v }
70
183
  opts.on("-r", "--repeat=seconds", Integer, "Repeat spawn attempts every n seconds (default: off)") { |v| OPTIONS[:repeat] = v }
71
184
  opts.on("-e", "--environment=name", String, "test|development|production (default: #{OPTIONS[:environment]})") { |v| OPTIONS[:environment] = v }
185
+ opts.on("-n", "--process=name", String, "default: #{OPTIONS[:process]}") { |v| OPTIONS[:process] = v }
72
186
  opts.on("-s", "--spawner=path", String, "default: #{OPTIONS[:spawner]}") { |v| OPTIONS[:spawner] = v }
73
187
  opts.on("-d", "--dispatcher=path", String, "default: #{OPTIONS[:dispatcher]}") { |dispatcher| OPTIONS[:dispatcher] = File.expand_path(dispatcher) }
74
188
 
@@ -84,11 +198,12 @@ ENV["RAILS_ENV"] = OPTIONS[:environment]
84
198
  if OPTIONS[:repeat]
85
199
  daemonize
86
200
  trap("TERM") { exit }
201
+ spawner_class.record_pid
87
202
 
88
203
  loop do
89
- spawn_all
204
+ spawner_class.spawn_all
90
205
  sleep(OPTIONS[:repeat])
91
206
  end
92
207
  else
93
- spawn_all
94
- end
208
+ spawner_class.spawn_all
209
+ end
@@ -1,10 +1,11 @@
1
1
  require 'optparse'
2
2
 
3
3
  options = { :environment => (ENV['RAILS_ENV'] || "development").dup }
4
+ code_or_file = nil
4
5
 
5
- ARGV.options do |opts|
6
+ ARGV.clone.options do |opts|
6
7
  script_name = File.basename($0)
7
- opts.banner = "Usage: runner 'puts Person.find(1).name' [options]"
8
+ opts.banner = "Usage: #{$0} [options] ('Some.ruby(code)' or a filename)"
8
9
 
9
10
  opts.separator ""
10
11
 
@@ -15,13 +16,33 @@ ARGV.options do |opts|
15
16
  opts.separator ""
16
17
 
17
18
  opts.on("-h", "--help",
18
- "Show this help message.") { puts opts; exit }
19
-
20
- opts.parse!
19
+ "Show this help message.") { $stderr.puts opts; exit }
20
+
21
+ if RUBY_PLATFORM !~ /mswin/
22
+ opts.separator ""
23
+ opts.separator "You can also use runner as a shebang line for your scripts like this:"
24
+ opts.separator "-------------------------------------------------------------"
25
+ opts.separator "#!/usr/bin/env #{File.expand_path($0)}"
26
+ opts.separator ""
27
+ opts.separator "Product.find(:all).each { |p| p.price *= 2 ; p.save! }"
28
+ opts.separator "-------------------------------------------------------------"
29
+ end
30
+
31
+ opts.order! { |o| code_or_file ||= o } rescue retry
21
32
  end
22
33
 
34
+ ARGV.delete(code_or_file)
35
+
23
36
  ENV["RAILS_ENV"] = options[:environment]
24
37
  RAILS_ENV.replace(options[:environment]) if defined?(RAILS_ENV)
25
38
 
26
39
  require RAILS_ROOT + '/config/environment'
27
- ARGV.empty? ? puts("Usage: runner 'code' [options]") : eval(ARGV.first)
40
+
41
+ if code_or_file.nil?
42
+ $stderr.puts "Run '#{$0} -h' for help."
43
+ exit 1
44
+ elsif File.exists?(code_or_file)
45
+ eval(File.read(code_or_file))
46
+ else
47
+ eval(code_or_file)
48
+ end
@@ -7,24 +7,33 @@ rescue Exception
7
7
  # FCGI not available
8
8
  end
9
9
 
10
+ begin
11
+ require_library_or_gem 'mongrel'
12
+ rescue Exception
13
+ # Mongrel not available
14
+ end
15
+
10
16
  server = case ARGV.first
11
- when "lighttpd"
12
- ARGV.shift
13
- when "webrick"
17
+ when "lighttpd", "mongrel", "webrick"
14
18
  ARGV.shift
15
19
  else
16
- if RUBY_PLATFORM !~ /mswin/ && !silence_stderr { `lighttpd -version` }.blank? && defined?(FCGI)
20
+ if defined?(Mongrel)
21
+ "mongrel"
22
+ elsif RUBY_PLATFORM !~ /mswin/ && !silence_stderr { `lighttpd -version` }.blank? && defined?(FCGI)
17
23
  "lighttpd"
18
24
  else
19
25
  "webrick"
20
26
  end
21
27
  end
22
28
 
23
- if server == "webrick"
24
- puts "=> Booting WEBrick..."
25
- else
26
- puts "=> Booting lighttpd (use 'script/server webrick' to force WEBrick)"
29
+ case server
30
+ when "webrick"
31
+ puts "=> Booting WEBrick..."
32
+ when "lighttpd"
33
+ puts "=> Booting lighttpd (use 'script/server webrick' to force WEBrick)"
34
+ when "mongrel"
35
+ puts "=> Booting Mongrel (use 'script/server webrick' to force WEBrick)"
27
36
  end
28
37
 
29
- FileUtils.mkdir_p(%w( tmp/sessions tmp/cache tmp/sockets ))
38
+ %w(cache pids sessions sockets).each { |dir_to_make| FileUtils.mkdir_p(File.join(RAILS_ROOT, 'tmp', dir_to_make)) }
30
39
  require "commands/servers/#{server}"
@@ -0,0 +1,19 @@
1
+ def tail(log_file)
2
+ cursor = File.size(log_file)
3
+ last_checked = Time.now
4
+ tail_thread = Thread.new do
5
+ File.open(log_file, 'r') do |f|
6
+ loop do
7
+ f.seek cursor
8
+ if f.mtime > last_checked
9
+ last_checked = f.mtime
10
+ contents = f.read
11
+ cursor += contents.length
12
+ print contents
13
+ end
14
+ sleep 1
15
+ end
16
+ end
17
+ end
18
+ tail_thread
19
+ end
@@ -1,4 +1,5 @@
1
1
  require 'rbconfig'
2
+ require 'commands/servers/base'
2
3
 
3
4
  unless RUBY_PLATFORM !~ /mswin/ && !silence_stderr { `lighttpd -version` }.blank?
4
5
  puts "PROBLEM: Lighttpd is not available on your system (or not in your path)"
@@ -17,8 +18,10 @@ default_config_file = config_file = Pathname.new("#{RAILS_ROOT}/config/lighttpd.
17
18
  require 'optparse'
18
19
 
19
20
  detach = false
21
+ command_line_port = nil
20
22
 
21
23
  ARGV.options do |opt|
24
+ opt.on("-p", "--port=port", "Changes the server.port number in the config/lighttpd.conf") { |port| command_line_port = port }
22
25
  opt.on('-c', "--config=#{config_file}", 'Specify a different lighttpd config file.') { |path| config_file = path }
23
26
  opt.on('-h', '--help', 'Show this message.') { puts opt; exit 0 }
24
27
  opt.on('-d', '-d', 'Call with -d to detach') { detach = true; puts "=> Configuration in config/lighttpd.conf" }
@@ -40,11 +43,26 @@ unless File.exist?(config_file)
40
43
  FileUtils.cp(source, config_file)
41
44
  end
42
45
 
46
+ # open the config/lighttpd.conf file and add the current user defined port setting to it
47
+ if command_line_port
48
+ File.open(config_file, 'r+') do |config|
49
+ lines = config.readlines
50
+
51
+ lines.each do |line|
52
+ line.gsub!(/^\s*server.port\s*=\s*(\d+)/, "server.port = #{command_line_port}")
53
+ end
54
+
55
+ config.rewind
56
+ config.print(lines)
57
+ config.truncate(config.pos)
58
+ end
59
+ end
60
+
43
61
  config = IO.read(config_file)
44
62
  default_port, default_ip = 3000, '0.0.0.0'
45
63
  port = config.scan(/^\s*server.port\s*=\s*(\d+)/).first rescue default_port
46
64
  ip = config.scan(/^\s*server.bind\s*=\s*"([^"]+)"/).first rescue default_ip
47
- puts "=> Rails application started on http://#{ip || default_ip}:#{port || default_port}"
65
+ puts "=> Rails application starting on http://#{ip || default_ip}:#{port || default_port}"
48
66
 
49
67
  tail_thread = nil
50
68
 
@@ -52,23 +70,7 @@ if !detach
52
70
  puts "=> Call with -d to detach"
53
71
  puts "=> Ctrl-C to shutdown server (see config/lighttpd.conf for options)"
54
72
  detach = false
55
-
56
- cursor = File.size(configuration.log_path)
57
- last_checked = Time.now
58
- tail_thread = Thread.new do
59
- File.open(configuration.log_path, 'r') do |f|
60
- loop do
61
- f.seek cursor
62
- if f.mtime > last_checked
63
- last_checked = f.mtime
64
- contents = f.read
65
- cursor += contents.length
66
- print contents
67
- end
68
- sleep 1
69
- end
70
- end
71
- end
73
+ tail_thread = tail(configuration.log_path)
72
74
  end
73
75
 
74
76
  trap(:INT) { exit }
@@ -0,0 +1,65 @@
1
+ require 'rbconfig'
2
+ require 'commands/servers/base'
3
+
4
+ unless defined?(Mongrel)
5
+ puts "PROBLEM: Mongrel is not available on your system (or not in your path)"
6
+ exit 1
7
+ end
8
+
9
+ require 'optparse'
10
+
11
+ OPTIONS = {
12
+ :port => 3000,
13
+ :ip => "0.0.0.0",
14
+ :environment => (ENV['RAILS_ENV'] || "development").dup,
15
+ :detach => false
16
+ }
17
+
18
+ ARGV.clone.options do |opts|
19
+ opts.on("-p", "--port=port", Integer, "Runs Rails on the specified port.", "Default: 3000") { |v| OPTIONS[:port] = v }
20
+ opts.on("-b", "--binding=ip", String, "Binds Rails to the specified ip.", "Default: 0.0.0.0") { |v| OPTIONS[:ip] = v }
21
+ opts.on("-d", "--daemon", "Make server run as a Daemon.") { OPTIONS[:detach] = true }
22
+ opts.on("-e", "--environment=name", String,
23
+ "Specifies the environment to run this server under (test/development/production).",
24
+ "Default: development") { |v| OPTIONS[:environment] = v }
25
+
26
+ opts.separator ""
27
+
28
+ opts.on("-h", "--help", "Show this help message.") { puts opts; exit }
29
+
30
+ opts.parse!
31
+ end
32
+
33
+ puts "=> Rails application starting on http://#{OPTIONS[:ip]}:#{OPTIONS[:port]}"
34
+
35
+ parameters = [
36
+ "start",
37
+ "-p", OPTIONS[:port].to_s,
38
+ "-a", OPTIONS[:ip].to_s,
39
+ "-e", OPTIONS[:environment],
40
+ "-P", "#{RAILS_ROOT}/tmp/pids/mongrel.pid"
41
+ ]
42
+
43
+ if OPTIONS[:detach]
44
+ `mongrel_rails #{parameters.join(" ")} -d`
45
+ else
46
+ ENV["RAILS_ENV"] = OPTIONS[:environment]
47
+ RAILS_ENV.replace(OPTIONS[:environment]) if defined?(RAILS_ENV)
48
+
49
+ require 'initializer'
50
+ Rails::Initializer.run(:initialize_logger)
51
+
52
+ puts "=> Call with -d to detach"
53
+ puts "=> Ctrl-C to shutdown server"
54
+ tail_thread = tail(Pathname.new("#{File.expand_path(RAILS_ROOT)}/log/#{RAILS_ENV}.log").cleanpath)
55
+
56
+ trap(:INT) { exit }
57
+
58
+ begin
59
+ silence_warnings { ARGV = parameters }
60
+ load("mongrel_rails")
61
+ ensure
62
+ tail_thread.kill if tail_thread
63
+ puts 'Exiting'
64
+ end
65
+ end