aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-07-16 20:05:27 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-07-16 20:05:27 +0000
commit1ce158ac8c58b2b815b6094087275c2162df94d4 (patch)
tree0fbd4622137cc653128312c5411828218ffc81ad /railties
parent45804e2c86228efcfb7d635525f0d1635a1b25c1 (diff)
downloadrails-1ce158ac8c58b2b815b6094087275c2162df94d4.tar.gz
rails-1ce158ac8c58b2b815b6094087275c2162df94d4.tar.bz2
rails-1ce158ac8c58b2b815b6094087275c2162df94d4.zip
Support for upcoming script/spawner
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1840 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/program_process.rb62
1 files changed, 62 insertions, 0 deletions
diff --git a/railties/lib/program_process.rb b/railties/lib/program_process.rb
new file mode 100644
index 0000000000..80aa95c41c
--- /dev/null
+++ b/railties/lib/program_process.rb
@@ -0,0 +1,62 @@
+class ProgramProcess
+ class << self
+ def process_keywords(action, *keywords)
+ processes = keywords.collect { |keyword| find_by_keyword(keyword) }.flatten
+
+ if processes.empty?
+ puts "Couldn't find any process matching: #{keywords.join(" or ")}"
+ else
+ processes.each do |process|
+ puts "#{action.humanize}ing #{process}"
+ process.send(action)
+ end
+ end
+ end
+
+ 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")
+ pid, *command = line.split
+ new(pid, command.join(" "))
+ }.compact
+ end
+
+ private
+ def process_lines_with_keyword(keyword)
+ `ps -ax -o 'pid command' | grep #{keyword}`
+ end
+ end
+
+ def initialize(pid, command)
+ @pid, @command = pid, command
+ end
+
+ def find
+ end
+
+ def reload
+ `kill -s HUP #{@pid}`
+ end
+
+ def restart
+ kill
+ `#{@command}`
+ end
+
+ def graceful_restart
+ graceful_kill
+ `#{@command}`
+ end
+
+ def graceful_kill
+ `kill -s TERM #{@pid}`
+ end
+
+ def kill
+ `kill -9 #{@pid}`
+ end
+
+ def to_s
+ "[#{@pid}] #{@command}"
+ end
+end \ No newline at end of file