mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Made the reaper talk to the spinner to make it spin faster during restarts and slower afterwards
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1931 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
65e4e5e337
commit
5b8b9178b3
2 changed files with 35 additions and 20 deletions
|
@ -60,16 +60,22 @@ class ProgramProcess
|
|||
`kill -9 #{@pid}`
|
||||
end
|
||||
|
||||
def usr1
|
||||
`kill -s USR1 #{@pid}`
|
||||
end
|
||||
|
||||
def to_s
|
||||
"[#{@pid}] #{@command}"
|
||||
end
|
||||
end
|
||||
|
||||
OPTIONS = {
|
||||
:action => "graceful",
|
||||
:dispatcher => File.expand_path(File.dirname(__FILE__) + '/../../public/dispatch.fcgi'),
|
||||
:iterations => 10,
|
||||
:nudge => false
|
||||
:action => "graceful",
|
||||
:dispatcher => File.expand_path(File.dirname(__FILE__) + '/../../public/dispatch.fcgi'),
|
||||
:spinner => File.expand_path(File.dirname(__FILE__) + '/spinner'),
|
||||
:toggle_spin => true,
|
||||
:iterations => 10,
|
||||
:nudge => false
|
||||
}
|
||||
|
||||
ARGV.options do |opts|
|
||||
|
@ -97,9 +103,7 @@ ARGV.options do |opts|
|
|||
FCGI process you have running if they're setup in a round-robin. Be sure to do one nudge per FCGI process
|
||||
across all your servers. So three servers with 10 processes each should nudge 30 times to be sure all processes
|
||||
are restarted.
|
||||
|
||||
NOTE: You're responsible for restarting the processes after they exit. This can be automated by using
|
||||
the spinner.
|
||||
|
||||
Examples:
|
||||
reaper -a reload
|
||||
reaper -n http://www.example.com -i 10 # gracefully exit, nudge 10 times
|
||||
|
@ -109,6 +113,8 @@ ARGV.options do |opts|
|
|||
|
||||
opts.on("-a", "--action=name", "reload|graceful|kill (default: #{OPTIONS[:action]})", String) { |OPTIONS[:action]| }
|
||||
opts.on("-d", "--dispatcher=path", "default: #{OPTIONS[:dispatcher]}", String) { |OPTIONS[:dispatcher]| }
|
||||
opts.on("-s", "--spinner=path", "default: #{OPTIONS[:spinner]}", String) { |OPTIONS[:spinner]| }
|
||||
opts.on("-t", "--toggle-spin", "Whether to send a USR1 to the spinner before and after the reaping (default: true)") { |OPTIONS[:toggle_spin]| }
|
||||
opts.on("-n", "--nudge=url", "Should point to URL that's handled by the FCGI process", String) { |OPTIONS[:nudge]| }
|
||||
opts.on("-i", "--iterations=number", "One nudge per FCGI process running (default: #{OPTIONS[:iterations]})", Integer) { |OPTIONS[:iterations]| }
|
||||
|
||||
|
@ -119,5 +125,7 @@ ARGV.options do |opts|
|
|||
opts.parse!
|
||||
end
|
||||
|
||||
ProgramProcess.process_keywords("usr1", OPTIONS[:spinner]) if OPTIONS[:toggle_spin]
|
||||
ProgramProcess.process_keywords(OPTIONS[:action], OPTIONS[:dispatcher])
|
||||
nudge(OPTIONS[:nudge], OPTIONS[:iterations]) if OPTIONS[:nudge]
|
||||
nudge(OPTIONS[:nudge], OPTIONS[:iterations]) if OPTIONS[:nudge]
|
||||
ProgramProcess.process_keywords("usr1", OPTIONS[:spinner]) if OPTIONS[:toggle_spin]
|
|
@ -14,9 +14,10 @@ def daemonize
|
|||
end
|
||||
|
||||
OPTIONS = {
|
||||
:interval => 1.0,
|
||||
:command => File.expand_path(File.dirname(__FILE__) + '/spawner'),
|
||||
:daemon => false
|
||||
:high_interval => 5.0,
|
||||
:low_interval => 0.5,
|
||||
:command => File.expand_path(File.dirname(__FILE__) + '/spawner'),
|
||||
:daemon => false
|
||||
}
|
||||
|
||||
ARGV.options do |opts|
|
||||
|
@ -28,8 +29,7 @@ ARGV.options do |opts|
|
|||
Description:
|
||||
The spinner is a protection loop for the spawner, which will attempt to restart any FCGI processes
|
||||
that might have been restarted or outright crashed. It's a brute-force attempt that'll just try
|
||||
to run the spawner every X number of seconds, so it does pose a load on the server (~1% on our test
|
||||
server).
|
||||
to run the spawner every X number of seconds, so it does pose a light load on the server.
|
||||
|
||||
Examples:
|
||||
spinner # attempts to run the spawner with default settings every second with output on the terminal
|
||||
|
@ -39,9 +39,10 @@ ARGV.options do |opts|
|
|||
|
||||
opts.on(" Options:")
|
||||
|
||||
opts.on("-c", "--command=path", String) { |OPTIONS[:command]| }
|
||||
opts.on("-i", "--interval=seconds", Float) { |OPTIONS[:interval]| }
|
||||
opts.on("-d", "--daemon") { |OPTIONS[:daemon]| }
|
||||
opts.on("-c", "--command=path", String) { |OPTIONS[:command]| }
|
||||
opts.on("-h", "--high-interval=seconds", Float) { |OPTIONS[:high_interval]| }
|
||||
opts.on("-l", "--low-interval=seconds", Float) { |OPTIONS[:low_interval]| }
|
||||
opts.on("-d", "--daemon") { |OPTIONS[:daemon]| }
|
||||
|
||||
opts.separator ""
|
||||
|
||||
|
@ -52,9 +53,15 @@ end
|
|||
|
||||
daemonize if OPTIONS[:daemon]
|
||||
|
||||
loop do
|
||||
system(OPTIONS[:command])
|
||||
sleep(OPTIONS[:interval])
|
||||
trap(OPTIONS[:daemon] ? "TERM" : "INT") { exit }
|
||||
trap("USR1") do
|
||||
$interval = ($interval == OPTIONS[:high_interval] ? OPTIONS[:low_interval] : OPTIONS[:high_interval])
|
||||
puts "New interval: #{$interval}"
|
||||
end
|
||||
|
||||
trap(OPTIONS[:daemon] ? "TERM" : "INT") { exit }
|
||||
$interval = OPTIONS[:high_interval]
|
||||
|
||||
loop do
|
||||
system(OPTIONS[:command])
|
||||
sleep($interval)
|
||||
end
|
Loading…
Reference in a new issue