TeX and CSS tweaks.

Sync with latest Instiki Trunk
(Updates Rails to 1.2.2)
This commit is contained in:
Jacques Distler 2007-02-09 02:04:31 -06:00
parent 0ac586ee25
commit c358389f25
443 changed files with 24218 additions and 9823 deletions

View file

@ -1,5 +1,5 @@
if ARGV.empty?
$stderr.puts "Usage: ./script/performance/profiler 'Person.expensive_method(10)' [times]"
$stderr.puts "Usage: ./script/performance/profiler 'Person.expensive_method(10)' [times] [flat|graph|graph_html]"
exit(1)
end
@ -16,14 +16,30 @@ end
# Use the ruby-prof extension if available. Fall back to stdlib profiler.
begin
require 'prof'
$stderr.puts 'Using the ruby-prof extension.'
Prof.clock_mode = Prof::GETTIMEOFDAY
Prof.start
profile_me
results = Prof.stop
require 'rubyprof_ext'
Prof.print_profile(results, $stderr)
begin
require "ruby-prof"
$stderr.puts 'Using the ruby-prof extension.'
RubyProf.clock_mode = RubyProf::WALL_TIME
RubyProf.start
profile_me
results = RubyProf.stop
if ARGV[2]
printer_class = RubyProf.const_get((ARGV[2] + "_printer").classify)
else
printer_class = RubyProf::FlatPrinter
end
printer = printer_class.new(results)
printer.print($stderr, 0)
rescue LoadError
require "prof"
$stderr.puts 'Using the old ruby-prof extension.'
Prof.clock_mode = Prof::GETTIMEOFDAY
Prof.start
profile_me
results = Prof.stop
require 'rubyprof_ext'
Prof.print_profile(results, $stderr)
end
rescue LoadError
require 'profiler'
$stderr.puts 'Using the standard Ruby profiler.'

View file

