Commit 66980aee by Karl Kloppenborg

Merge pull request #3 from consolo/monit

Add support for monit
parents 68d192b1 d9832656
......@@ -25,6 +25,8 @@ Or install it yourself as:
# Capfile
require 'capistrano/sneakers'
# Include monit tasks
# require 'capistrano/sneakers/monit'
```
## Contributors
......
# Load monit tasks
load File.expand_path('../../tasks/monit.rake', __FILE__)
namespace :load do
task :defaults do
set :sneakers_monit_conf_dir, -> { "/etc/monit/conf.d/#{sneakers_monit_service_name}.conf" }
set :sneakers_monit_use_sudo, true
set :sneakers_monit_bin, '/usr/bin/monit'
end
end
namespace :sneakers do
namespace :monit do
desc 'Add Sneakers to monit'
task :config do
on roles(fetch(:sneakers_role)) do |role|
@role = role
template_sneakers 'sneakers_monit.conf', "#{fetch(:tmp_dir)}/monit.conf", @role
sudo_if_needed "mv #{fetch(:tmp_dir)}/monit.conf #{fetch(:sneakers_monit_conf_dir)}"
sudo_if_needed "#{fetch(:sneakers_monit_bin)} reload"
end
end
desc 'Enable Sneakers monit'
task :monitor do
on roles(fetch(:sneakers_role)) do
sudo_if_needed "#{fetch(:sneakers_monit_bin)} monitor #{sneakers_monit_service_name}"
end
end
desc 'Disable Sneakers monit'
task :unmonitor do
on roles(fetch(:sneakers_role)) do
sudo_if_needed "#{fetch(:sneakers_monit_bin)} unmonitor #{sneakers_monit_service_name}"
end
end
desc 'Start Sneakers through monit'
task :start do
on roles(fetch(:sneakers_role)) do
sudo_if_needed "#{fetch(:sneakers_monit_bin)} start #{sneakers_monit_service_name}"
end
end
desc 'Stop Sneakers through monit'
task :stop do
on roles(fetch(:sneakers_role)) do
sudo_if_needed "#{fetch(:sneakers_monit_bin)} stop #{sneakers_monit_service_name}"
end
end
desc 'Restart Sneakers through monit'
task :restart do
on roles(fetch(:sneakers_role)) do
sudo_if_needed "#{fetch(:sneakers_monit_bin)} restart #{sneakers_monit_service_name}"
end
end
before 'deploy:updating', 'sneakers:monit:unmonitor'
after 'deploy:published', 'sneakers:monit:monitor'
def sneakers_monit_service_name
fetch(:sneakers_monit_service_name, "sneakers_#{fetch(:application)}_#{fetch(:stage)}")
end
def sudo_if_needed(command)
fetch(:sneakers_monit_use_sudo) ? sudo(command) : execute(command)
end
end
end
# Monit configuration for Sneakers
# Service name: <%= sneakers_monit_service_name %>
#
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