diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-07-24 07:57:10 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-07-24 07:57:10 +0000 |
commit | d75481c5808085935e94fcbf6460c7685ef26396 (patch) | |
tree | 4e80c3fc2dba459fb1aaab79836caaf2641f7b05 /railties/bin/process/spinner | |
parent | eddd7c453b9f34ec95b64d1dee9b8fcf560a4b29 (diff) | |
download | rails-d75481c5808085935e94fcbf6460c7685ef26396.tar.gz rails-d75481c5808085935e94fcbf6460c7685ef26396.tar.bz2 rails-d75481c5808085935e94fcbf6460c7685ef26396.zip |
Added convenience controls for FCGI processes (especially when managed remotely): spinner, spawner, and reaper. They reside in script/process. More details can be had by calling them with -h/--help
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1909 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/bin/process/spinner')
-rwxr-xr-x | railties/bin/process/spinner | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/railties/bin/process/spinner b/railties/bin/process/spinner new file mode 100755 index 0000000000..ff7a576163 --- /dev/null +++ b/railties/bin/process/spinner @@ -0,0 +1,60 @@ +#!/usr/local/bin/ruby + +require 'optparse' + +def daemonize + exit if fork # Parent exits, child continues. + Process.setsid # Become session leader. + exit if fork # Zap session leader. See [1]. + Dir.chdir "/" # Release old working directory. + File.umask 0000 # Ensure sensible umask. Adjust as needed. + STDIN.reopen "/dev/null" # Free file descriptors and + STDOUT.reopen "/dev/null", "a" # point them somewhere sensible. + STDERR.reopen STDOUT # STDOUT/ERR should better go to a logfile. +end + +OPTIONS = { + :interval => 1.0, + :command => File.expand_path(File.dirname(__FILE__) + '/spawner'), + :daemon => false +} + +ARGV.options do |opts| + opts.banner = "Usage: spinner [options]" + + opts.separator "" + + opts.on <<-EOF + 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). + + Examples: + spinner # attempts to run the spawner with default settings every second with output on the terminal + spinner -i 3 -d # only run the spawner every 3 seconds and detach from the terminal to become a daemon + spinner -c '/path/to/app/script/process/spawner -p 9000 -i 10' -d # using custom spawner + EOF + + 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.separator "" + + opts.on("-h", "--help", "Show this help message.") { puts opts; exit } + + opts.parse! +end + +daemonize if OPTIONS[:daemon] + +loop do + system(OPTIONS[:command]) + sleep(OPTIONS[:interval]) +end + +trap(OPTIONS[:daemon] ? "TERM" : "INT") { exit }
\ No newline at end of file |