Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
capistrano-sneakers
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
capistrano-sneakers
Commits
8f269a97
Commit
8f269a97
authored
Aug 01, 2018
by
ErgoLau
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use require and include
parent
ce63d1f1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
124 additions
and
26 deletions
+124
-26
lib/capistrano/sneakers/helper_methods.rb
+97
-0
lib/capistrano/tasks/sneakers.rake
+27
-26
No files found.
lib/capistrano/sneakers/helper_methods.rb
0 → 100644
View file @
8f269a97
module
Capistrano
module
Sneakers
module
HelperMethods
def
each_process_with_index
(
reverse
=
false
,
&
block
)
_pid_files
=
pid_files
_pid_files
.
reverse!
if
reverse
_pid_files
.
each_with_index
do
|
pid_file
,
idx
|
within
release_path
do
yield
(
pid_file
,
idx
)
end
end
end
def
pid_files
sneakers_roles
=
Array
(
fetch
(
:sneakers_roles
))
sneakers_roles
.
select!
{
|
role
|
host
.
roles
.
include?
(
role
)
}
sneakers_roles
.
flat_map
do
|
role
|
processes
=
fetch
(
:sneakers_processes
)
if
processes
==
1
fetch
(
:sneakers_pid
)
else
Array
.
new
(
processes
)
{
|
idx
|
fetch
(
:sneakers_pid
).
gsub
(
/\.pid$/
,
"-
#{
idx
}
.pid"
)
}
end
end
end
def
pid_file_exists?
(
pid_file
)
test
(
*
(
"[ -f
#{
pid_file
}
]"
).
split
(
' '
))
end
def
process_exists?
(
pid_file
)
test
(
*
(
"kill -0 $( cat
#{
pid_file
}
)"
).
split
(
' '
))
end
def
quiet_sneakers
(
pid_file
)
if
fetch
(
:sneakers_use_signals
)
||
fetch
(
:sneakers_run_config
)
execute
:kill
,
"-USR1 `cat
#{
pid_file
}
`"
else
begin
execute
:bundle
,
:exec
,
:sneakersctl
,
'quiet'
,
"
#{
pid_file
}
"
rescue
SSHKit
::
Command
::
Failed
# If gems are not installed eq(first deploy) and sneakers_default_hooks as active
warn
'sneakersctl not found (ignore if this is the first deploy)'
end
end
end
def
stop_sneakers
(
pid_file
)
if
fetch
(
:sneakers_run_config
)
==
true
execute
:kill
,
"-SIGTERM `cat
#{
pid_file
}
`"
else
if
fetch
(
:stop_sneakers_in_background
,
fetch
(
:sneakers_run_in_background
))
if
fetch
(
:sneakers_use_signals
)
background
:kill
,
"-TERM `cat
#{
pid_file
}
`"
else
background
:bundle
,
:exec
,
:sneakersctl
,
'stop'
,
"
#{
pid_file
}
"
,
fetch
(
:sneakers_timeout
)
end
else
execute
:bundle
,
:exec
,
:sneakersctl
,
'stop'
,
"
#{
pid_file
}
"
,
fetch
(
:sneakers_timeout
)
end
end
end
def
start_sneakers
(
pid_file
,
idx
=
0
)
if
fetch
(
:sneakers_run_config
)
==
true
# Use sneakers configuration prebuilt in
raise
"[ set :workers, ['worker1', 'workerN'] ] not configured properly, please configure the workers you wish to use"
if
fetch
(
:sneakers_workers
).
nil?
or
fetch
(
:sneakers_workers
)
==
false
or
!
fetch
(
:sneakers_workers
).
kind_of?
Array
workers
=
fetch
(
:sneakers_workers
).
compact
.
join
(
','
)
info
"Starting the sneakers processes"
with
rails_env:
fetch
(
:sneakers_env
),
workers:
workers
do
rake
'sneakers:run'
end
end
end
def
switch_user
(
role
,
&
block
)
user
=
sneakers_user
(
role
)
if
user
==
role
.
user
block
.
call
else
as
user
do
block
.
call
end
end
end
def
sneakers_user
(
role
)
properties
=
role
.
properties
properties
.
fetch
(
:sneakers_user
)
||
fetch
(
:sneakers_user
)
||
properties
.
fetch
(
:run_as
)
||
role
.
user
end
end
end
end
lib/capistrano/tasks/sneakers.rake
View file @
8f269a97
require
'lib/sneakers_helper'
require
'capistrano/sneakers/helper_methods'
include
Capistrano
::
Sneakers
::
HelperMethods
namespace
:load
do
task
:defaults
do
...
...
@@ -41,11 +42,11 @@ namespace :sneakers do
desc
'Quiet sneakers (stop processing new tasks)'
task
:quiet
do
on
roles
fetch
(
:sneakers_roles
)
do
|
role
|
SneakersHelper
.
switch_user
(
role
)
do
switch_user
(
role
)
do
if
test
(
"[ -d
#{
current_path
}
]"
)
SneakersHelper
.
each_process_with_index
(
true
)
do
|
pid_file
,
idx
|
if
SneakersHelper
.
pid_file_exists?
(
pid_file
)
&&
SneakersHelper
.
process_exists?
(
pid_file
)
SneakersHelper
.
quiet_sneakers
(
pid_file
)
each_process_with_index
(
true
)
do
|
pid_file
,
idx
|
if
pid_file_exists?
(
pid_file
)
&&
process_exists?
(
pid_file
)
quiet_sneakers
(
pid_file
)
end
end
end
...
...
@@ -56,11 +57,11 @@ namespace :sneakers do
desc
'Stop sneakers'
task
:stop
do
on
roles
fetch
(
:sneakers_roles
)
do
|
role
|
SneakersHelper
.
switch_user
(
role
)
do
switch_user
(
role
)
do
if
test
(
"[ -d
#{
current_path
}
]"
)
SneakersHelper
.
each_process_with_index
(
true
)
do
|
pid_file
,
idx
|
if
SneakersHelper
.
pid_file_exists?
(
pid_file
)
&&
SneakersHelper
.
process_exists?
(
pid_file
)
SneakersHelper
.
stop_sneakers
(
pid_file
)
each_process_with_index
(
true
)
do
|
pid_file
,
idx
|
if
pid_file_exists?
(
pid_file
)
&&
process_exists?
(
pid_file
)
stop_sneakers
(
pid_file
)
end
end
end
...
...
@@ -71,10 +72,10 @@ namespace :sneakers do
desc
'Start sneakers'
task
:start
do
on
roles
fetch
(
:sneakers_roles
)
do
|
role
|
SneakersHelper
.
switch_user
(
role
)
do
SneakersHelper
.
each_process_with_index
do
|
pid_file
,
idx
|
unless
SneakersHelper
.
pid_file_exists?
(
pid_file
)
&&
SneakersHelper
.
process_exists?
(
pid_file
)
SneakersHelper
.
start_sneakers
(
pid_file
,
idx
)
switch_user
(
role
)
do
each_process_with_index
do
|
pid_file
,
idx
|
unless
pid_file_exists?
(
pid_file
)
&&
process_exists?
(
pid_file
)
start_sneakers
(
pid_file
,
idx
)
end
end
end
...
...
@@ -93,12 +94,12 @@ namespace :sneakers do
desc
'Rolling-restart sneakers'
task
:rolling_restart
do
on
roles
fetch
(
:sneakers_roles
)
do
|
role
|
SneakersHelper
.
switch_user
(
role
)
do
SneakersHelper
.
each_process_with_index
(
true
)
do
|
pid_file
,
idx
|
if
SneakersHelper
.
pid_file_exists?
(
pid_file
)
&&
SneakersHelper
.
process_exists?
(
pid_file
)
SneakersHelper
.
stop_sneakers
(
pid_file
)
switch_user
(
role
)
do
each_process_with_index
(
true
)
do
|
pid_file
,
idx
|
if
pid_file_exists?
(
pid_file
)
&&
process_exists?
(
pid_file
)
stop_sneakers
(
pid_file
)
end
SneakersHelper
.
start_sneakers
(
pid_file
,
idx
)
start_sneakers
(
pid_file
,
idx
)
end
end
end
...
...
@@ -107,10 +108,10 @@ namespace :sneakers do
# Delete any pid file not in use
task
:cleanup
do
on
roles
fetch
(
:sneakers_roles
)
do
|
role
|
SneakersHelper
.
switch_user
(
role
)
do
SneakersHelper
.
each_process_with_index
do
|
pid_file
,
idx
|
unless
SneakersHelper
.
process_exists?
(
pid_file
)
if
SneakersHelper
.
pid_file_exists?
(
pid_file
)
switch_user
(
role
)
do
each_process_with_index
do
|
pid_file
,
idx
|
unless
process_exists?
(
pid_file
)
if
pid_file_exists?
(
pid_file
)
execute
"rm
#{
pid_file
}
"
end
end
...
...
@@ -124,10 +125,10 @@ namespace :sneakers do
task
:respawn
do
invoke
'sneakers:cleanup'
on
roles
fetch
(
:sneakers_roles
)
do
|
role
|
SneakersHelper
.
switch_user
(
role
)
do
SneakersHelper
.
each_process_with_index
do
|
pid_file
,
idx
|
unless
SneakersHelper
.
pid_file_exists?
(
pid_file
)
SneakersHelper
.
start_sneakers
(
pid_file
,
idx
)
switch_user
(
role
)
do
each_process_with_index
do
|
pid_file
,
idx
|
unless
pid_file_exists?
(
pid_file
)
start_sneakers
(
pid_file
,
idx
)
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment