Forked from rostamizadeh/Monit_Capistrano_Recipe.rb
Last active
August 29, 2015 14:08
-
-
Save suhovius/bad797d13c0691933f8c to your computer and use it in GitHub Desktop.
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
namespace :monit do | |
desc "Monit unicorn configuration" | |
task :unicorn_service_tests, roles: :web do | |
run "mkdir -p #{shared_path}/config" | |
template "monit_unicorn.rb.erb", "/tmp/monit_unicorn" | |
run "#{sudo} mv /tmp/monit_unicorn /etc/monit/conf.d/unicorn_#{application}_#{rails_env}.conf" | |
unicorn_worker_pids.each do |val| | |
worker_template "monit_unicorn_worker.rb.erb", "/tmp/monit_unicorn_#{application}_#{rails_env}_#{val}_worker", val | |
run "#{sudo} mv /tmp/monit_unicorn_#{application}_#{rails_env}_#{val}_worker /etc/monit/conf.d/unicorn_#{application}_#{rails_env}_#{val}_worker.conf" | |
end | |
run "#{sudo} monit -g unicorn_#{application}_#{rails_env} reload " | |
end | |
after "monit:unmonitor", "monit:unicorn_service_tests" | |
%w[monitor unmonitor].each do |command| | |
desc "monit #{command} unicorn_#{application}_#{rails_env}" | |
task command, roles: :web do | |
#run at group level | |
run "#{sudo} monit -g unicorn_#{application}_#{rails_env} #{command} " | |
end | |
end | |
after "deploy", "monit:monitor" | |
after "deploy:setup", "monit:monitor" | |
before "deploy", "monit:unmonitor" | |
before "deploy:setup", "monit:unmonitor" | |
end |
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
check process unicorn_<%= application %>_<%= rails_env %> | |
with pidfile "<%= shared_path %>/pids/unicorn.pid" | |
start program = "/etc/init.d/unicorn_<%= application %>_<%= rails_env %> start" | |
stop program = "/etc/init.d/unicorn_<%= application %>_<%= rails_env %> stop" | |
if mem is greater than 50.0 MB for 1 cycles then restart | |
if cpu is greater than 25% for 1 cycles then restart | |
group unicorn_<%= application %>_<%= rails_env %> |
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
check process unicorn_<%= application %>_<%= rails_env %>_<%= val %>_worker | |
with pidfile "<%= shared_path %>/pids/unicorn.worker.<%= val %>.pid" | |
start program = "/bin/true" | |
stop program = "/etc/init.d/unicorn_<%= application %>_<%= rails_env %> kill_worker <%= val %>" | |
if mem is greater than 90.0 MB for 1 cycles then restart | |
if cpu is greater than 40% for 3 cycles then restart | |
group unicorn_<%= application %>_<%= rails_env %> |
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
set :unicorn_workers, "1" | |
set :unicorn_worker_pids, (0...(unicorn_workers.to_i)).to_a |
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
def worker_template(from, to, val) | |
erb = File.read(File.expand_path("../templates/#{from}", __FILE__)) | |
put ERB.new(erb).result(binding), to | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment