Commit 146e66ca by ErgoLau

prefix method name to isolate

parent 8f269a97
module Capistrano
module Sneakers
module HelperMethods
def each_process_with_index(reverse = false, &block)
_pid_files = pid_files
def sneakers_each_process_with_index(reverse = false, &block)
_pid_files = sneakers_pid_files
_pid_files.reverse! if reverse
_pid_files.each_with_index do |pid_file, idx|
within release_path do
......@@ -11,7 +11,7 @@ module Capistrano
end
end
def pid_files
def sneakers_pid_files
sneakers_roles = Array(fetch(:sneakers_roles))
sneakers_roles.select! { |role| host.roles.include?(role) }
sneakers_roles.flat_map do |role|
......@@ -24,11 +24,11 @@ module Capistrano
end
end
def pid_file_exists?(pid_file)
def sneakers_pid_file_exists?(pid_file)
test(*("[ -f #{pid_file} ]").split(' '))
end
def process_exists?(pid_file)
def sneakers_process_exists?(pid_file)
test(*("kill -0 $( cat #{pid_file} )").split(' '))
end
......@@ -76,7 +76,7 @@ module Capistrano
end
end
def switch_user(role, &block)
def sneakers_switch_user(role, &block)
user = sneakers_user(role)
if user == role.user
block.call
......
......@@ -42,10 +42,10 @@ namespace :sneakers do
desc 'Quiet sneakers (stop processing new tasks)'
task :quiet do
on roles fetch(:sneakers_roles) do |role|
switch_user(role) do
sneakers_switch_user(role) do
if test("[ -d #{current_path} ]")
each_process_with_index(true) do |pid_file, idx|
if pid_file_exists?(pid_file) && process_exists?(pid_file)
sneakers_each_process_with_index(true) do |pid_file, idx|
if pid_file_exists?(pid_file) && sneakers_process_exists?(pid_file)
quiet_sneakers(pid_file)
end
end
......@@ -57,10 +57,10 @@ namespace :sneakers do
desc 'Stop sneakers'
task :stop do
on roles fetch(:sneakers_roles) do |role|
switch_user(role) do
sneakers_switch_user(role) do
if test("[ -d #{current_path} ]")
each_process_with_index(true) do |pid_file, idx|
if pid_file_exists?(pid_file) && process_exists?(pid_file)
sneakers_each_process_with_index(true) do |pid_file, idx|
if sneakers_pid_file_exists?(pid_file) && sneakers_process_exists?(pid_file)
stop_sneakers(pid_file)
end
end
......@@ -72,9 +72,9 @@ namespace :sneakers do
desc 'Start sneakers'
task :start do
on roles fetch(:sneakers_roles) do |role|
switch_user(role) do
each_process_with_index do |pid_file, idx|
unless pid_file_exists?(pid_file) && process_exists?(pid_file)
sneakers_switch_user(role) do
sneakers_each_process_with_index do |pid_file, idx|
unless sneakers_pid_file_exists?(pid_file) && sneakers_process_exists?(pid_file)
start_sneakers(pid_file, idx)
end
end
......@@ -94,9 +94,9 @@ namespace :sneakers do
desc 'Rolling-restart sneakers'
task :rolling_restart do
on roles fetch(:sneakers_roles) do |role|
switch_user(role) do
each_process_with_index(true) do |pid_file, idx|
if pid_file_exists?(pid_file) && process_exists?(pid_file)
sneakers_switch_user(role) do
sneakers_each_process_with_index(true) do |pid_file, idx|
if sneakers_pid_file_exists?(pid_file) && sneakers_process_exists?(pid_file)
stop_sneakers(pid_file)
end
start_sneakers(pid_file, idx)
......@@ -108,10 +108,10 @@ namespace :sneakers do
# Delete any pid file not in use
task :cleanup do
on roles fetch(:sneakers_roles) do |role|
switch_user(role) do
each_process_with_index do |pid_file, idx|
unless process_exists?(pid_file)
if pid_file_exists?(pid_file)
sneakers_switch_user(role) do
sneakers_each_process_with_index do |pid_file, idx|
unless sneakers_process_exists?(pid_file)
if sneakers_pid_file_exists?(pid_file)
execute "rm #{pid_file}"
end
end
......@@ -125,9 +125,9 @@ namespace :sneakers do
task :respawn do
invoke 'sneakers:cleanup'
on roles fetch(:sneakers_roles) do |role|
switch_user(role) do
each_process_with_index do |pid_file, idx|
unless pid_file_exists?(pid_file)
sneakers_switch_user(role) do
sneakers_each_process_with_index do |pid_file, idx|
unless sneakers_pid_file_exists?(pid_file)
start_sneakers(pid_file, idx)
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