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
4ae4fbdd
Commit
4ae4fbdd
authored
Nov 16, 2015
by
Jordan Hollinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support for running as a different user
parent
3a5b47e9
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
10 deletions
+38
-10
lib/capistrano/tasks/sneakers.rb
+38
-10
No files found.
lib/capistrano/tasks/sneakers.rb
View file @
4ae4fbdd
...
...
@@ -55,7 +55,7 @@ namespace :sneakers do
end
def
sneakers_pid_process_exists?
(
pid_file
)
sneakers_pid_file_exists?
(
pid_file
)
and
test
(
*
(
"kill -0 $( cat
#{
pid_file
}
)"
).
split
(
' '
)
)
sneakers_pid_file_exists?
(
pid_file
)
and
test
(
:kill
,
"-0 $( cat
#{
pid_file
}
)"
)
end
def
sneakers_pid_file_exists?
(
pid_file
)
...
...
@@ -64,11 +64,11 @@ namespace :sneakers do
def
stop_sneakers
(
pid_file
)
if
fetch
(
:sneakers_run_config
)
==
true
execute
"kill
-SIGTERM `cat
#{
pid_file
}
`"
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
}
`"
background
:kill
,
"
-TERM `cat
#{
pid_file
}
`"
else
background
:bundle
,
:exec
,
:sneakersctl
,
'stop'
,
"
#{
pid_file
}
"
,
fetch
(
:sneakers_timeout
)
end
...
...
@@ -80,7 +80,7 @@ namespace :sneakers do
def
quiet_sneakers
(
pid_file
)
if
fetch
(
:sneakers_use_signals
)
||
fetch
(
:sneakers_run_config
)
background
"kill
-USR1 `cat
#{
pid_file
}
`"
background
:kill
,
"
-USR1 `cat
#{
pid_file
}
`"
else
begin
execute
:bundle
,
:exec
,
:sneakersctl
,
'quiet'
,
"
#{
pid_file
}
"
...
...
@@ -137,6 +137,22 @@ namespace :sneakers do
end
end
def
as_sneakers_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
task
:add_default_hooks
do
after
'deploy:starting'
,
'sneakers:quiet'
after
'deploy:updated'
,
'sneakers:stop'
...
...
@@ -146,7 +162,8 @@ namespace :sneakers do
desc
'Quiet sneakers (stop processing new tasks)'
task
:quiet
do
on
roles
fetch
(
:sneakers_role
)
do
on
roles
fetch
(
:sneakers_role
)
do
|
role
|
as_sneakers_user
(
role
)
do
if
test
(
"[ -d
#{
current_path
}
]"
)
# fixes #11
for_each_sneakers_process
(
true
)
do
|
pid_file
,
idx
|
if
sneakers_pid_process_exists?
(
pid_file
)
...
...
@@ -156,10 +173,12 @@ namespace :sneakers do
end
end
end
end
desc
'Stop sneakers'
task
:stop
do
on
roles
fetch
(
:sneakers_role
)
do
on
roles
fetch
(
:sneakers_role
)
do
|
role
|
as_sneakers_user
(
role
)
do
if
test
(
"[ -d
#{
current_path
}
]"
)
for_each_sneakers_process
(
true
)
do
|
pid_file
,
idx
|
if
sneakers_pid_process_exists?
(
pid_file
)
...
...
@@ -169,15 +188,18 @@ namespace :sneakers do
end
end
end
end
desc
'Start sneakers'
task
:start
do
on
roles
fetch
(
:sneakers_role
)
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
)
end
end
end
end
desc
'Restart sneakers'
task
:restart
do
...
...
@@ -187,7 +209,8 @@ namespace :sneakers do
desc
'Rolling-restart sneakers'
task
:rolling_restart
do
on
roles
fetch
(
:sneakers_role
)
do
on
roles
fetch
(
:sneakers_role
)
do
|
role
|
as_sneakers_user
(
role
)
do
for_each_sneakers_process
(
true
)
do
|
pid_file
,
idx
|
if
sneakers_pid_process_exists?
(
pid_file
)
stop_sneakers
(
pid_file
)
...
...
@@ -196,10 +219,12 @@ namespace :sneakers do
end
end
end
end
# Delete any pid file not in use
task
:cleanup
do
on
roles
fetch
(
:sneakers_role
)
do
on
roles
fetch
(
:sneakers_role
)
do
|
role
|
as_sneakers_user
(
role
)
do
for_each_sneakers_process
do
|
pid_file
,
idx
|
if
sneakers_pid_file_exists?
(
pid_file
)
execute
"rm
#{
pid_file
}
"
unless
sneakers_pid_process_exists?
(
pid_file
)
...
...
@@ -207,12 +232,14 @@ namespace :sneakers do
end
end
end
end
# TODO : Don't start if all proccess are off, raise warning.
desc
'Respawn missing sneakers proccesses'
task
:respawn
do
invoke
'sneakers:cleanup'
on
roles
fetch
(
:sneakers_role
)
do
on
roles
fetch
(
:sneakers_role
)
do
|
role
|
as_sneakers_user
(
role
)
do
for_each_sneakers_process
do
|
pid_file
,
idx
|
unless
sneakers_pid_file_exists?
(
pid_file
)
start_sneakers
(
pid_file
,
idx
)
...
...
@@ -220,6 +247,7 @@ namespace :sneakers do
end
end
end
end
def
template_sneakers
(
from
,
to
,
role
)
[
...
...
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