Step 1. Drop this in lib/tasks/development.rake:
task "server" do
# Dump lines from the file to the console at the specified interval (in seconds).
def tail(file_name, interval = 1)
position = File.size(file_name)
leftover = ""
while true
sleep interval
File.open file_name do |file|
file.seek position
text = file.read
lines = text[/([^n]*n)*/m]
if lines.empty?
leftover << text
else
puts (leftover + lines)
leftover = text[lines.size..-1]
end
position = file.tell
end
end
end
pid = "#{RAILS_ROOT}/tmp/pids/mongrel.pid"
trap "INT" do
puts "Stopping mongrel"
puts `mongrel_rails stop -P #{pid}`
exit
end
puts "Starting mongrel, hit Ctrl-C to stop"
puts `mongrel_rails start -d -e #{RAILS_ENV} -P #{pid}`
tail "log/development.log"
end
Step 2. Start the server:
rake start
Step 3. Hit the browser, watch the log, hit Ctrl-C to kill.
Update: If you’re using Sake (if not, what’s taking you so long?), you can skip step 1 and install it once for all your apps:
sake -i http://pastie.caboo.se/90791.txt