Commit 4dfff615 by Andrew Babichev

Replace sidekiq_service_name with sidekiq_monit_service_name

It's worth to emphasize service name is used exclusively in monit setup.
parent a2f96b46
...@@ -2,7 +2,7 @@ namespace :load do ...@@ -2,7 +2,7 @@ namespace :load do
task :defaults do task :defaults do
set :monit_bin, '/usr/bin/monit' set :monit_bin, '/usr/bin/monit'
set :sneakers_monit_default_hooks, true 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_use_sudo, true
set :sneakers_monit_templates_path, 'config/deploy/templates' set :sneakers_monit_templates_path, 'config/deploy/templates'
end end
...@@ -29,7 +29,7 @@ namespace :sneakers do ...@@ -29,7 +29,7 @@ namespace :sneakers do
@role = role @role = role
upload_sneakers_template 'sneakers_monit', "#{fetch(:tmp_dir)}/monit.conf", @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 mv_command
sudo_if_needed "#{fetch(:monit_bin)} reload" sudo_if_needed "#{fetch(:monit_bin)} reload"
...@@ -40,10 +40,10 @@ namespace :sneakers do ...@@ -40,10 +40,10 @@ namespace :sneakers do
task :monitor do task :monitor do
on roles(fetch(:sneakers_roles)) do on roles(fetch(:sneakers_roles)) do
begin begin
sudo_if_needed "#{fetch(:monit_bin)} monitor #{sneakers_service_name}" sudo_if_needed "#{fetch(:monit_bin)} monitor #{sneakers_monit_service_name}"
rescue rescue
invoke 'sneakers:monit:config' invoke 'sneakers:monit:config'
sudo_if_needed "#{fetch(:monit_bin)} monitor #{sneakers_service_name}" sudo_if_needed "#{fetch(:monit_bin)} monitor #{sneakers_monit_service_name}"
end end
end end
end end
...@@ -52,7 +52,7 @@ namespace :sneakers do ...@@ -52,7 +52,7 @@ namespace :sneakers do
task :unmonitor do task :unmonitor do
on roles(fetch(:sneakers_roles)) do on roles(fetch(:sneakers_roles)) do
begin begin
sudo_if_needed "#{fetch(:monit_bin)} unmonitor #{sneakers_service_name}" sudo_if_needed "#{fetch(:monit_bin)} unmonitor #{sneakers_monit_service_name}"
rescue rescue
# no worries here # no worries here
end end
...@@ -62,26 +62,26 @@ namespace :sneakers do ...@@ -62,26 +62,26 @@ namespace :sneakers do
desc 'Start Sneakers monit-service' desc 'Start Sneakers monit-service'
task :start do task :start do
on roles(fetch(:sneakers_roles)) 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
end end
desc 'Stop Sneakers monit-service' desc 'Stop Sneakers monit-service'
task :stop do task :stop do
on roles(fetch(:sneakers_roles)) 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
end end
desc 'Restart Sneakers monit-service' desc 'Restart Sneakers monit-service'
task :restart do task :restart do
on roles(fetch(:sneakers_roles)) 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
end end
def sneakers_service_name def sneakers_monit_service_name
fetch(:sneakers_service_name, "sneakers_#{fetch(:application)}_#{fetch(:sneakers_env)}") fetch(:sneakers_monit_service_name, "sneakers_#{fetch(:application)}_#{fetch(:sneakers_env)}")
end end
def sudo_if_needed(command) def sudo_if_needed(command)
......
# Monit configuration for Sneakers # Monit configuration for Sneakers : <%= fetch(:application) %>
# Service name: <%= sneakers_service_name %> check process <%= sneakers_monit_service_name %>
#
check process <%= sneakers_service_name %>
with pidfile "<%= fetch(:sneakers_pid) %>" 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'" 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) %>`'" 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