@ -136,7 +136,7 @@ class RailsEnvironment
Tempfile.open("svn-set-prop") do |file|
file.write(items)
file.flush
system("svn propset -q svn:externals -F #{file.path} \"#{root}/vendor/plugins\"")
system("svn propset -q svn:externals -F \"#{file.path}\" \"#{root}/vendor/plugins\"")
end
end
@ -150,10 +150,18 @@ class Plugin
guess_name(uri)
end
def self.find(name)
name =~ /\// ? new(name) : Repositories.instance.find_plugin(name)
end
def to_s
"#{@name.ljust(30)}#{@uri}"
end
def svn_url?
@uri =~ /svn(?:\+ssh)?:\/\/*/
end
def installed?
File.directory?("#{rails_env.root}/vendor/plugins/#{name}") \
or rails_env.externals.detect{ |name, repo| self.uri == repo }
@ -161,7 +169,7 @@ class Plugin
def install(method=nil, options = {})
method ||= rails_env.best_install_method?
method = :export if method == :http and @uri =~ /svn:\/\/*/
method = :export if method == :http and svn_url?
uninstall if installed? and options[:force]
@ -177,6 +185,7 @@ class Plugin
path = "#{rails_env.root}/vendor/plugins/#{name}"
if File.directory?(path)
puts "Removing 'vendor/plugins/#{name}'" if $verbose
run_uninstall_hook
rm_r path
else
puts "Plugin doesn't exist: #{path}"
@ -187,6 +196,20 @@ class Plugin
rails_env.externals = externals
end
def info
tmp = "#{rails_env.root}/_tmp_about.yml"
if svn_url?
cmd = "svn export #{@uri} \"#{rails_env.root}/#{tmp}\""
puts cmd if $verbose
system(cmd)
end
open(svn_url? ? tmp : File.join(@uri, 'about.yml')) do |stream|
stream.read
end rescue "No about.yml found in #{uri}"
ensure
FileUtils.rm_rf tmp if svn_url?
end
private
def run_install_hook
@ -194,6 +217,11 @@ class Plugin
load install_hook_file if File.exists? install_hook_file
end
def run_uninstall_hook
uninstall_hook_file = "#{rails_env.root}/vendor/plugins/#{name}/uninstall.rb"
load uninstall_hook_file if File.exists? uninstall_hook_file
end
def install_using_export(options = {})
svn_command :export, options
end
@ -442,7 +470,7 @@ module Commands
options.parse!(general)
command = general.shift
if command =~ /^(list|discover|install|source|unsource|sources|remove|update)$/
if command =~ /^(list|discover|install|source|unsource|sources|remove|update|info)$/
command = Commands.const_get(command.capitalize).new(self)
command.parse!(sub)
else
@ -549,8 +577,8 @@ module Commands
def options
OptionParser.new do |o|
o.set_summary_indent(' ')
o.banner = "Usage: #{@base_command.script_name} source REPOSITORY"
o.define_head "Add a new repository."
o.banner = "Usage: #{@base_command.script_name} source REPOSITORY [REPOSITORY [REPOSITORY]...]"
o.define_head "Add new repositories to the default search list."
end
end
@ -656,13 +684,17 @@ module Commands
puts "Scraping #{uri}" if $verbose
dupes = []
content = open(uri).each do |line|
if line =~ /<a[^>]*href=['"]([^'"]*)['"]/ or line =~ /(svn:\/\/[^<|\n]*)/
uri = $1
if uri =~ /\/plugins\// and uri !~ /\/browser\//
uri = extract_repository_uri(uri)
yield uri unless dupes.include?(uri) or Repositories.instance.exist?(uri)
dupes << uri
begin
if line =~ /<a[^>]*href=['"]([^'"]*)['"]/ || line =~ /(svn:\/\/[^<|\n]*)/
uri = $1
if uri =~ /^\w+:\/\// && uri =~ /\/plugins\// && uri !~ /\/browser\// && uri !~ /^http:\/\/wiki\.rubyonrails/ && uri !~ /http:\/\/instiki/
uri = extract_repository_uri(uri)
yield uri unless dupes.include?(uri) || Repositories.instance.exist?(uri)
dupes << uri
end
end
rescue
puts "Problems scraping '#{uri}': #{$!.to_s}"
end
end
end
@ -729,19 +761,12 @@ module Commands
environment = @base_command.environment
install_method = determine_install_method
puts "Plugins will be installed using #{install_method}" if $verbose
args.each do |name|
if name =~ /\// then
::Plugin.new(name).install(install_method, @options)
else
plugin = Repositories.instance.find_plugin(name)
unless plugin.nil?
plugin.install(install_method, @options)
else
puts "Plugin not found: #{name}"
exit 1
end
end
args.each do |name|
::Plugin.find(name).install(install_method, @options)
end
rescue
puts "Plugin not found: #{args.inspect}"
exit 1
end
end
@ -802,6 +827,27 @@ module Commands
end
end
class Info
def initialize(base_command)
@base_command = base_command
end
def options
OptionParser.new do |o|
o.set_summary_indent(' ')
o.banner = "Usage: #{@base_command.script_name} info name [name]..."
o.define_head "Shows plugin info at {url}/about.yml."
end
end
def parse!(args)
options.parse!(args)
args.each do |name|
puts ::Plugin.find(name).info
puts
end
end
end
end
class RecursiveHTTPFetcher

View file

