Checkout of Instiki Trunk 1/21/2007.
This commit is contained in:
commit
69b62b6f33
1138 changed files with 139586 additions and 0 deletions
92
vendor/rails/railties/lib/commands/servers/lighttpd.rb
vendored
Normal file
92
vendor/rails/railties/lib/commands/servers/lighttpd.rb
vendored
Normal file
|
@ -0,0 +1,92 @@
|
|||
require 'rbconfig'
|
||||
|
||||
unless RUBY_PLATFORM !~ /mswin/ && !silence_stderr { `lighttpd -version` }.blank?
|
||||
puts "PROBLEM: Lighttpd is not available on your system (or not in your path)"
|
||||
exit 1
|
||||
end
|
||||
|
||||
unless defined?(FCGI)
|
||||
puts "PROBLEM: Lighttpd requires that the FCGI Ruby bindings are installed on the system"
|
||||
exit 1
|
||||
end
|
||||
|
||||
require 'initializer'
|
||||
configuration = Rails::Initializer.run(:initialize_logger).configuration
|
||||
default_config_file = config_file = Pathname.new("#{RAILS_ROOT}/config/lighttpd.conf").cleanpath
|
||||
|
||||
require 'optparse'
|
||||
|
||||
detach = false
|
||||
|
||||
ARGV.options do |opt|
|
||||
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" }
|
||||
opt.parse!
|
||||
end
|
||||
|
||||
unless File.exist?(config_file)
|
||||
if config_file != default_config_file
|
||||
puts "=> #{config_file} not found."
|
||||
exit 1
|
||||
end
|
||||
|
||||
require 'fileutils'
|
||||
|
||||
source = File.expand_path(File.join(File.dirname(__FILE__),
|
||||
"..", "..", "..", "configs", "lighttpd.conf"))
|
||||
puts "=> #{config_file} not found, copying from #{source}"
|
||||
|
||||
FileUtils.cp(source, config_file)
|
||||
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}"
|
||||
|
||||
tail_thread = nil
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
trap(:INT) { exit }
|
||||
|
||||
begin
|
||||
`rake tmp:sockets:clear` # Needed if lighttpd crashes or otherwise leaves FCGI sockets around
|
||||
`lighttpd #{!detach ? "-D " : ""}-f #{config_file}`
|
||||
ensure
|
||||
unless detach
|
||||
tail_thread.kill if tail_thread
|
||||
puts 'Exiting'
|
||||
|
||||
# Ensure FCGI processes are reaped
|
||||
silence_stream(STDOUT) do
|
||||
ARGV.replace ['-a', 'kill']
|
||||
require 'commands/process/reaper'
|
||||
end
|
||||
|
||||
`rake tmp:sockets:clear` # Remove sockets on clean shutdown
|
||||
end
|
||||
end
|
59
vendor/rails/railties/lib/commands/servers/webrick.rb
vendored
Normal file
59
vendor/rails/railties/lib/commands/servers/webrick.rb
vendored
Normal file
|
@ -0,0 +1,59 @@
|
|||
require 'webrick'
|
||||
require 'optparse'
|
||||
|
||||
OPTIONS = {
|
||||
:port => 3000,
|
||||
:ip => "0.0.0.0",
|
||||
:environment => (ENV['RAILS_ENV'] || "development").dup,
|
||||
:server_root => File.expand_path(RAILS_ROOT + "/public/"),
|
||||
:server_type => WEBrick::SimpleServer,
|
||||
:charset => "UTF-8",
|
||||
:mime_types => WEBrick::HTTPUtils::DefaultMimeTypes
|
||||
}
|
||||
|
||||
ARGV.options do |opts|
|
||||
script_name = File.basename($0)
|
||||
opts.banner = "Usage: ruby #{script_name} [options]"
|
||||
|
||||
opts.separator ""
|
||||
|
||||
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("-e", "--environment=name", String,
|
||||
"Specifies the environment to run this server under (test/development/production).",
|
||||
"Default: development") { |v| OPTIONS[:environment] = v }
|
||||
opts.on("-m", "--mime-types=filename", String,
|
||||
"Specifies an Apache style mime.types configuration file to be used for mime types",
|
||||
"Default: none") { |mime_types_file| OPTIONS[:mime_types] = WEBrick::HTTPUtils::load_mime_types(mime_types_file) }
|
||||
|
||||
opts.on("-d", "--daemon",
|
||||
"Make Rails run as a Daemon (only works if fork is available -- meaning on *nix)."
|
||||
) { OPTIONS[:server_type] = WEBrick::Daemon }
|
||||
|
||||
opts.on("-c", "--charset=charset", String,
|
||||
"Set default charset for output.",
|
||||
"Default: UTF-8") { |v| OPTIONS[:charset] = v }
|
||||
|
||||
opts.separator ""
|
||||
|
||||
opts.on("-h", "--help",
|
||||
"Show this help message.") { puts opts; exit }
|
||||
|
||||
opts.parse!
|
||||
end
|
||||
|
||||
ENV["RAILS_ENV"] = OPTIONS[:environment]
|
||||
RAILS_ENV.replace(OPTIONS[:environment]) if defined?(RAILS_ENV)
|
||||
|
||||
require RAILS_ROOT + "/config/environment"
|
||||
require 'webrick_server'
|
||||
|
||||
OPTIONS['working_directory'] = File.expand_path(RAILS_ROOT)
|
||||
|
||||
puts "=> Rails application started on http://#{OPTIONS[:ip]}:#{OPTIONS[:port]}"
|
||||
puts "=> Ctrl-C to shutdown server; call with --help for options" if OPTIONS[:server_type] == WEBrick::SimpleServer
|
||||
DispatchServlet.dispatch(OPTIONS)
|
Loading…
Add table
Add a link
Reference in a new issue