I have a class that I am monitoring using god. This is it's structure:
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
And this is how I'm running it with god:
config/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
Since I didn't specify a stop (I don't know how), god will send a SIGTERM
and then a SIGKILL
to stop the process if that fails. Is this how I'm supposed to handle non-daemonized processes?