@ -4,89 +4,102 @@ require 'uri'
if RUBY_PLATFORM =~ /mswin32/ then abort("Reaper is only for Unix") end
# Instances of this class represent a single running process. Processes may
# be queried by "keyword" to find those that meet a specific set of criteria.
class ProgramProcess
class Killer
class << self
# Searches for all processes matching the given keywords, and then invokes
# a specific action on each of them. This is useful for (e.g.) reloading a
# set of processes:
#
# ProgramProcess.process_keywords(:reload, "basecamp")
def process_keywords(action, *keywords)
processes = keywords.collect { |keyword| find_by_keyword(keyword) }.flatten
if processes.empty?
puts "Couldn't find any process matching: #{keywords.join(" or ")}"
else
processes.each do |process|
puts "#{action.capitalize}ing #{process}"
process.send(action)
end
end
# Killer.process(:reload, "/tmp/pids", "dispatcher.*.pid")
def process(action, pid_path, pattern, keyword)
new(pid_path, pattern, keyword).process(action)
end
# Searches for all processes matching the given keyword:
#
# ProgramProcess.find_by_keyword("basecamp")
def find_by_keyword(keyword)
process_lines_with_keyword(keyword).split("\n").collect { |line|
next if line =~ /inq|ps axww|grep|spawn-fcgi|spawner|reaper/
pid, *command = line.split
new(pid, command.join(" "))
}.compact
# Forces the (rails) application to reload by sending a +HUP+ signal to the
# process.
def reload(pid)
`kill -s HUP #{pid}`
end
private
def process_lines_with_keyword(keyword)
`ps axww -o 'pid command' | grep #{keyword}`
# Force the (rails) application to restart by sending a +USR2+ signal to the
# process.
def restart(pid)
`kill -s USR2 #{pid}`
end
# Forces the (rails) application to gracefully terminate by sending a
# +TERM+ signal to the process.
def graceful(pid)
`kill -s TERM #{pid}`
end
# Forces the (rails) application to terminate immediately by sending a -9
# signal to the process.
def kill(pid)
`kill -9 #{pid}`
end
# Send a +USR1+ signal to the process.
def usr1(pid)
`kill -s USR1 #{pid}`
end
end
def initialize(pid_path, pattern, keyword=nil)
@pid_path, @pattern, @keyword = pid_path, pattern, keyword
end
def process(action)
pids = find_processes
if pids.empty?
warn "Couldn't find any pid file in '#{@pid_path}' matching '#{@pattern}'"
warn "(also looked for processes matching #{@keyword.inspect})" if @keyword
else
pids.each do |pid|
puts "#{action.capitalize}ing #{pid}"
self.class.send(action, pid)
end
delete_pid_files if terminating?(action)
end
end
private
def terminating?(action)
[ "kill", "graceful" ].include?(action)
end
def find_processes
files = pid_files
if files.empty?
find_processes_via_grep
else
files.collect { |pid_file| File.read(pid_file).to_i }
end
end
# Create a new ProgramProcess instance that represents the process with the
# given pid, running the given command.
def initialize(pid, command)
@pid, @command = pid, command
end
# Forces the (rails) application to reload by sending a +HUP+ signal to the
# process.
def reload
`kill -s HUP #{@pid}`
end
# Forces the (rails) application to gracefully terminate by sending a
# +TERM+ signal to the process.
def graceful
`kill -s TERM #{@pid}`
end
# Forces the (rails) application to terminate immediately by sending a -9
# signal to the process.
def kill
`kill -9 #{@pid}`
end
# Send a +USR1+ signal to the process.
def usr1
`kill -s USR1 #{@pid}`
end
# Force the (rails) application to restart by sending a +USR2+ signal to the
# process.
def restart
`kill -s USR2 #{@pid}`
end
def to_s #:nodoc:
"[#{@pid}] #{@command}"
end
def find_processes_via_grep
lines = `ps axww -o 'pid command' | grep #{@keyword}`.split(/\n/).
reject { |line| line =~ /inq|ps axww|grep|spawn-fcgi|spawner|reaper/ }
lines.map { |line| line[/^\s*(\d+)/, 1].to_i }
end
def delete_pid_files
pid_files.each { |pid_file| File.delete(pid_file) }
end
def pid_files
Dir.glob(@pid_path + "/" + @pattern)
end
end
OPTIONS = {
:action => "restart",
:dispatcher => File.expand_path(RAILS_ROOT + '/public/dispatch.fcgi')
:action => "restart",
:pid_path => File.expand_path(RAILS_ROOT + '/tmp/pids'),
:pattern => "dispatch.[0-9]*.pid",
:dispatcher => File.expand_path("#{RAILS_ROOT}/public/dispatch.fcgi")
}
ARGV.options do |opts|
@ -96,9 +109,13 @@ ARGV.options do |opts|
opts.on <<-EOF
Description:
The reaper is used to restart, reload, gracefully exit, and forcefully exit FCGI processes
running a Rails Dispatcher. This is commonly done when a new version of the application
is available, so the existing processes can be updated to use the latest code.
The reaper is used to restart, reload, gracefully exit, and forcefully exit processes
running a Rails Dispatcher (or any other process responding to the same signals). This
is commonly done when a new version of the application is available, so the existing
processes can be updated to use the latest code.
It uses pid files to work on the processes and by default assume them to be located
in RAILS_ROOT/tmp/pids.
The reaper actions are:
@ -110,15 +127,17 @@ ARGV.options do |opts|
Restart is the most common and default action.
Examples:
reaper # restarts the default dispatcher
reaper -a reload
reaper -a exit -d /my/special/dispatcher.fcgi
reaper # restarts the default dispatchers
reaper -a reload # reload the default dispatchers
reaper -a kill -r *.pid # kill all processes that keep pids in tmp/pids
EOF
opts.on(" Options:")
opts.on("-a", "--action=name", "reload|graceful|kill (default: #{OPTIONS[:action]})", String) { |v| OPTIONS[:action] = v }
opts.on("-d", "--dispatcher=path", "default: #{OPTIONS[:dispatcher]}", String) { |v| OPTIONS[:dispatcher] = 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.on("-d", "--dispatcher=path", "DEPRECATED. default: #{OPTIONS[:dispatcher]}", String) { |v| OPTIONS[:dispatcher] = v }
opts.separator ""
@ -127,4 +146,4 @@ ARGV.options do |opts|
opts.parse!
end
ProgramProcess.process_keywords(OPTIONS[:action], OPTIONS[:dispatcher])
Killer.process(OPTIONS[:action], OPTIONS[:pid_path], OPTIONS[:pattern], OPTIONS[:dispatcher])

View file

@ -1,5 +1,7 @@
require 'active_support'
require 'optparse'
require 'socket'
require 'fileutils'
def daemonize #:nodoc:
exit if fork # Parent exits, child continues.
@ -12,63 +14,175 @@ def daemonize #:nodoc:
STDERR.reopen STDOUT # STDOUT/ERR should better go to a logfile.
end
def spawn(port)
print "Checking if something is already running on port #{port}..."
begin
srv = TCPServer.new('0.0.0.0', port)
srv.close
srv = nil
print "NO\n "
print "Starting FCGI on port: #{port}\n "
system("#{OPTIONS[:spawner]} -f #{OPTIONS[:dispatcher]} -p #{port}")
rescue
print "YES\n"
class Spawner
def self.record_pid(name = "#{OPTIONS[:process]}.spawner", id = Process.pid)
FileUtils.mkdir_p(OPTIONS[:pids])
File.open(File.expand_path(OPTIONS[:pids] + "/#{name}.pid"), "w+") { |f| f.write(id) }
end
def self.spawn_all
OPTIONS[:instances].times do |i|
port = OPTIONS[:port] + i
print "Checking if something is already running on #{OPTIONS[:address]}:#{port}..."
begin
srv = TCPServer.new(OPTIONS[:address], port)
srv.close
srv = nil
puts "NO"
puts "Starting dispatcher on port: #{OPTIONS[:address]}:#{port}"
FileUtils.mkdir_p(OPTIONS[:pids])
spawn(port)
rescue
puts "YES"
end
end
end
end
def spawn_all
OPTIONS[:instances].times { |i| spawn(OPTIONS[:port] + i) }
class FcgiSpawner < Spawner
def self.spawn(port)
cmd = "#{OPTIONS[:spawner]} -f #{OPTIONS[:dispatcher]} -p #{port} -P #{OPTIONS[:pids]}/#{OPTIONS[:process]}.#{port}.pid"
cmd << " -a #{OPTIONS[:address]}" if can_bind_to_custom_address?
system(cmd)
end
def self.can_bind_to_custom_address?
@@can_bind_to_custom_address ||= /^\s-a\s/.match `#{OPTIONS[:spawner]} -h`
end
end
class MongrelSpawner < Spawner
def self.spawn(port)
cmd =
"mongrel_rails start -d " +
"-a #{OPTIONS[:address]} " +
"-p #{port} " +
"-P #{OPTIONS[:pids]}/#{OPTIONS[:process]}.#{port}.pid " +
"-e #{OPTIONS[:environment]} " +
"-c #{OPTIONS[:rails_root]} " +
"-l #{OPTIONS[:rails_root]}/log/mongrel.log"
system(cmd)
end
def self.can_bind_to_custom_address?
true
end
end
begin
require_library_or_gem 'fcgi'
rescue Exception
# FCGI not available
end
begin
require_library_or_gem 'mongrel'
rescue Exception
# Mongrel not available
end
server = case ARGV.first
when "fcgi", "mongrel"
ARGV.shift
else
if defined?(Mongrel)
"mongrel"
elsif RUBY_PLATFORM !~ /mswin/ && !silence_stderr { `spawn-fcgi -version` }.blank? && defined?(FCGI)
"fcgi"
end
end
case server
when "fcgi"
puts "=> Starting FCGI dispatchers"
spawner_class = FcgiSpawner
when "mongrel"
puts "=> Starting mongrel dispatchers"
spawner_class = MongrelSpawner
else
puts "Neither FCGI (spawn-fcgi) nor Mongrel was installed and available!"
exit(0)
end
OPTIONS = {
:environment => "production",
:spawner => '/usr/bin/env spawn-fcgi',
:dispatcher => File.expand_path(RAILS_ROOT + '/public/dispatch.fcgi'),
:pids => File.expand_path(RAILS_ROOT + "/tmp/pids"),
:rails_root => File.expand_path(RAILS_ROOT),
:process => "dispatch",
:port => 8000,
:address => '0.0.0.0',
:instances => 3,
:repeat => nil
}
ARGV.options do |opts|
opts.banner = "Usage: spawner [options]"
opts.banner = "Usage: spawner [platform] [options]"
opts.separator ""
opts.on <<-EOF
Description:
The spawner is a wrapper for spawn-fcgi that makes it easier to start multiple FCGI
processes running the Rails dispatcher. The spawn-fcgi command is included with the lighttpd
web server, but can be used with both Apache and lighttpd (and any other web server supporting
externally managed FCGI processes).
The spawner is a wrapper for spawn-fcgi and mongrel that makes it
easier to start multiple processes running the Rails dispatcher. The
spawn-fcgi command is included with the lighttpd web server, but can
be used with both Apache and lighttpd (and any other web server
supporting externally managed FCGI processes). Mongrel automatically
ships with with mongrel_rails for starting dispatchers.
You decide a starting port (default is 8000) and the number of FCGI process instances you'd
like to run. So if you pick 9100 and 3 instances, you'll start processes on 9100, 9101, and 9102.
The first choice you need to make is whether to spawn the Rails
dispatchers as FCGI or Mongrel. By default, this spawner will prefer
Mongrel, so if that's installed, and no platform choice is made,
Mongrel is used.
By setting the repeat option, you get a protection loop, which will attempt to restart any FCGI processes
that might have been exited or outright crashed.
Then decide a starting port (default is 8000) and the number of FCGI
process instances you'd like to run. So if you pick 9100 and 3
instances, you'll start processes on 9100, 9101, and 9102.
Examples:
spawner # starts instances on 8000, 8001, and 8002
spawner -p 9100 -i 10 # starts 10 instances counting from 9100 to 9109
spawner -p 9100 -r 5 # starts 3 instances counting from 9100 to 9102 and attempts start them every 5 seconds
By setting the repeat option, you get a protection loop, which will
attempt to restart any FCGI processes that might have been exited or
outright crashed.
You can select bind address for started processes. By default these
listen on every interface. For single machine installations you would
probably want to use 127.0.0.1, hiding them form the outside world.
Examples:
spawner # starts instances on 8000, 8001, and 8002
# using Mongrel if available.
spawner fcgi # starts instances on 8000, 8001, and 8002
# using FCGI.
spawner mongrel -i 5 # starts instances on 8000, 8001, 8002,
# 8003, and 8004 using Mongrel.
spawner -p 9100 -i 10 # starts 10 instances counting from 9100 to
# 9109 using Mongrel if available.
spawner -p 9100 -r 5 # starts 3 instances counting from 9100 to
# 9102 and attempts start them every 5
# seconds.
spawner -a 127.0.0.1 # starts 3 instances binding to localhost
EOF
opts.on(" Options:")
opts.on("-p", "--port=number", Integer, "Starting port number (default: #{OPTIONS[:port]})") { |OPTIONS[:port]| }
if spawner_class.can_bind_to_custom_address?
opts.on("-a", "--address=ip", String, "Bind to IP address (default: #{OPTIONS[:address]})") { |OPTIONS[:address]| }
end
opts.on("-p", "--port=number", Integer, "Starting port number (default: #{OPTIONS[:port]})") { |v| OPTIONS[:port] = v }
opts.on("-i", "--instances=number", Integer, "Number of instances (default: #{OPTIONS[:instances]})") { |v| OPTIONS[:instances] = v }
opts.on("-r", "--repeat=seconds", Integer, "Repeat spawn attempts every n seconds (default: off)") { |v| OPTIONS[:repeat] = v }
opts.on("-e", "--environment=name", String, "test|development|production (default: #{OPTIONS[:environment]})") { |v| OPTIONS[:environment] = v }
opts.on("-n", "--process=name", String, "default: #{OPTIONS[:process]}") { |v| OPTIONS[:process] = v }
opts.on("-s", "--spawner=path", String, "default: #{OPTIONS[:spawner]}") { |v| OPTIONS[:spawner] = v }
opts.on("-d", "--dispatcher=path", String, "default: #{OPTIONS[:dispatcher]}") { |dispatcher| OPTIONS[:dispatcher] = File.expand_path(dispatcher) }
@ -84,11 +198,12 @@ ENV["RAILS_ENV"] = OPTIONS[:environment]
if OPTIONS[:repeat]
daemonize
trap("TERM") { exit }
spawner_class.record_pid
loop do
spawn_all
spawner_class.spawn_all
sleep(OPTIONS[:repeat])
end
else
spawn_all
end
spawner_class.spawn_all
end

View file

@ -1,10 +1,11 @@
require 'optparse'
options = { :environment => (ENV['RAILS_ENV'] || "development").dup }
code_or_file = nil
ARGV.options do |opts|
ARGV.clone.options do |opts|
script_name = File.basename($0)
opts.banner = "Usage: runner 'puts Person.find(1).name' [options]"
opts.banner = "Usage: #{$0} [options] ('Some.ruby(code)' or a filename)"
opts.separator ""
@ -15,13 +16,33 @@ ARGV.options do |opts|
opts.separator ""
opts.on("-h", "--help",
"Show this help message.") { puts opts; exit }
"Show this help message.") { $stderr.puts opts; exit }
opts.parse!
if RUBY_PLATFORM !~ /mswin/
opts.separator ""
opts.separator "You can also use runner as a shebang line for your scripts like this:"
opts.separator "-------------------------------------------------------------"
opts.separator "#!/usr/bin/env #{File.expand_path($0)}"
opts.separator ""
opts.separator "Product.find(:all).each { |p| p.price *= 2 ; p.save! }"
opts.separator "-------------------------------------------------------------"
end
opts.order! { |o| code_or_file ||= o } rescue retry
end
ARGV.delete(code_or_file)
ENV["RAILS_ENV"] = options[:environment]
RAILS_ENV.replace(options[:environment]) if defined?(RAILS_ENV)
require RAILS_ROOT + '/config/environment'
ARGV.empty? ? puts("Usage: runner 'code' [options]") : eval(ARGV.first)
if code_or_file.nil?
$stderr.puts "Run '#{$0} -h' for help."
exit 1
elsif File.exists?(code_or_file)
eval(File.read(code_or_file))
else
eval(code_or_file)
end

