aboutsummaryrefslogtreecommitdiffstats
path: root/railties/bin
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-07-26 12:39:44 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-07-26 12:39:44 +0000
commit5b8b9178b357b46af2d8ff638b0ceac78e709a9e (patch)
tree0289e92fc7edf331ac37486221c90069bf285a57 /railties/bin
parent65e4e5e337a4ec043411879931081e310145e293 (diff)
downloadrails-5b8b9178b357b46af2d8ff638b0ceac78e709a9e.tar.gz
rails-5b8b9178b357b46af2d8ff638b0ceac78e709a9e.tar.bz2
rails-5b8b9178b357b46af2d8ff638b0ceac78e709a9e.zip
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
Diffstat (limited to 'railties/bin')
-rwxr-xr-xrailties/bin/process/reaper24
-rwxr-xr-xrailties/bin/process/spinner31
2 files changed, 35 insertions, 20 deletions
diff --git a/railties/bin/process/reaper b/railties/bin/process/reaper
index a636d329c8..3b58698653 100755
--- a/railties/bin/process/reaper
+++ b/railties/bin/process/reaper
@@ -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] \ No newline at end of file
+nudge(OPTIONS[:nudge], OPTIONS[:iterations]) if OPTIONS[:nudge]
+ProgramProcess.process_keywords("usr1", OPTIONS[:spinner]) if OPTIONS[:toggle_spin] \ No newline at end of file
diff --git a/railties/bin/process/spinner b/railties/bin/process/spinner
index ff7a576163..f4cd33cac1 100755
--- a/railties/bin/process/spinner
+++ b/railties/bin/process/spinner
@@ -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 } \ No newline at end of file
+$interval = OPTIONS[:high_interval]
+
+loop do
+ system(OPTIONS[:command])
+ sleep($interval)
+end \ No newline at end of file