我有一门课,我正在使用上帝进行监控。这是它的结构:
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
结尾
由于我没有指定停止(我不知道如何),如果失败,上帝会发送 aSIGTERM
然后 a来停止该过程。SIGKILL
这是我应该如何处理非守护进程吗?