works but need some cleanup
This commit is contained in:
parent
0ec83db287
commit
e40a859b7d
752 changed files with 4866 additions and 27923 deletions
|
@ -1,4 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
require File.dirname(__FILE__) + '/../config/boot'
|
||||
$LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info"
|
||||
require 'commands/about'
|
|
@ -1,19 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
if ARGV.empty?
|
||||
puts "Usage: benchmarker times 'Person.expensive_way' 'Person.another_expensive_way' ..."
|
||||
exit
|
||||
end
|
||||
|
||||
require File.dirname(__FILE__) + '/../config/environment'
|
||||
require 'benchmark'
|
||||
include Benchmark
|
||||
|
||||
# Don't include compilation in the benchmark
|
||||
ARGV[1..-1].each { |expression| eval(expression) }
|
||||
|
||||
bm(6) do |x|
|
||||
ARGV[1..-1].each_with_index do |expression, idx|
|
||||
x.report("##{idx + 1}") { ARGV[0].to_i.times { eval(expression) } }
|
||||
end
|
||||
end
|
|
@ -1,3 +0,0 @@
|
|||
#!/usr/bin/ruby18
|
||||
require File.dirname(__FILE__) + '/../config/boot'
|
||||
require 'commands/breakpointer'
|
|
@ -1,3 +0,0 @@
|
|||
#!/usr/bin/ruby18
|
||||
require File.dirname(__FILE__) + '/../config/boot'
|
||||
require 'commands/console'
|
|
@ -1,7 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
ActiveRecord::Base.lock_mutex
|
||||
ActiveRecord::Base.connection.begin_db_transaction
|
||||
at_exit do
|
||||
ActiveRecord::Base.connection.rollback_db_transaction
|
||||
ActiveRecord::Base.unlock_mutex
|
||||
end
|
|
@ -1,3 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
require File.dirname(__FILE__) + '/../config/boot'
|
||||
require 'commands/dbconsole'
|
|
@ -1,3 +0,0 @@
|
|||
#!/usr/bin/ruby18
|
||||
require File.dirname(__FILE__) + '/../config/boot'
|
||||
require 'commands/destroy'
|
|
@ -1,3 +0,0 @@
|
|||
#!/usr/bin/ruby18
|
||||
require File.dirname(__FILE__) + '/../config/boot'
|
||||
require 'commands/generate'
|
|
@ -1,2 +0,0 @@
|
|||
#!/bin/sh
|
||||
lighttpd -D -f config/lighttpd.conf
|
|
@ -1,47 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require 'fileutils'
|
||||
include FileUtils
|
||||
|
||||
require File.dirname(__FILE__) + "/../config/environment"
|
||||
|
||||
# RAILS_ROOT is just one up
|
||||
RAILS_ROOT = File.expand_path(File.dirname(__FILE__) + '/..')
|
||||
include Mailr::Localization
|
||||
|
||||
|
||||
# goto RAILS_ROOT so we can address all files relatively from there
|
||||
Dir.chdir(RAILS_ROOT)
|
||||
|
||||
# directories and extensions to harvest
|
||||
dirpattern = '{app,components,lib}'
|
||||
extpattern = 'r{b,html,xml}'
|
||||
|
||||
total_replacements = 0
|
||||
|
||||
Dir.glob("#{dirpattern}/**/*.#{extpattern}").each do |f|
|
||||
next if f == 'lib/localization.rb'
|
||||
puts "Scanning file #{f}"
|
||||
fc = ""
|
||||
re = /l[ ]?\(\:([a-z0-9\_\-]*)[ ]?\)/
|
||||
File.open(f, "r").each_line { |line| fc << line}
|
||||
has_replacements = 0
|
||||
# remeber that it will not work if there are localized messages with parameters
|
||||
# e.g. l(:key, param1, param2) - this should be fixed locally with:
|
||||
# sprintf(_('message'), param1, param2
|
||||
fc = fc.gsub(re) { |match|
|
||||
result = ""
|
||||
has_replacements = has_replacements + 1
|
||||
total_replacements = total_replacements + 1
|
||||
match.scan(re) { |token|
|
||||
result = "_('"<<eval("l(:#{token})").gsub("'", "\\'") << "')"
|
||||
}
|
||||
result
|
||||
}
|
||||
f = File.open(f, "w")
|
||||
f << fc
|
||||
f.close
|
||||
puts "... #{has_replacements} replacements made." if has_replacements > 0
|
||||
end
|
||||
|
||||
puts "Done - #{total_replacements} total replacements made."
|
|
@ -1,48 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
# we need fileutils for easy file access
|
||||
require 'fileutils'
|
||||
require 'rubygems'
|
||||
include FileUtils
|
||||
# we will need the modified rgettext.rb that can read erb templates
|
||||
require File.dirname(__FILE__) + '/rgettext'
|
||||
|
||||
|
||||
# RAILS_ROOT is just one up
|
||||
RAILS_ROOT = File.expand_path(File.dirname(__FILE__) + '/..')
|
||||
# $DEBUG = true
|
||||
# goto RAILS_ROOT so we can address all files relatively from there
|
||||
Dir.chdir(RAILS_ROOT)
|
||||
|
||||
# the potfile will hold the temporary data before it is merged; note the
|
||||
# filename .messages.pot (if you don't prepend a dot to the filename Dir.glob
|
||||
# will get confused later on)
|
||||
potfile = "#{RAILS_ROOT}/locale/.messages.pot"
|
||||
|
||||
# if the potfile exists from the previous run, delete it
|
||||
rm_f potfile
|
||||
|
||||
# directories and extensions to harvest
|
||||
dirpattern = '{app,components,config,custom,lib}'
|
||||
extpattern = 'r{b,html,xml}'
|
||||
files = Dir.glob("#{dirpattern}/**/*.#{extpattern}")
|
||||
|
||||
# run the harvester on the collected filenames and output to potfile
|
||||
RGettext.new.start files, potfile
|
||||
|
||||
# now iterate through all locale dirs and update/merge
|
||||
Dir.glob('locale/*').each do |dir|
|
||||
# check if every dir has a pofile to begin with, else msmerge will fail
|
||||
# if not, use the potfile and don't merge
|
||||
pofile = "#{RAILS_ROOT}/#{dir}/LC_MESSAGES/messages.po"
|
||||
if File.exists?(pofile)
|
||||
print "Updating pofile #{pofile} "
|
||||
system "msgmerge --force-po --no-location --update #{pofile} #{potfile}"
|
||||
else
|
||||
print "The pofile '#{pofile}' does not exist. I will create it for you "
|
||||
path_to_pofile = File.dirname(pofile)
|
||||
mkdir path_to_pofile unless File.exists?(path_to_pofile)
|
||||
cp potfile, pofile
|
||||
puts ' .... done.'
|
||||
end
|
||||
end
|
|
@ -1,3 +0,0 @@
|
|||
#!/usr/bin/ruby18
|
||||
require File.dirname(__FILE__) + '/../../config/boot'
|
||||
require 'commands/performance/benchmarker'
|
|
@ -1,3 +0,0 @@
|
|||
#!/usr/bin/ruby18
|
||||
require File.dirname(__FILE__) + '/../../config/boot'
|
||||
require 'commands/performance/profiler'
|
|
@ -1,3 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
require File.dirname(__FILE__) + '/../../config/boot'
|
||||
require 'commands/performance/request'
|
|
@ -1,3 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
require File.dirname(__FILE__) + '/../config/boot'
|
||||
require 'commands/plugin'
|
|
@ -1,3 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
require File.dirname(__FILE__) + '/../../config/boot'
|
||||
require 'commands/process/inspector'
|
|
@ -1,3 +0,0 @@
|
|||
#!/usr/bin/ruby18
|
||||
require File.dirname(__FILE__) + '/../../config/boot'
|
||||
require 'commands/process/reaper'
|
|
@ -1,3 +0,0 @@
|
|||
#!/usr/bin/ruby18
|
||||
require File.dirname(__FILE__) + '/../../config/boot'
|
||||
require 'commands/process/spawner'
|
|
@ -1,3 +0,0 @@
|
|||
#!/usr/bin/ruby18
|
||||
require File.dirname(__FILE__) + '/../../config/boot'
|
||||
require 'commands/process/spinner'
|
|
@ -1,34 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
if ARGV.empty?
|
||||
$stderr.puts "Usage: profiler 'Person.expensive_method(10)' [times]"
|
||||
exit(1)
|
||||
end
|
||||
|
||||
# Keep the expensive require out of the profile.
|
||||
$stderr.puts 'Loading Rails...'
|
||||
require File.dirname(__FILE__) + '/../config/environment'
|
||||
|
||||
# Define a method to profile.
|
||||
if ARGV[1] and ARGV[1].to_i > 1
|
||||
eval "def profile_me() #{ARGV[1]}.times { #{ARGV[0]} } end"
|
||||
else
|
||||
eval "def profile_me() #{ARGV[0]} end"
|
||||
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)
|
||||
rescue LoadError
|
||||
$stderr.puts 'Using the standard Ruby profiler.'
|
||||
Profiler__.start_profile
|
||||
profile_me
|
||||
Profiler__.stop_profile
|
||||
Profiler__.print_profile($stderr)
|
||||
end
|
6
script/rails
Executable file
6
script/rails
Executable file
|
@ -0,0 +1,6 @@
|
|||
#!/usr/bin/env ruby18
|
||||
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
||||
|
||||
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
||||
require File.expand_path('../../config/boot', __FILE__)
|
||||
require 'rails/commands'
|
|
@ -1,215 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
=begin
|
||||
rgettext - ruby version of xgettext
|
||||
Copyright (C) 2005 Sascha Ebach
|
||||
Copyright (C) 2003,2004 Masao Mutoh
|
||||
Copyright (C) 2001,2002 Yasushi Shoji, Masao Mutoh
|
||||
|
||||
Yasushi Shoji <yashi@yashi.com>
|
||||
Masao Mutoh <mutoh@highway.ne.jp>
|
||||
Sascha Ebach <se@digitale-wertschoepfung.de>
|
||||
|
||||
You may redistribute it and/or modify it under the same
|
||||
license terms as Ruby.
|
||||
|
||||
2005-03-12: Added support for eruby templates (Sascha Ebach)
|
||||
2005-03-20: Added second parameter to RGetext.start to allow different
|
||||
output when not called from the command line. Pulled out
|
||||
RGetext.set_output().
|
||||
|
||||
=end
|
||||
|
||||
require 'gettext/parser/ruby'
|
||||
require 'gettext/parser/glade'
|
||||
|
||||
require 'getoptlong'
|
||||
require 'gettext'
|
||||
|
||||
require 'tempfile'
|
||||
require 'erb'
|
||||
|
||||
class RGettext
|
||||
include GetText
|
||||
|
||||
# constant values
|
||||
VERSION = %w($Revision: 1.15 $)[1].scan(/\d+/).collect {|s| s.to_i}
|
||||
DATE = %w($Date: 2004/11/05 18:19:08 $)[1]
|
||||
MAX_LINE_LEN = 70
|
||||
|
||||
def start(files=ARGV, output = nil)
|
||||
opt = check_options
|
||||
opt['output'] = output unless output.nil?
|
||||
set_output(opt)
|
||||
|
||||
|
||||
if files.empty?
|
||||
print_help
|
||||
exit
|
||||
end
|
||||
|
||||
ary = []
|
||||
files.each do |file|
|
||||
begin
|
||||
$stderr.puts "Processing #{file}"
|
||||
if glade_file?(file)
|
||||
ary = GladeParser.parse(file, ary)
|
||||
elsif erb_file?(file)
|
||||
content = File.open(file, 'r') {|f| f.read }
|
||||
tf = Tempfile.new('erb-gettext')
|
||||
tf.puts ERB.new(content).src
|
||||
tf.close
|
||||
old_index = ary.size - 1
|
||||
ary = GetText::RubyParser.parse(tf.path, ary)
|
||||
#replace tokens with /tmp/... with real file names
|
||||
for i in old_index..ary.size-1
|
||||
for j in 0..ary[i].size-1
|
||||
ary[i][j] = ary[i][j].gsub("#{tf.path}", file)
|
||||
end
|
||||
end
|
||||
tf.close true
|
||||
else
|
||||
ary = RubyParser.parse(file, ary)
|
||||
end
|
||||
rescue
|
||||
puts $!
|
||||
exit 1
|
||||
end
|
||||
end
|
||||
generate_pot_header
|
||||
generate_pot(ary)
|
||||
@out.close
|
||||
end
|
||||
|
||||
# following methods are
|
||||
private
|
||||
XML_RE = /<\?xml/
|
||||
GLADE_RE = /glade-2.0.dtd/
|
||||
|
||||
def erb_file?(file)
|
||||
File.extname(file) == '.rhtml'
|
||||
end
|
||||
|
||||
def glade_file?(file)
|
||||
data = IO.readlines(file)
|
||||
if XML_RE =~ data[0]
|
||||
if GLADE_RE =~ data[1]
|
||||
return true
|
||||
else
|
||||
raise _("%s is not glade-2.0 format.") % [file]
|
||||
end
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
def initialize
|
||||
bindtextdomain("rgettext")
|
||||
end
|
||||
|
||||
def generate_pot_header
|
||||
time = Time.now.strftime("%Y-%m-%d %H:%M%z")
|
||||
@out << "# SOME DESCRIPTIVE TITLE.\n"
|
||||
@out << "# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER\n"
|
||||
@out << "# This file is distributed under the same license as the PACKAGE package.\n"
|
||||
@out << "# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.\n"
|
||||
@out << "#\n"
|
||||
@out << "#, fuzzy\n"
|
||||
@out << "msgid \"\"\n"
|
||||
@out << "msgstr \"\"\n"
|
||||
@out << "\"Project-Id-Version: PACKAGE VERSION\\n\"\n"
|
||||
@out << "\"POT-Creation-Date: #{time}\\n\"\n"
|
||||
@out << "\"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n\"\n"
|
||||
@out << "\"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n\"\n"
|
||||
@out << "\"Language-Team: LANGUAGE <LL@li.org>\\n\"\n"
|
||||
@out << "\"MIME-Version: 1.0\\n\"\n"
|
||||
@out << "\"Content-Type: text/plain; charset=UTF-8\\n\"\n"
|
||||
@out << "\"Content-Transfer-Encoding: 8bit\\n\"\n"
|
||||
@out << "\"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\\n\"\n"
|
||||
end
|
||||
|
||||
def generate_pot(ary)
|
||||
result = Array.new
|
||||
ary.each do |key|
|
||||
msgid = key.shift
|
||||
curr_pos = MAX_LINE_LEN
|
||||
key.each do |e|
|
||||
if curr_pos + e.size > MAX_LINE_LEN
|
||||
@out << "\n#:"
|
||||
curr_pos = 3
|
||||
else
|
||||
curr_pos += (e.size + 1)
|
||||
end
|
||||
@out << " " << e
|
||||
end
|
||||
msgid.gsub!(/"/, '\"')
|
||||
msgid.gsub!(/\r/, '')
|
||||
if msgid.include?("\000")
|
||||
ids = msgid.split(/\000/)
|
||||
@out << "\nmsgid \"" << ids[0] << "\"\n"
|
||||
@out << "msgid_plural \"" << ids[1] << "\"\n"
|
||||
@out << "msgstr[0] \"\"\n"
|
||||
@out << "msgstr[1] \"\"\n"
|
||||
else
|
||||
@out << "\nmsgid \"" << msgid << "\"\n"
|
||||
@out << "msgstr \"\"\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def print_help
|
||||
printf _("Usage: %s input.rb -o output.pot\n"), $0
|
||||
print _("Extract translatable strings from given input files.\n\n")
|
||||
end
|
||||
|
||||
def check_options
|
||||
command_options = [
|
||||
['--help', '-h', GetoptLong::NO_ARGUMENT], #'print this help and exit'],
|
||||
['--version', '-v', GetoptLong::NO_ARGUMENT], #'print version info and exit'],
|
||||
['--output', '-o', GetoptLong::REQUIRED_ARGUMENT]#, ['FILE', 'write output to specified file']]
|
||||
]
|
||||
|
||||
parser = GetoptLong.new
|
||||
parser.set_options(*command_options)
|
||||
|
||||
opt = Hash.new
|
||||
parser.each do |name, arg|
|
||||
opt.store(name.sub(/^--/, ""), arg || true)
|
||||
end
|
||||
|
||||
if opt['version']
|
||||
print "#{$0} #{VERSION.join('.')} \(#{DATE}\)\n\n"
|
||||
exit
|
||||
end
|
||||
|
||||
if opt['help']
|
||||
print_help
|
||||
exit
|
||||
end
|
||||
|
||||
opt
|
||||
end
|
||||
|
||||
def set_output(opt)
|
||||
if opt['output']
|
||||
unless FileTest.exist? opt['output']
|
||||
@out = File.new(File.expand_path(opt['output']), "w+")
|
||||
else
|
||||
if $>.tty?
|
||||
# FIXME
|
||||
printf $stderr, "File '#{opt['output']}' already exists\n"
|
||||
exit 1
|
||||
else
|
||||
printf $stderr, "File '#{opt['output']}' already exists"
|
||||
exit 1
|
||||
end
|
||||
end
|
||||
else
|
||||
@out = STDOUT
|
||||
end
|
||||
end
|
||||
end # class RGettext
|
||||
|
||||
if __FILE__ == $0 # in case we want to start it from somewhere else
|
||||
rgettext = RGettext.new
|
||||
rgettext.start
|
||||
end
|
|
@ -1,3 +0,0 @@
|
|||
#!/usr/bin/ruby18
|
||||
require File.dirname(__FILE__) + '/../config/boot'
|
||||
require 'commands/runner'
|
|
@ -1,339 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require 'stringio'
|
||||
require 'yaml'
|
||||
require 'digest/sha1'
|
||||
require 'logger'
|
||||
require 'fileutils'
|
||||
require 'socket'
|
||||
require 'cgi'
|
||||
require 'rubygems'
|
||||
require 'cmdparse'
|
||||
require 'monitor'
|
||||
|
||||
def log(msg)
|
||||
$stderr.print msg,"\n"
|
||||
end
|
||||
|
||||
def error(msg, exc=nil)
|
||||
if exc
|
||||
$stderr.print "ERROR: #{msg}: #{exc}\n"
|
||||
$stderr.puts exc.backtrace
|
||||
else
|
||||
$stderr.print "ERROR: #{msg}\n"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Modifies CGI so that we can use it.
|
||||
class SCGIFixed < ::CGI
|
||||
public :env_table
|
||||
|
||||
def initialize(params, data, out, *args)
|
||||
@env_table = params
|
||||
@args = *args
|
||||
@input = StringIO.new(data)
|
||||
@out = out
|
||||
super(*args)
|
||||
end
|
||||
def args
|
||||
@args
|
||||
end
|
||||
def env_table
|
||||
@env_table
|
||||
end
|
||||
def stdinput
|
||||
@input
|
||||
end
|
||||
def stdoutput
|
||||
@out
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
class SCGIProcessor < Monitor
|
||||
|
||||
def initialize(settings)
|
||||
@env = settings[:env] || "development"
|
||||
@debug = settings[:debug] || false
|
||||
@host = settings[:host] || "127.0.0.1"
|
||||
@port = settings[:port] || "9999"
|
||||
@children = settings[:children] || 1
|
||||
@pid_file = settings[:pid_file] || "children.yaml"
|
||||
@status_dir = settings[:status_dir] || "/tmp"
|
||||
@log_file = settings[:logfile] || "log/scgi.log"
|
||||
@maxconns = settings[:maxconns]
|
||||
@busy_msg = settings[:busy_msg] || "BUSY"
|
||||
@settings = settings
|
||||
@started = Time.now
|
||||
@conns = 0
|
||||
@total_conns = 0
|
||||
@errors = 0
|
||||
|
||||
if @maxconns
|
||||
@maxconns = @maxconns.to_i
|
||||
else
|
||||
@maxconns = 2**30-1
|
||||
end
|
||||
|
||||
if settings[:conns_second]
|
||||
@throttle_sleep = 1.0/settings[:conns_second].to_i
|
||||
end
|
||||
|
||||
super()
|
||||
end
|
||||
|
||||
def run
|
||||
ENV['RAILS_ENV'] = @env
|
||||
|
||||
begin
|
||||
require_gem 'rails'
|
||||
require "config/environment"
|
||||
rescue Object
|
||||
error("loading rails environment", $!)
|
||||
end
|
||||
|
||||
server = TCPServer.new(@host, @port)
|
||||
|
||||
if @debug
|
||||
log("Listening for connections on #@host:#@port")
|
||||
listen(server)
|
||||
else
|
||||
childpids = []
|
||||
@children.to_i.times do
|
||||
# fork each child listening to the same port. very simple yet effective way to spread the load
|
||||
# to multiple processes without using threads and still using high performance libevent
|
||||
begin
|
||||
pid = fork do
|
||||
$stderr = open(@log_file,"w")
|
||||
$stderr.sync = false
|
||||
listen(server)
|
||||
end
|
||||
childpids << pid
|
||||
Process.detach(pid)
|
||||
rescue Object
|
||||
error("Could not fork child processes. Your system might not support fork. Use -D instead.", $!)
|
||||
end
|
||||
end
|
||||
|
||||
# tell the user what the sha1 is so they can check for modification later
|
||||
log("#@pid_file will have SHA1 #{Digest::SHA1.hexdigest(YAML.dump(childpids))}")
|
||||
log("Record this somewhere so you know if it was modified later by someone else.")
|
||||
# all children forked and the pids are now ready to write to the pid file
|
||||
open(@pid_file,"w") { |f| f.write(YAML.dump(childpids)) }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def listen(socket)
|
||||
thread = Thread.new do
|
||||
while true
|
||||
handle_client(socket.accept)
|
||||
sleep @throttle_sleep if @throttle_sleep
|
||||
|
||||
@total_conns += 1
|
||||
end
|
||||
end
|
||||
|
||||
begin
|
||||
thread.join
|
||||
rescue Interrupt
|
||||
log("Shutting down from SIGINT.")
|
||||
rescue Object
|
||||
error("while listening for connections on #@host:#@port", $!)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def handle_client(socket)
|
||||
Thread.new do
|
||||
begin
|
||||
synchronize { @conns += 1}
|
||||
|
||||
len = ""
|
||||
# we only read 10 bytes of the length. any request longer than this is invalid
|
||||
while len.length <= 10
|
||||
c = socket.read(1)
|
||||
if c == ':'
|
||||
# found the terminal, len now has a length in it so read the payload
|
||||
break
|
||||
else
|
||||
len << c
|
||||
end
|
||||
end
|
||||
|
||||
# we should now either have a payload length to get
|
||||
payload = socket.read(len.to_i)
|
||||
if (c = socket.read(1)) != ','
|
||||
error("Malformed request, does not end with ','")
|
||||
else
|
||||
read_header(socket, payload, @conns)
|
||||
end
|
||||
rescue IOError
|
||||
error("received IOError #$! when handling client. Your web server doesn't like me.")
|
||||
rescue Object
|
||||
@errors += 1
|
||||
error("after accepting client #@host:#@port -- #{$!.class}", $!)
|
||||
ensure
|
||||
synchronize { @conns -= 1}
|
||||
socket.close if not socket.closed?
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
def read_header(socket, payload, conns)
|
||||
return if socket.closed?
|
||||
request = split_body(payload)
|
||||
if request and request["CONTENT_LENGTH"]
|
||||
length = request["CONTENT_LENGTH"].to_i
|
||||
if length > 0
|
||||
body = socket.read(length)
|
||||
else
|
||||
body = ""
|
||||
end
|
||||
|
||||
if @conns > @maxconns
|
||||
socket.write("Content-type: text/plain\r\n\r\n")
|
||||
socket.write(@busy_msg)
|
||||
else
|
||||
process_request(request, body, socket)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def process_request(request, body, socket)
|
||||
return if socket.closed?
|
||||
cgi = SCGIFixed.new(request, body, socket)
|
||||
begin
|
||||
synchronize do
|
||||
# unfortuneatly, the dependencies.rb file is not thread safe and will throw exceptions
|
||||
# claiming that Dispatcher is not defined, or that other classes are missing. We have
|
||||
# to sync the dispatch call to get around this.
|
||||
Dispatcher.dispatch(cgi, ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, cgi.stdoutput)
|
||||
end
|
||||
rescue IOError
|
||||
error("received IOError #$! when handling client. Your web server doesn't like me.")
|
||||
rescue Object => rails_error
|
||||
error("calling Dispatcher.dispatch", rails_error)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def split_body(data)
|
||||
result = {}
|
||||
el = data.split("\0")
|
||||
i = 0
|
||||
len = el.length
|
||||
while i < len
|
||||
result[el[i]] = el[i+1]
|
||||
i += 1
|
||||
end
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
def status
|
||||
pid = Process.pid
|
||||
open("#@status_dir/scgi_rails-status.#{pid}","w") do |f|
|
||||
status = {
|
||||
'time' => Time.now, 'pid' => pid, 'settings' => @settings,
|
||||
'env' => @env, 'status_dir' => @status_dir, 'started' => @started,
|
||||
'max_conns' => @maxconns, 'total_conns' => @total_conns,
|
||||
'conns' => @conns, 'errors' => @errors, 'systimes' => Process.times
|
||||
}
|
||||
f.write(YAML.dump(status))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def signal_children(pidfile, signal)
|
||||
if not File.exists? pidfile
|
||||
log("No #{pidfile} as specified. Probably nothing running or wrong path.")
|
||||
exit 1
|
||||
end
|
||||
|
||||
childpids = YAML.load_file(pidfile)
|
||||
childpids.each do |pid|
|
||||
begin
|
||||
log("Signaling pid #{pid}")
|
||||
Process.kill(signal, pid)
|
||||
rescue Object
|
||||
log("Couldn't send #{signal} signal to #{pid} pid.")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def make_command(parent, name, desc, options)
|
||||
cmd = CmdParse::Command.new(name, false )
|
||||
cmd.short_desc = desc
|
||||
settings = {}
|
||||
cmd.options = CmdParse::OptionParserWrapper.new do |opt|
|
||||
options.each do |short, long, info, symbol|
|
||||
opt.on(short, long, info) {|val| settings[symbol] = val}
|
||||
end
|
||||
end
|
||||
cmd.set_execution_block do |args|
|
||||
yield(settings, args)
|
||||
end
|
||||
parent.add_command(cmd)
|
||||
end
|
||||
|
||||
|
||||
cmd = CmdParse::CommandParser.new( true )
|
||||
cmd.program_name = "scgi_rails"
|
||||
cmd.program_version = [0, 2, 1]
|
||||
cmd.options = CmdParse::OptionParserWrapper.new do |opt|
|
||||
opt.separator "Global options:"
|
||||
opt.on("--verbose", "Be verbose when outputting info") {|t| $verbose = true }
|
||||
end
|
||||
|
||||
cmd.add_command( CmdParse::HelpCommand.new )
|
||||
cmd.add_command( CmdParse::VersionCommand.new )
|
||||
|
||||
make_command(cmd, 'start', "Start Rails Application",
|
||||
[['-e','--env STRING','Rails environment', :env],
|
||||
['-D','--[no-]debug', 'Do not fork children, stay in foreground.', :debug],
|
||||
['-h','--host STRING', 'IP address to bind as server', :host],
|
||||
['-p','--port NUMBER', 'Port to bind to', :port],
|
||||
['-c','--children NUMBER', 'Number of children to start (not win32)', :children],
|
||||
['-f','--pid-file PATH', 'Where to read the list of running children', :pid_file],
|
||||
['-l','--log-file PATH', 'Use a different log from from log/scgi.log', :logfile],
|
||||
['-t','--throttle NUMBER', 'Max conn/second to allow.', :conns_second],
|
||||
['-m','--max-conns NUMBER', 'Max simultaneous connections before the busy message', :maxconns],
|
||||
['-b','--busy-msg', 'Busy message given to clients over the max connections ("busy")', :busy_msg],
|
||||
['-s','--status-dir PATH', 'Where to put the status files', :status_dir]]) do |settings, args|
|
||||
scgi = SCGIProcessor.new(settings)
|
||||
begin
|
||||
trap("HUP") { scgi.status }
|
||||
rescue Object
|
||||
error("Could not setup a SIGHUP handler. You won't be able to get status.")
|
||||
end
|
||||
|
||||
scgi.run
|
||||
end
|
||||
|
||||
|
||||
make_command(cmd, 'status', "Get status from all running children",
|
||||
[['-s','--status-dir PATH', 'Where to put the status files', :status_dir],
|
||||
['-f','--pid-file PATH', 'Where to read the list of running children', :pid_file]]) do |settings, args|
|
||||
signal_children(settings[:pid_file] || 'children.yaml', "HUP")
|
||||
log("Status files for each child should show up in the configured status directory (/tmp by default).")
|
||||
end
|
||||
|
||||
make_command(cmd, 'stop', "Stop all running children",
|
||||
[['-s','--sig SIGNAL', 'Where to put the status files', :signal],
|
||||
['-n','--[no-]delete', 'Keep the children.yaml file rather than delete', :nodelete],
|
||||
['-f','--pid-file PATH', 'Where to read the list of running children', :pid_file]]) do |settings, args|
|
||||
pid_file = settings[:pid_file] || "children.yaml"
|
||||
signal_children(pid_file, settings[:signal] || "INT")
|
||||
if not settings[:nodelete] and File.exist?(pid_file)
|
||||
File.unlink(pid_file)
|
||||
end
|
||||
end
|
||||
|
||||
cmd.parse
|
|
@ -1,3 +0,0 @@
|
|||
#!/usr/bin/ruby18
|
||||
require File.dirname(__FILE__) + '/../config/boot'
|
||||
require 'commands/server'
|
Loading…
Add table
Add a link
Reference in a new issue