Permalink
Browse files

Going to pull all commands into Rails

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2410 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 6f38041 commit 070d218c479c8cbb41e78f599110f0ea1cf0343a @dhh dhh committed Sep 29, 2005
@@ -1,21 +1,7 @@
-#!/usr/local/bin/ruby
-
require 'optparse'
require 'net/http'
require 'uri'
-def nudge(url, iterations)
- print "Nudging #{url}: "
-
- iterations.times do
- Net::HTTP.get_response(URI.parse(url)) rescue nil
- print "."
- STDOUT.flush
- end
-
- puts
-end
-
if RUBY_PLATFORM =~ /mswin32/ then abort("Reaper is only for Unix") end
class ProgramProcess
@@ -35,15 +21,15 @@ def process_keywords(action, *keywords)
def find_by_keyword(keyword)
process_lines_with_keyword(keyword).split("\n").collect { |line|
- next if line.include?("inq") || line.include?("ps -wwax") || line.include?("grep")
+ next if line.include?("inq") || line.include?("ps -ax") || line.include?("grep")
pid, *command = line.split
new(pid, command.join(" "))
}.compact
end
private
def process_lines_with_keyword(keyword)
- `ps -wwax -o 'pid command' | grep #{keyword}`
+ `ps -ax -o 'pid command' | grep #{keyword}`
end
end
@@ -70,18 +56,18 @@ def usr1
`kill -s USR1 #{@pid}`
end
+ def restart
+ `kill -s USR2 #{@pid}`
+ end
+
def to_s
"[#{@pid}] #{@command}"
end
end
OPTIONS = {
- :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
+ :action => "restart",
+ :dispatcher => File.expand_path(RAILS_ROOT + '/public/dispatch.fcgi')
}
ARGV.options do |opts|
@@ -112,17 +98,12 @@ def to_s
Examples:
reaper -a reload
- reaper -n http://www.example.com -i 10 # gracefully exit, nudge 10 times
EOF
opts.on(" Options:")
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", "--[no-]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]| }
opts.separator ""
@@ -131,7 +112,4 @@ def to_s
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]
-ProgramProcess.process_keywords("usr1", OPTIONS[:spinner]) if OPTIONS[:toggle_spin]
+ProgramProcess.process_keywords(OPTIONS[:action], OPTIONS[:dispatcher])
@@ -1,5 +1,3 @@
-#!/usr/local/bin/ruby
-
require 'optparse'
def spawn(port)
@@ -10,7 +8,7 @@ def spawn(port)
OPTIONS = {
:environment => "production",
:spawner => '/usr/bin/env spawn-fcgi',
- :dispatcher => File.expand_path(File.dirname(__FILE__) + '/../../public/dispatch.fcgi'),
+ :dispatcher => File.expand_path(RAILS_ROOT + '/public/dispatch.fcgi'),
:port => 8000,
:instances => 3
}
@@ -1,5 +1,3 @@
-#!/usr/local/bin/ruby
-
require 'optparse'
def daemonize

0 comments on commit 070d218

Please sign in to comment.