aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-09-29 11:49:56 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-09-29 11:49:56 +0000
commit070d218c479c8cbb41e78f599110f0ea1cf0343a (patch)
treeb4a16db61cdd45ca285f26ec29097d08cbc114fd
parent6f3804113329d407d134c235120ab2e1e8da5244 (diff)
downloadrails-070d218c479c8cbb41e78f599110f0ea1cf0343a.tar.gz
rails-070d218c479c8cbb41e78f599110f0ea1cf0343a.tar.bz2
rails-070d218c479c8cbb41e78f599110f0ea1cf0343a.zip
Going to pull all commands into Rails
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2410 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--[-rwxr-xr-x]railties/lib/commands/process/reaper.rb (renamed from railties/bin/process/reaper)40
-rw-r--r--[-rwxr-xr-x]railties/lib/commands/process/spawner.rb (renamed from railties/bin/process/spawner)4
-rw-r--r--[-rwxr-xr-x]railties/lib/commands/process/spinner.rb (renamed from railties/bin/process/spinner)2
3 files changed, 10 insertions, 36 deletions
diff --git a/railties/bin/process/reaper b/railties/lib/commands/process/reaper.rb
index 0ab5bbbb8a..27c05ed5ce 100755..100644
--- a/railties/bin/process/reaper
+++ b/railties/lib/commands/process/reaper.rb
@@ -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,7 +21,7 @@ class ProgramProcess
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
@@ -43,7 +29,7 @@ class ProgramProcess
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 @@ class ProgramProcess
`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 @@ ARGV.options do |opts|
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 @@ 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]
-ProgramProcess.process_keywords("usr1", OPTIONS[:spinner]) if OPTIONS[:toggle_spin]
+ProgramProcess.process_keywords(OPTIONS[:action], OPTIONS[:dispatcher]) \ No newline at end of file
diff --git a/railties/bin/process/spawner b/railties/lib/commands/process/spawner.rb
index 2ac0df04f8..465017d8a4 100755..100644
--- a/railties/bin/process/spawner
+++ b/railties/lib/commands/process/spawner.rb
@@ -1,5 +1,3 @@
-#!/usr/local/bin/ruby
-
require 'optparse'
def spawn(port)
@@ -10,7 +8,7 @@ end
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
}
diff --git a/railties/bin/process/spinner b/railties/lib/commands/process/spinner.rb
index f4cd33cac1..88c8e7cbd0 100755..100644
--- a/railties/bin/process/spinner
+++ b/railties/lib/commands/process/spinner.rb
@@ -1,5 +1,3 @@
-#!/usr/local/bin/ruby
-
require 'optparse'
def daemonize