def keepalive(options = {})
if God::EventHandler.loaded?
self.transition(:init, { true => :up, false => :start }) do |on|
on.condition(:process_running) do |c|
c.interval = options[:interval] || DEFAULT_KEEPALIVE_INTERVAL
c.running = true
end
end
self.transition([:start, :restart], :up) do |on|
on.condition(:process_running) do |c|
c.interval = options[:interval] || DEFAULT_KEEPALIVE_INTERVAL
c.running = true
end
end
self.transition(:up, :start) do |on|
on.condition(:process_exits)
end
else
self.start_if do |start|
start.condition(:process_running) do |c|
c.interval = options[:interval] || DEFAULT_KEEPALIVE_INTERVAL
c.running = false
end
end
end
self.restart_if do |restart|
if options[:memory_max]
restart.condition(:memory_usage) do |c|
c.interval = options[:interval] || DEFAULT_KEEPALIVE_INTERVAL
c.above = options[:memory_max]
c.times = options[:memory_times] || DEFAULT_KEEPALIVE_MEMORY_TIMES
end
end
if options[:cpu_max]
restart.condition(:cpu_usage) do |c|
c.interval = options[:interval] || DEFAULT_KEEPALIVE_INTERVAL
c.above = options[:cpu_max]
c.times = options[:cpu_times] || DEFAULT_KEEPALIVE_CPU_TIMES
end
end
end
end