diff options
Diffstat (limited to 'railties/bin/process/spinner')
-rwxr-xr-x | railties/bin/process/spinner | 31 |
1 files changed, 19 insertions, 12 deletions
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 |