Sha256: 120a2af9184edae1e0b196ebb5ac749d8550b0fe0e44d26edf4ac94c1fc19ecf

Contents?: true

Size: 1.61 KB

Versions: 13

Compression:

Stored size: 1.61 KB

Contents

# http://unicorn.bogomips.org/SIGNALS.html

rails_env = ENV['RAILS_ENV'] || 'production'
rails_root = ENV['RAILS_ROOT'] || File.dirname(File.dirname(__FILE__))

God.watch do |w|
  w.name = "unicorn_<%= app_name.downcase %>"
  w.interval = 30.seconds # default

  # unicorn needs to be run from the rails root
  w.start = "cd #{rails_root} && unicorn -c #{rails_root}/config/unicorn.rb -E #{rails_env} -D"

  # QUIT gracefully shuts down workers
  w.stop = "kill -KILL `cat #{rails_root}/tmp/pids/unicorn.pid`"

  # USR2 causes the master to re-create itself and spawn a new worker pool
  w.restart = "kill -USR2 `cat #{rails_root}/tmp/pids/unicorn.pid`"# && cd #{rails_root} && unicorn -c #{rails_root}/config/unicorn.rb -E #{rails_env} -D"

  w.start_grace = 10.seconds
  w.restart_grace = 10.seconds
  w.pid_file = "#{rails_root}/tmp/pids/unicorn.pid"

  w.uid = '<%= app_name.downcase %>'
  w.gid = '<%= app_name.downcase %>'

  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 = 150.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

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
hancock_cms-2.0.1.3 lib/generators/hancock/cms/templates/unicorn.god.erb
hancock_cms-1.0.2.3 lib/generators/hancock/cms/templates/unicorn.god.erb
hancock_cms-2.0.1.2 lib/generators/hancock/cms/templates/unicorn.god.erb
hancock_cms-2.0.1.1 lib/generators/hancock/cms/templates/unicorn.god.erb
hancock_cms-1.0.2.2 lib/generators/hancock/cms/templates/unicorn.god.erb
hancock_cms-1.0.1 lib/generators/hancock/cms/templates/unicorn.god.erb
hancock_cms-2.0.0.2 lib/generators/hancock/cms/templates/unicorn.god.erb
hancock_cms-1.0.0.4 lib/generators/hancock/cms/templates/unicorn.god.erb
hancock_cms-1.0.0.3 lib/generators/hancock/cms/templates/unicorn.god.erb
hancock_cms-2.0.0.1 lib/generators/hancock/cms/templates/unicorn.god.erb
hancock_cms-1.0.0.2 lib/generators/hancock/cms/templates/unicorn.god.erb
hancock_cms-2.0.0 lib/generators/hancock/cms/templates/unicorn.god.erb
hancock_cms-1.0.0 lib/generators/hancock/cms/templates/unicorn.god.erb