Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- apps = {
- :rtrac => {
- :path => "/var/www/apps/rtrac/current/",
- :rackup => "--rackup /var/www/apps/rtrac/current/config/thin_proctitle.ru",
- :ports => %w{4001 4002 4003 4004 4005 4006 4007 4008},
- :uid => 'deployer',
- :gid => 'deployer',
- :server => 'thin',
- :env => 'production'
- #:env => 'development'
- },
- }
- apps.each do |name, app|
- app[:ports].each do |port|
- God.watch do |w|
- w.group = name.to_s
- w.uid = app[:uid]
- w.gid = app[:gid]
- w.name = "#{name}-#{app[:server]}-#{port}"
- w.interval = 30.seconds # default
- w.start = "#{app[:server]} start #{app[:rackup]} -e #{app[:env]} -c #{app[:path]} -p #{port} -P \
- #{app[:path]}/log/#{app[:server]}.#{port}.pid -d"
- w.stop = "#{app[:server]} stop -P #{app[:path]}/log/#{app[:server]}.#{port}.pid"
- w.restart = "#{app[:server]} restart -P #{app[:path]}/log/#{app[:server]}.#{port}.pid"
- w.start_grace = 10.seconds
- w.restart_grace = 10.seconds
- w.pid_file = File.join("#{app[:path]}", "log/#{app[:server]}.#{port}.pid")
- w.behavior(:clean_pid_file)
- w.start_if do |start|
- start.condition(:process_running) do |c|
- c.interval = 5.seconds
- c.running = false
- end
- end
- w.restart_if do |restart|
- restart.condition(:memory_usage) do |c|
- c.above = 800.megabytes
- c.times = [3, 5] # 3 out of 5 intervals
- end
- restart.condition(:cpu_usage) do |c|
- c.above = 50.percent
- c.times = 5
- end
- end
- # lifecycle
- w.lifecycle do |on|
- on.condition(:flapping) do |c|
- c.to_state = [:start, :restart]
- c.times = 5
- c.within = 5.minute
- c.transition = :unmonitored
- c.retry_in = 10.minutes
- c.retry_times = 5
- c.retry_within = 2.hours
- end
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment