Commit 05b83e7e by Karl Kloppenborg Committed by GitHub

Merge pull request #18 from Tensho/re-config-monit-service-on-fail

[WIP] Re-Config Monit Service Definition on Monitor Fail
parents d852a9a1 4dfff615
......@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = '>= 2.0.0'
spec.add_dependency 'capistrano', '>= 3.9.0'
spec.add_dependency 'sneakers'
spec.add_dependency 'sneakers', '>= 2.6'
spec.add_development_dependency "bundler", "~> 1.7"
spec.add_development_dependency "rake", "~> 10.0"
......
......@@ -2,7 +2,7 @@ namespace :load do
task :defaults do
set :monit_bin, '/usr/bin/monit'
set :sneakers_monit_default_hooks, true
set :sneakers_monit_conf_dir, -> { '/etc/monit/conf.d' }
set :sneakers_monit_conf_dir, '/etc/monit/conf.d'
set :sneakers_monit_use_sudo, true
set :sneakers_monit_templates_path, 'config/deploy/templates'
end
......@@ -29,7 +29,7 @@ namespace :sneakers do
@role = role
upload_sneakers_template 'sneakers_monit', "#{fetch(:tmp_dir)}/monit.conf", @role
mv_command = "mv #{fetch(:tmp_dir)}/monit.conf #{fetch(:sneakers_monit_conf_dir)}/#{sneakers_service_name}.conf"
mv_command = "mv #{fetch(:tmp_dir)}/monit.conf #{fetch(:sneakers_monit_conf_dir)}/#{sneakers_monit_service_name}.conf"
sudo_if_needed mv_command
sudo_if_needed "#{fetch(:monit_bin)} reload"
......@@ -39,40 +39,49 @@ namespace :sneakers do
desc 'Monitor Sneakers monit-service'
task :monitor do
on roles(fetch(:sneakers_roles)) do
sudo_if_needed "#{fetch(:monit_bin)} monitor #{sneakers_service_name}"
begin
sudo_if_needed "#{fetch(:monit_bin)} monitor #{sneakers_monit_service_name}"
rescue
invoke 'sneakers:monit:config'
sudo_if_needed "#{fetch(:monit_bin)} monitor #{sneakers_monit_service_name}"
end
end
end
desc 'Unmonitor Sneakers monit-service'
task :unmonitor do
on roles(fetch(:sneakers_roles)) do
sudo_if_needed "#{fetch(:monit_bin)} unmonitor #{sneakers_service_name}"
begin
sudo_if_needed "#{fetch(:monit_bin)} unmonitor #{sneakers_monit_service_name}"
rescue
# no worries here
end
end
end
desc 'Start Sneakers monit-service'
task :start do
on roles(fetch(:sneakers_roles)) do
sudo_if_needed "#{fetch(:monit_bin)} start #{sneakers_service_name}"
sudo_if_needed "#{fetch(:monit_bin)} start #{sneakers_monit_service_name}"
end
end
desc 'Stop Sneakers monit-service'
task :stop do
on roles(fetch(:sneakers_roles)) do
sudo_if_needed "#{fetch(:monit_bin)} stop #{sneakers_service_name}"
sudo_if_needed "#{fetch(:monit_bin)} stop #{sneakers_monit_service_name}"
end
end
desc 'Restart Sneakers monit-service'
task :restart do
on roles(fetch(:sneakers_roles)) do
sudo_if_needed "#{fetch(:monit_bin)} restart #{sneakers_service_name}"
sudo_if_needed "#{fetch(:monit_bin)} restart #{sneakers_monit_service_name}"
end
end
def sneakers_service_name
fetch(:sneakers_service_name, "sneakers_#{fetch(:application)}_#{fetch(:sneakers_env)}")
def sneakers_monit_service_name
fetch(:sneakers_monit_service_name, "sneakers_#{fetch(:application)}_#{fetch(:sneakers_env)}")
end
def sudo_if_needed(command)
......
# Monit configuration for Sneakers
# Service name: <%= sneakers_service_name %>
#
check process <%= sneakers_service_name %>
# Monit configuration for Sneakers : <%= fetch(:application) %>
check process <%= sneakers_monit_service_name %>
with pidfile "<%= fetch(:sneakers_pid) %>"
start program = "/usr/bin/sudo -iu <%= sneakers_user(@role) %> /bin/bash -c 'cd <%= current_path %> && RAILS_ENV=<%= fetch(:sneakers_env) %> WORKERS=<%= fetch(:sneakers_workers).join(',') %> <%= SSHKit.config.command_map[:rake] %> sneakers:run'"
stop program = "/usr/bin/sudo -iu <%= sneakers_user(@role) %> /bin/bash -c 'kill -SIGTERM `cat <%= fetch(:sneakers_pid) %>`'"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment