Gurpartap/cognizant

View on GitHub
examples/apps/thin.cz

Summary

Maintainability
Test Coverage
app_root = "/apps/acmecorp.com"
servers = 5
port = 4000

Cognizant.application "acmecorp.com" do |app|
  servers.times do |n|
    app.monitor "thin-#{n}" do
      # autostart!
      group "thin"
      uid "www-data"
      gid "www-data"

      env RACK_ENV: "production"
      chdir "#{app_root}/current"

      daemonize false
      pidfile "#{app_root}/shared/tmp/pids/thin.400#{n}.pid"

      start_command   "bundle exec thin start   --only #{n} --servers #{servers} --port #{port}"
      stop_command    "bundle exec thin stop    --only #{n} --servers #{servers} --port #{port}"
      restart_command "bundle exec thin restart --only #{n} --servers #{servers} --port #{port}"

      check :flapping, times: 3, within: 1.minute, retry_after: 15.seconds, retries: 10
      check :transition, from: :running, to: :stopped do |process|
        `say a thin server has stopped` # send an email, etc.
      end

      check :cpu_usage,    above: 50.percent,    every: 5.seconds, times: 5,      do: :restart
      check :memory_usage, above: 300.megabytes, every: 5.seconds, times: [3, 5], do: :restart
    end
  end
end