View file

@ -7,24 +7,33 @@ rescue Exception
# FCGI not available
end
begin
require_library_or_gem 'mongrel'
rescue Exception
# Mongrel not available
end
server = case ARGV.first
when "lighttpd"
ARGV.shift
when "webrick"
when "lighttpd", "mongrel", "webrick"
ARGV.shift
else
if RUBY_PLATFORM !~ /mswin/ && !silence_stderr { `lighttpd -version` }.blank? && defined?(FCGI)
if defined?(Mongrel)
"mongrel"
elsif RUBY_PLATFORM !~ /mswin/ && !silence_stderr { `lighttpd -version` }.blank? && defined?(FCGI)
"lighttpd"
else
"webrick"
end
end
if server == "webrick"
puts "=> Booting WEBrick..."
else
puts "=> Booting lighttpd (use 'script/server webrick' to force WEBrick)"
case server
when "webrick"
puts "=> Booting WEBrick..."
when "lighttpd"
puts "=> Booting lighttpd (use 'script/server webrick' to force WEBrick)"
when "mongrel"
puts "=> Booting Mongrel (use 'script/server webrick' to force WEBrick)"
end
FileUtils.mkdir_p(%w( tmp/sessions tmp/cache tmp/sockets ))
%w(cache pids sessions sockets).each { |dir_to_make| FileUtils.mkdir_p(File.join(RAILS_ROOT, 'tmp', dir_to_make)) }
require "commands/servers/#{server}"

