aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/commands/process
diff options
context:
space:
mode:
authorJamis Buck <jamis@37signals.com>2005-10-16 03:00:44 +0000
committerJamis Buck <jamis@37signals.com>2005-10-16 03:00:44 +0000
commitae294afa8d0a68d39613382d84cfba8821e48e38 (patch)
tree74891cc3c6609f147cbc138a9340e8b8bc384cf4 /railties/lib/commands/process
parent1ea085ec7e77af32bf5234fb4642b012aec62779 (diff)
downloadrails-ae294afa8d0a68d39613382d84cfba8821e48e38.tar.gz
rails-ae294afa8d0a68d39613382d84cfba8821e48e38.tar.bz2
rails-ae294afa8d0a68d39613382d84cfba8821e48e38.zip
Documentation updates/fixes for railties
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2637 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/lib/commands/process')
-rw-r--r--railties/lib/commands/process/reaper.rb27
-rw-r--r--railties/lib/commands/process/spinner.rb2
2 files changed, 24 insertions, 5 deletions
diff --git a/railties/lib/commands/process/reaper.rb b/railties/lib/commands/process/reaper.rb
index 1a08cb1def..b99fd1efa2 100644
--- a/railties/lib/commands/process/reaper.rb
+++ b/railties/lib/commands/process/reaper.rb
@@ -4,8 +4,16 @@ require 'uri'
if RUBY_PLATFORM =~ /mswin32/ then abort("Reaper is only for Unix") end
+# Instances of this class represent a single running process. Processes may
+# be queried by "keyword" to find those that meet a specific set of criteria.
class ProgramProcess
class << self
+
+ # Searches for all processes matching the given keywords, and then invokes
+ # a specific action on each of them. This is useful for (e.g.) reloading a
+ # set of processes:
+ #
+ # ProgramProcess.process_keywords(:reload, "basecamp")
def process_keywords(action, *keywords)
processes = keywords.collect { |keyword| find_by_keyword(keyword) }.flatten
@@ -19,6 +27,9 @@ class ProgramProcess
end
end
+ # Searches for all processes matching the given keyword:
+ #
+ # ProgramProcess.find_by_keyword("basecamp")
def find_by_keyword(keyword)
process_lines_with_keyword(keyword).split("\n").collect { |line|
next if line.include?("inq") || line.include?("ps -ax") || line.include?("grep")
@@ -33,34 +44,42 @@ class ProgramProcess
end
end
+ # Create a new ProgramProcess instance that represents the process with the
+ # given pid, running the given command.
def initialize(pid, command)
@pid, @command = pid, command
end
- def find
- end
-
+ # Forces the (rails) application to reload by sending a +HUP+ signal to the
+ # process.
def reload
`kill -s HUP #{@pid}`
end
+ # Forces the (rails) application to gracefully terminate by sending a
+ # +TERM+ signal to the process.
def graceful
`kill -s TERM #{@pid}`
end
+ # Forces the (rails) application to terminate immediately by sending a -9
+ # signal to the process.
def kill
`kill -9 #{@pid}`
end
+ # Send a +USR1+ signal to the process.
def usr1
`kill -s USR1 #{@pid}`
end
+ # Force the (rails) application to restart by sending a +USR2+ signal to the
+ # process.
def restart
`kill -s USR2 #{@pid}`
end
- def to_s
+ def to_s #:nodoc:
"[#{@pid}] #{@command}"
end
end
diff --git a/railties/lib/commands/process/spinner.rb b/railties/lib/commands/process/spinner.rb
index 161623c622..af073c747f 100644
--- a/railties/lib/commands/process/spinner.rb
+++ b/railties/lib/commands/process/spinner.rb
@@ -1,6 +1,6 @@
require 'optparse'
-def daemonize
+def daemonize #:nodoc:
exit if fork # Parent exits, child continues.
Process.setsid # Become session leader.
exit if fork # Zap session leader. See [1].