Commit 2a0b7e85 by Karl Kloppenborg Committed by GitHub

Merge pull request #13 from Tensho/sneakers-restart

Correct Timing in Sneakers Restart Task
parents 3a5ecde3 b298b43a
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'capistrano/sneakers/version'
......
require 'capistrano/sneakers/version'
cap_version = Gem::Specification.find_by_name('capistrano').version
if cap_version >= Gem::Version.new('3.0.0')
#
# Load Tasks from sneakers "cap" file
#
load File.expand_path('../tasks/sneakers.rake', __FILE__)
else
raise Gem::LoadError, "Capistrano-Sneakers requires capistrano version 3.0.0 or greater, version detected: #{cap_version}"
end
load File.expand_path('../tasks/sneakers.rake', __FILE__)
......@@ -63,5 +63,24 @@ namespace :sneakers do
def sudo_if_needed(command)
fetch(:sneakers_monit_use_sudo) ? sudo(command) : execute(command)
end
def template_sneakers(from, to, role)
[
File.join('lib', 'capistrano', 'templates', "#{from}-#{role.hostname}-#{fetch(:stage)}.rb"),
File.join('lib', 'capistrano', 'templates', "#{from}-#{role.hostname}.rb"),
File.join('lib', 'capistrano', 'templates', "#{from}-#{fetch(:stage)}.rb"),
File.join('lib', 'capistrano', 'templates', "#{from}.rb.erb"),
File.join('lib', 'capistrano', 'templates', "#{from}.rb"),
File.join('lib', 'capistrano', 'templates', "#{from}.erb"),
File.expand_path("../../templates/#{from}.rb.erb", __FILE__),
File.expand_path("../../templates/#{from}.erb", __FILE__)
].each do |path|
if File.file?(path)
erb = File.read(path)
upload! StringIO.new(ERB.new(erb).result(binding)), to
break
end
end
end
end
end
namespace :load do
task :defaults do
set :sneakers_default_hooks, -> { true }
......@@ -18,9 +17,7 @@ namespace :load do
end
end
namespace :deploy do
before :starting, :check_sneakers_hooks do
invoke 'sneakers:add_default_hooks' if fetch(:sneakers_default_hooks)
end
......@@ -31,7 +28,6 @@ namespace :deploy do
end
namespace :sneakers do
def for_each_sneakers_process(reverse = false, &block)
pids = processes_sneakers_pids
pids.reverse! if reverse
......@@ -196,7 +192,9 @@ namespace :sneakers do
on roles fetch(:sneakers_role) do |role|
as_sneakers_user(role) do
for_each_sneakers_process do |pid_file, idx|
start_sneakers(pid_file, idx) unless sneakers_pid_process_exists?(pid_file)
unless sneakers_pid_process_exists?(pid_file)
start_sneakers(pid_file, idx)
end
end
end
end
......@@ -205,6 +203,9 @@ namespace :sneakers do
desc 'Restart sneakers'
task :restart do
invoke! 'sneakers:stop'
# It takes some time to stop serverengine processes and cleanup pidfiles.
# We should wait until pidfiles will be removed.
sleep 5
invoke 'sneakers:start'
end
......@@ -249,23 +250,4 @@ namespace :sneakers do
end
end
end
def template_sneakers(from, to, role)
[
File.join('lib', 'capistrano', 'templates', "#{from}-#{role.hostname}-#{fetch(:stage)}.rb"),
File.join('lib', 'capistrano', 'templates', "#{from}-#{role.hostname}.rb"),
File.join('lib', 'capistrano', 'templates', "#{from}-#{fetch(:stage)}.rb"),
File.join('lib', 'capistrano', 'templates', "#{from}.rb.erb"),
File.join('lib', 'capistrano', 'templates', "#{from}.rb"),
File.join('lib', 'capistrano', 'templates', "#{from}.erb"),
File.expand_path("../../templates/#{from}.rb.erb", __FILE__),
File.expand_path("../../templates/#{from}.erb", __FILE__)
].each do |path|
if File.file?(path)
erb = File.read(path)
upload! StringIO.new(ERB.new(erb).result(binding)), to
break
end
end
end
end
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