Ooops! Fixed upgrade of Rails.

This commit is contained in:
Jacques Distler 2007-02-09 17:12:31 -06:00
parent 5536e6e79e
commit bba0cf6b10
177 changed files with 13221 additions and 0 deletions

View file

@ -0,0 +1,68 @@
require 'optparse'
if RUBY_PLATFORM =~ /mswin32/ then abort("Inspector is only for Unix") end
OPTIONS = {
:pid_path => File.expand_path(RAILS_ROOT + '/tmp/pids'),
:pattern => "dispatch.*.pid",
:ps => "ps -o pid,state,user,start,time,pcpu,vsz,majflt,command -p %s"
}
class Inspector
def self.inspect(pid_path, pattern)
new(pid_path, pattern).inspect
end
def initialize(pid_path, pattern)
@pid_path, @pattern = pid_path, pattern
end
def inspect
header = `#{OPTIONS[:ps] % 1}`.split("\n")[0] + "\n"
lines = pids.collect { |pid| `#{OPTIONS[:ps] % pid}`.split("\n")[1] }
puts(header + lines.join("\n"))
end
private
def pids
pid_files.collect do |pid_file|
File.read(pid_file).to_i
end
end
def pid_files
Dir.glob(@pid_path + "/" + @pattern)
end
end
ARGV.options do |opts|
opts.banner = "Usage: inspector [options]"
opts.separator ""
opts.on <<-EOF
Description:
Displays system information about Rails dispatchers (or other processes that use pid files) through
the ps command.
Examples:
inspector # default ps on all tmp/pids/dispatch.*.pid files
inspector -s 'ps -o user,start,majflt,pcpu,vsz -p %s' # custom ps, %s is where the pid is interleaved
EOF
opts.on(" Options:")
opts.on("-s", "--ps=command", "default: #{OPTIONS[:ps]}", String) { |v| OPTIONS[:ps] = v }
opts.on("-p", "--pidpath=path", "default: #{OPTIONS[:pid_path]}", String) { |v| OPTIONS[:pid_path] = v }
opts.on("-r", "--pattern=pattern", "default: #{OPTIONS[:pattern]}", String) { |v| OPTIONS[:pattern] = v }
opts.separator ""
opts.on("-h", "--help", "Show this help message.") { puts opts; exit }
opts.parse!
end
Inspector.inspect(OPTIONS[:pid_path], OPTIONS[:pattern])

View file

@ -0,0 +1,19 @@
def tail(log_file)
cursor = File.size(log_file)
last_checked = Time.now
tail_thread = Thread.new do
File.open(log_file, 'r') do |f|
loop do
f.seek cursor
if f.mtime > last_checked
last_checked = f.mtime
contents = f.read
cursor += contents.length
print contents
end
sleep 1
end
end
end
tail_thread
end

View file

@ -0,0 +1,65 @@
require 'rbconfig'
require 'commands/servers/base'
unless defined?(Mongrel)
puts "PROBLEM: Mongrel is not available on your system (or not in your path)"
exit 1
end
require 'optparse'
OPTIONS = {
:port => 3000,
:ip => "0.0.0.0",
:environment => (ENV['RAILS_ENV'] || "development").dup,
:detach => false
}
ARGV.clone.options do |opts|
opts.on("-p", "--port=port", Integer, "Runs Rails on the specified port.", "Default: 3000") { |v| OPTIONS[:port] = v }
opts.on("-b", "--binding=ip", String, "Binds Rails to the specified ip.", "Default: 0.0.0.0") { |v| OPTIONS[:ip] = v }
opts.on("-d", "--daemon", "Make server run as a Daemon.") { OPTIONS[:detach] = true }
opts.on("-e", "--environment=name", String,
"Specifies the environment to run this server under (test/development/production).",
"Default: development") { |v| OPTIONS[:environment] = v }
opts.separator ""
opts.on("-h", "--help", "Show this help message.") { puts opts; exit }
opts.parse!
end
puts "=> Rails application starting on http://#{OPTIONS[:ip]}:#{OPTIONS[:port]}"
parameters = [
"start",
"-p", OPTIONS[:port].to_s,
"-a", OPTIONS[:ip].to_s,
"-e", OPTIONS[:environment],
"-P", "#{RAILS_ROOT}/tmp/pids/mongrel.pid"
]
if OPTIONS[:detach]
`mongrel_rails #{parameters.join(" ")} -d`
else
ENV["RAILS_ENV"] = OPTIONS[:environment]
RAILS_ENV.replace(OPTIONS[:environment]) if defined?(RAILS_ENV)
require 'initializer'
Rails::Initializer.run(:initialize_logger)
puts "=> Call with -d to detach"
puts "=> Ctrl-C to shutdown server"
tail_thread = tail(Pathname.new("#{File.expand_path(RAILS_ROOT)}/log/#{RAILS_ENV}.log").cleanpath)
trap(:INT) { exit }
begin
silence_warnings { ARGV = parameters }
load("mongrel_rails")
ensure
tail_thread.kill if tail_thread
puts 'Exiting'
end
end