Guest User

Untitled

a guest
Jun 19th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. apps = {
  2. :rtrac => {
  3. :path => "/var/www/apps/rtrac/current/",
  4. :rackup => "--rackup /var/www/apps/rtrac/current/config/thin_proctitle.ru",
  5. :ports => %w{4001 4002 4003 4004 4005 4006 4007 4008},
  6. :uid => 'deployer',
  7. :gid => 'deployer',
  8. :server => 'thin',
  9. :env => 'production'
  10. #:env => 'development'
  11. },
  12. }
  13.  
  14. apps.each do |name, app|
  15. app[:ports].each do |port|
  16. God.watch do |w|
  17. w.group = name.to_s
  18. w.uid = app[:uid]
  19. w.gid = app[:gid]
  20. w.name = "#{name}-#{app[:server]}-#{port}"
  21. w.interval = 30.seconds # default
  22. w.start = "#{app[:server]} start #{app[:rackup]} -e #{app[:env]} -c #{app[:path]} -p #{port} -P \
  23. #{app[:path]}/log/#{app[:server]}.#{port}.pid -d"
  24. w.stop = "#{app[:server]} stop -P #{app[:path]}/log/#{app[:server]}.#{port}.pid"
  25. w.restart = "#{app[:server]} restart -P #{app[:path]}/log/#{app[:server]}.#{port}.pid"
  26. w.start_grace = 10.seconds
  27. w.restart_grace = 10.seconds
  28. w.pid_file = File.join("#{app[:path]}", "log/#{app[:server]}.#{port}.pid")
  29.  
  30. w.behavior(:clean_pid_file)
  31.  
  32. w.start_if do |start|
  33. start.condition(:process_running) do |c|
  34. c.interval = 5.seconds
  35. c.running = false
  36. end
  37. end
  38.  
  39. w.restart_if do |restart|
  40. restart.condition(:memory_usage) do |c|
  41. c.above = 800.megabytes
  42. c.times = [3, 5] # 3 out of 5 intervals
  43. end
  44.  
  45. restart.condition(:cpu_usage) do |c|
  46. c.above = 50.percent
  47. c.times = 5
  48. end
  49. end
  50.  
  51. # lifecycle
  52. w.lifecycle do |on|
  53. on.condition(:flapping) do |c|
  54. c.to_state = [:start, :restart]
  55. c.times = 5
  56. c.within = 5.minute
  57. c.transition = :unmonitored
  58. c.retry_in = 10.minutes
  59. c.retry_times = 5
  60. c.retry_within = 2.hours
  61. end
  62. end
  63. end
  64. end
  65. end
Add Comment
Please, Sign In to add comment