View file

@ -1,4 +1,5 @@
require 'rbconfig'
require 'commands/servers/base'
unless RUBY_PLATFORM !~ /mswin/ && !silence_stderr { `lighttpd -version` }.blank?
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.
require 'optparse'
detach = false
command_line_port = nil
ARGV.options do |opt|
opt.on("-p", "--port=port", "Changes the server.port number in the config/lighttpd.conf") { |port| command_line_port = port }
opt.on('-c', "--config=#{config_file}", 'Specify a different lighttpd config file.') { |path| config_file = path }
opt.on('-h', '--help', 'Show this message.') { puts opt; exit 0 }
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)
FileUtils.cp(source, config_file)
end
# open the config/lighttpd.conf file and add the current user defined port setting to it
if command_line_port
File.open(config_file, 'r+') do |config|
lines = config.readlines
lines.each do |line|
line.gsub!(/^\s*server.port\s*=\s*(\d+)/, "server.port = #{command_line_port}")
end
config.rewind
config.print(lines)
config.truncate(config.pos)
end
end
config = IO.read(config_file)
default_port, default_ip = 3000, '0.0.0.0'
port = config.scan(/^\s*server.port\s*=\s*(\d+)/).first rescue default_port
ip = config.scan(/^\s*server.bind\s*=\s*"([^"]+)"/).first rescue default_ip
puts "=> Rails application started on http://#{ip || default_ip}:#{port || default_port}"
puts "=> Rails application starting on http://#{ip || default_ip}:#{port || default_port}"
tail_thread = nil
@ -52,23 +70,7 @@ if !detach
puts "=> Call with -d to detach"
puts "=> Ctrl-C to shutdown server (see config/lighttpd.conf for options)"
detach = false
cursor = File.size(configuration.log_path)
last_checked = Time.now
tail_thread = Thread.new do
File.open(configuration.log_path, '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 = tail(configuration.log_path)
end
trap(:INT) { exit }