Last active
December 16, 2015 09:48
-
-
Save KazW/5415240 to your computer and use it in GitHub Desktop.
Discourse God file, needs work.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rails_env = 'production' | |
rails_root = File.dirname(File.dirname(__FILE__)) # Place this file in the config directory | |
secret_token = 'CHANGE_THIS' | |
user = 'deployer' | |
group = 'users' | |
num_webs = 4 | |
environment = {'RAILS_ENV' => rails_env, 'SECRET_TOKEN' => secret_token, 'RUBY_GC_MALLOC_LIMIT' => 90000000} | |
config_hash = {:rails_root => rails_root, :user => user, :group => group, :environment => environment} | |
def generic_monitoring(w, options = {}) | |
w.start_if do |start| | |
start.condition(:process_running) do |c| | |
c.interval = 30.seconds | |
c.running = false | |
end | |
end | |
w.restart_if do |restart| | |
restart.condition(:memory_usage) do |c| | |
c.above = options[:memory_limit] | |
c.times = [3, 5] # 3 out of 5 intervals | |
end | |
restart.condition(:cpu_usage) do |c| | |
c.above = options[:cpu_limit] | |
c.times = 5 | |
end | |
end | |
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 | |
def generic_settings(w, options = {}) | |
w.dir = options[:rails_root] | |
w.env = options[:environment] | |
w.uid = options[:user] | |
w.gid = options[:group] | |
w.behavior(:clean_pid_file) | |
w.interval = 20.seconds | |
w.start_grace = 30.seconds | |
w.stop_grace = 30.seconds | |
w.restart_grace = 30.seconds | |
end | |
# Thin servers | |
num_webs.times do |num| | |
God.watch do |w| | |
yaml_file = "#{rails_root}/config/thin.yml" | |
w.name = "thin-#{num}" | |
w.group = 'web' | |
w.start = "bundle exec thin start -C #{yaml_file} -o #{num}" | |
w.stop = "bundle exec thin stop -C #{yaml_file} -o #{num}" | |
w.restart = "bundle exec thin restart -C #{yaml_file} -o #{num}" | |
w.pid_file = "#{rails_root}/tmp/pids/thin.#{num}.pid" | |
w.log = "#{rails_root}/log/thin.#{num}.log" | |
generic_settings(w, config_hash) | |
generic_monitoring(w, :cpu_limit => 30.percent, :memory_limit => 275.megabytes) | |
end | |
end | |
# Sidekiq | |
God.watch do |w| | |
pid_file = "#{rails_root}/tmp/pids/sidekiq.pid" | |
w.name = 'sidekiq' | |
w.start = "bundle exec sidekiq -P #{rails_root}/tmp/pids/sidekiq.pid" | |
w.stop = "kill -QUIT `cat #{pid_file}`" | |
w.pid_file = "#{rails_root}/tmp/pids/sidekiq.pid" | |
w.log = "#{rails_root}/log/sidekiq.log" | |
generic_settings(w, config_hash) | |
generic_monitoring(w, :cpu_limit => 30.percent, :memory_limit => 250.megabytes) | |
end | |
# Clockwork | |
God.watch do |w| | |
pid_file = "#{rails_root}/tmp/pids/clockwork.pid" | |
w.name = 'clockwork' | |
w.start = "bundle exec clockwork #{rails_root}/config/clock.rb" | |
w.stop = "kill -QUIT `cat #{pid_file}`" | |
w.pid_file = "#{rails_root}/tmp/pids/clockwork.pid" | |
w.log = "#{rails_root}/log/clockwork.log" | |
generic_settings(w, config_hash) | |
generic_monitoring(w, :cpu_limit => 30.percent, :memory_limit => 200.megabytes) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment