1
我有一堂課,我正在用神監督。這是它的結構:什麼是正確的方法來終止與神的非守護進程?
的lib/my_class.rb
#!/usr/bin/env ruby
class MyClass
def start(config)
loop do
EventMachine::run do
end
end
end
begin
config = {"foo" => "bar"}
my_class = MyClass.new
my_class.start(config)
rescue Exception => ex
puts "Exception in MyClass: #{ex.message} at #{ex.backtrace.join("\n")}"
end
這是我在神面前怎樣運行它:
配置/ my_config.god
rails_root = File.dirname(File.dirname(__FILE__))
God.pid_file_directory = File.join(rails_root, 'tmp/pids/')
# myclass
God.watch do |w|
w.name = "myclass"
w.interval = 30.seconds
w.start = "#{rails_root}/script/rails runner #{rails_root}/lib/my_class.rb"
# w.stop = "do nothing?"
# w.restart = "#{w.stop} && #{w.start}"
w.start_grace = 10.seconds
w.restart_grace = 10.seconds
w.log = "#{rails_root}/log/my_class.log"
w.start_if do |start|
start.condition(:process_running) do |c|
c.interval = 5.seconds
c.running = false
end
end
end
因爲我沒有指定止損(我不知道如何),所以上帝會發送一個SIGTERM
,然後一個SIGKILL
來停止這個過程。這是我應該如何處理非守護進程?
*「...終止與神的非守護進程?」* - 這是一個編程論壇,我們傾向於避免這裏的宗教討論=) –
哈哈,我想知道標題:「什麼是正確的方式神是否在守護和殺死進程?「^_ ^ – David