mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Implements an improved SwitchTower friendly mongrel_rails.
git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@61 19e92222-5c0b-0410-8929-a290d50e31e9
This commit is contained in:
parent
d8da355512
commit
e8d6936a04
4 changed files with 79 additions and 15 deletions
2
Rakefile
2
Rakefile
|
@ -30,7 +30,7 @@ end
|
|||
|
||||
setup_extension("http11", "http11")
|
||||
|
||||
version="0.3.6"
|
||||
version="0.3.7"
|
||||
summary = "A small fast HTTP library and server that runs Rails, Camping, and Nitro apps."
|
||||
test_file = "test/test_ws.rb"
|
||||
author="Zed A. Shaw"
|
||||
|
|
|
@ -117,19 +117,40 @@ class StartCommand < Mongrel::Command::Command
|
|||
end
|
||||
|
||||
def start_mongrel(rails)
|
||||
@restart = false
|
||||
|
||||
# start up mongrel with the right configurations
|
||||
server = Mongrel::HttpServer.new(@address, @port, @num_procs.to_i, @timeout.to_i)
|
||||
server.register("/", rails)
|
||||
server.run
|
||||
trap("INT") { server.stop }
|
||||
|
||||
# graceful shutdown
|
||||
trap("TERM") {
|
||||
server.stop
|
||||
}
|
||||
|
||||
# rails reload
|
||||
trap("HUP") {
|
||||
server.stop
|
||||
@restart = true
|
||||
}
|
||||
|
||||
# restart
|
||||
trap("USR2") {
|
||||
server.stop
|
||||
@restart = true
|
||||
}
|
||||
|
||||
begin
|
||||
puts "Server ready."
|
||||
STDERR.puts "Server ready."
|
||||
server.acceptor.join
|
||||
rescue Interrupt
|
||||
puts "Interrupted."
|
||||
STDERR.puts "Interrupted."
|
||||
raise
|
||||
end
|
||||
|
||||
# daemonize makes restart easy
|
||||
run if @restart
|
||||
end
|
||||
|
||||
def run
|
||||
|
@ -140,12 +161,24 @@ class StartCommand < Mongrel::Command::Command
|
|||
end
|
||||
|
||||
|
||||
def send_signal(signal, pid_file)
|
||||
pid = open(pid_file).read.to_i
|
||||
print "Sending #{signal} to Mongrel at PID #{pid}..."
|
||||
begin
|
||||
Process.kill(signal, pid)
|
||||
rescue Errno::ESRCH
|
||||
puts "Process does not exist. Not running."
|
||||
end
|
||||
|
||||
puts "Done."
|
||||
end
|
||||
|
||||
class StopCommand < Mongrel::Command::Command
|
||||
|
||||
def configure
|
||||
options [
|
||||
options [
|
||||
['-c', '--chdir PATH', "Change to dir before starting (will be expanded)", :@cwd, Dir.pwd],
|
||||
['-f', '--force', "Force the shutdown.", :@force, false],
|
||||
['-P', '--pid FILE', "Where to write the PID", :@pid_file, "log/mongrel.pid"]
|
||||
]
|
||||
end
|
||||
|
@ -162,16 +195,47 @@ class StopCommand < Mongrel::Command::Command
|
|||
|
||||
|
||||
def run
|
||||
pid = open(@pid_file).read.to_i
|
||||
print "Stopping Mongrel at PID #{pid}..."
|
||||
begin
|
||||
Process.kill("INT", pid)
|
||||
rescue Errno::ESRCH
|
||||
puts "Process does not exist. Not running."
|
||||
if @force
|
||||
send_signal("KILL", @pid_file)
|
||||
else
|
||||
send_signal("TERM", @pid_file)
|
||||
end
|
||||
|
||||
File.unlink(@pid_file)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
class RestartCommand < Mongrel::Command::Command
|
||||
|
||||
def configure
|
||||
options [
|
||||
['-c', '--chdir PATH', "Change to dir before starting (will be expanded)", :@cwd, Dir.pwd],
|
||||
['-s', '--soft', "Do a soft restart rather than a process exit restart", :@soft, false],
|
||||
['-P', '--pid FILE', "Where to write the PID", :@pid_file, "log/mongrel.pid"]
|
||||
]
|
||||
end
|
||||
|
||||
def validate
|
||||
@cwd = File.expand_path(@cwd)
|
||||
valid_dir? @cwd, "Invalid path to change to during daemon mode: #@cwd"
|
||||
|
||||
@pid_file = File.join(@cwd,@pid_file)
|
||||
valid_exists? @pid_file, "PID file #@pid_file does not exist. Not running?"
|
||||
|
||||
return @valid
|
||||
end
|
||||
|
||||
|
||||
def run
|
||||
if @soft
|
||||
send_signal("HUP", @pid_file)
|
||||
else
|
||||
send_signal("USR2", @pid_file)
|
||||
end
|
||||
|
||||
File.unlink(@pid_file)
|
||||
puts "Done."
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -118,7 +118,7 @@ module Mongrel
|
|||
SERVER_SOFTWARE='SERVER_SOFTWARE'
|
||||
|
||||
# Current Mongrel version (used for SERVER_SOFTWARE and other response headers).
|
||||
MONGREL_VERSION='Mongrel 0.3.6'
|
||||
MONGREL_VERSION='Mongrel 0.3.7'
|
||||
|
||||
# The standard empty 404 response for bad requests. Use Error4040Handler for custom stuff.
|
||||
ERROR_404_RESPONSE="HTTP/1.1 404 Not Found\r\nConnection: close\r\nServer: #{MONGREL_VERSION}\r\n\r\nNOT FOUND"
|
||||
|
|
|
@ -44,6 +44,7 @@ module Mongrel
|
|||
@valid = true
|
||||
# this is retarded, but it has to be done this way because -h and -v exit
|
||||
@done_validating = false
|
||||
@original_args = argv.dup
|
||||
|
||||
configure
|
||||
|
||||
|
@ -154,9 +155,8 @@ module Mongrel
|
|||
# Runs the args against the first argument as the command name.
|
||||
# If it has any errors it returns a false, otherwise it return true.
|
||||
def run(args)
|
||||
# find the command and change the program's name to reflect it
|
||||
# find the command
|
||||
cmd_name = args.shift
|
||||
$0 = "#{cmd_name}"
|
||||
|
||||
if !cmd_name or cmd_name == "?" or cmd_name == "help"
|
||||
print_command_list
|
||||
|
|
Loading…
Reference in a new issue