Commit 146e66ca by ErgoLau

prefix method name to isolate

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