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
1afdcc0b
Unverified
Commit
1afdcc0b
authored
Jan 26, 2018
by
Andrew Babichev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add sneakers_monit_templates_path
parent
2a0b7e85
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
70 additions
and
66 deletions
+70
-66
lib/capistrano/tasks/monit.rake
+37
-26
lib/capistrano/tasks/sneakers.rake
+7
-38
lib/generators/capistrano/sneakers/monit/template_generator.rb
+24
-0
lib/generators/capistrano/sneakers/monit/templates/sneakers_monit.conf.erb
+2
-2
No files found.
lib/capistrano/tasks/monit.rake
View file @
1afdcc0b
namespace
:load
do
task
:defaults
do
set
:sneakers_monit_conf_dir
,
->
{
"/etc/monit/conf.d/
#{
sneakers_monit_service_name
}
.conf"
}
set
:sneakers_monit_conf_dir
,
->
{
'/etc/monit/conf.d'
}
set
:sneakers_monit_use_sudo
,
true
set
:sneakers_monit_bin
,
'/usr/bin/monit'
set
:sneakers_monit_templates_path
,
'config/deploy/templates'
end
end
...
...
@@ -12,8 +13,11 @@ namespace :sneakers do
task
:config
do
on
roles
(
fetch
(
:sneakers_role
))
do
|
role
|
@role
=
role
template_sneakers
'sneakers_monit.conf'
,
"
#{
fetch
(
:tmp_dir
)
}
/monit.conf"
,
@role
sudo_if_needed
"mv
#{
fetch
(
:tmp_dir
)
}
/monit.conf
#{
fetch
(
:sneakers_monit_conf_dir
)
}
"
upload_sneakers_template
'sneakers_monit'
,
"
#{
fetch
(
:tmp_dir
)
}
/monit.conf"
,
@role
mv_command
=
"mv
#{
fetch
(
:tmp_dir
)
}
/monit.conf
#{
fetch
(
:sneakers_monit_conf_dir
)
}
/
#{
sneakers_service_name
}
.conf"
sudo_if_needed
mv_command
sudo_if_needed
"
#{
fetch
(
:sneakers_monit_bin
)
}
reload"
end
end
...
...
@@ -21,66 +25,73 @@ namespace :sneakers do
desc
'Enable Sneakers monit'
task
:monitor
do
on
roles
(
fetch
(
:sneakers_role
))
do
sudo_if_needed
"
#{
fetch
(
:sneakers_monit_bin
)
}
monitor
#{
sneakers_
monit_
service_name
}
"
sudo_if_needed
"
#{
fetch
(
:sneakers_monit_bin
)
}
monitor
#{
sneakers_service_name
}
"
end
end
desc
'Disable Sneakers monit'
task
:unmonitor
do
on
roles
(
fetch
(
:sneakers_role
))
do
sudo_if_needed
"
#{
fetch
(
:sneakers_monit_bin
)
}
unmonitor
#{
sneakers_
monit_
service_name
}
"
sudo_if_needed
"
#{
fetch
(
:sneakers_monit_bin
)
}
unmonitor
#{
sneakers_service_name
}
"
end
end
desc
'Start Sneakers through monit'
task
:start
do
on
roles
(
fetch
(
:sneakers_role
))
do
sudo_if_needed
"
#{
fetch
(
:sneakers_monit_bin
)
}
start
#{
sneakers_
monit_
service_name
}
"
sudo_if_needed
"
#{
fetch
(
:sneakers_monit_bin
)
}
start
#{
sneakers_service_name
}
"
end
end
desc
'Stop Sneakers through monit'
task
:stop
do
on
roles
(
fetch
(
:sneakers_role
))
do
sudo_if_needed
"
#{
fetch
(
:sneakers_monit_bin
)
}
stop
#{
sneakers_
monit_
service_name
}
"
sudo_if_needed
"
#{
fetch
(
:sneakers_monit_bin
)
}
stop
#{
sneakers_service_name
}
"
end
end
desc
'Restart Sneakers through monit'
task
:restart
do
on
roles
(
fetch
(
:sneakers_role
))
do
sudo_if_needed
"
#{
fetch
(
:sneakers_monit_bin
)
}
restart
#{
sneakers_
monit_
service_name
}
"
sudo_if_needed
"
#{
fetch
(
:sneakers_monit_bin
)
}
restart
#{
sneakers_service_name
}
"
end
end
before
'deploy:updating'
,
'sneakers:monit:unmonitor'
after
'deploy:published'
,
'sneakers:monit:monitor'
def
sneakers_
monit_
service_name
fetch
(
:sneakers_
monit_service_name
,
"sneakers_
#{
fetch
(
:application
)
}
_
#{
fetch
(
:stage
)
}
"
)
def
sneakers_service_name
fetch
(
:sneakers_
service_name
,
"sneakers_
#{
fetch
(
:application
)
}
_
#{
fetch
(
:sneakers_env
)
}
"
)
end
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
def
upload_sneakers_template
(
from
,
to
,
role
)
template
=
sneakers_template
(
from
,
role
)
upload!
(
StringIO
.
new
(
ERB
.
new
(
template
).
result
(
binding
)),
to
)
end
def
sneakers_template
(
name
,
role
)
local_template_directory
=
fetch
(
:sneakers_monit_templates_path
)
search_paths
=
[
"
#{
name
}
-
#{
role
.
hostname
}
-
#{
fetch
(
:stage
)
}
.erb"
,
"
#{
name
}
-
#{
role
.
hostname
}
.erb"
,
"
#{
name
}
-
#{
fetch
(
:stage
)
}
.erb"
,
"
#{
name
}
.erb"
].
map
{
|
filename
|
File
.
join
(
local_template_directory
,
filename
)
}
global_search_path
=
File
.
expand_path
(
File
.
join
(
*
%w[.. .. .. generators capistrano sneakers monit templates]
,
"
#{
name
}
.conf.erb"
),
__FILE__
)
search_paths
<<
global_search_path
template_path
=
search_paths
.
detect
{
|
path
|
File
.
file?
(
path
)
}
File
.
read
(
template_path
)
end
end
end
lib/capistrano/tasks/sneakers.rake
View file @
1afdcc0b
...
...
@@ -5,12 +5,13 @@ namespace :load do
set
:sneakers_pid
,
->
{
File
.
join
(
shared_path
,
'tmp'
,
'pids'
,
'sneakers.pid'
)
}
set
:sneakers_env
,
->
{
fetch
(
:rack_env
,
fetch
(
:rails_env
,
fetch
(
:stage
)))
}
set
:sneakers_log
,
->
{
File
.
join
(
shared_path
,
'log'
,
'sneakers.log'
)
}
# set :sneakers_timeout, -> { 10 }
set
:sneakers_role
,
->
{
:app
}
set
:sneakers_processes
,
->
{
1
}
set
:sneakers_workers
,
->
{
false
}
# if this is false it will cause Capistrano to exit
set
:sneakers_run_config
,
->
{
false
}
# if this is true sneakers will run with preconfigured /config/initializers/sneakers.rb
set
:sneakers_boot_file
,
->
{
false
}
# Needed for booting daemons dynamically
# set :sneakers_timeout, -> 10
# TODO: Rename to plural
set
:sneakers_role
,
[
:app
]
set
:sneakers_processes
,
1
set
:sneakers_workers
,
false
# if this is false it will cause Capistrano to exit
# rename to sneakers_config
set
:sneakers_run_config
,
true
# if this is true sneakers will run with preconfigured /config/initializers/sneakers.rb
# Rbenv and RVM integration
set
:rbenv_map_bins
,
fetch
(
:rbenv_map_bins
).
to_a
.
concat
(
%w(sneakers)
)
set
:rvm_map_bins
,
fetch
(
:rvm_map_bins
).
to_a
.
concat
(
%w(sneakers)
)
...
...
@@ -94,43 +95,11 @@ namespace :sneakers do
workers
=
fetch
(
:sneakers_workers
).
compact
.
join
(
','
)
#run "cmd", env: { 'WORKERS' => workers } #export this to environmental variable
info
"Starting the sneakers processes"
#workers.each do |worker|
with
rails_env:
fetch
(
:sneakers_env
),
workers:
workers
do
rake
'sneakers:run'
end
#execute :bundle, :exec, :sneakers, args.compact.join(' ')
else
args
=
[]
# Using custom sneakers setup
args
.
push
"--index
#{
idx
}
"
args
.
push
"--pidfile
#{
pid_file
}
"
args
.
push
"--environment
#{
fetch
(
:sneakers_env
)
}
"
args
.
push
"--logfile
#{
fetch
(
:sneakers_log
)
}
"
if
fetch
(
:sneakers_log
)
args
.
push
"--require
#{
fetch
(
:sneakers_require
)
}
"
if
fetch
(
:sneakers_require
)
args
.
push
"--tag
#{
fetch
(
:sneakers_tag
)
}
"
if
fetch
(
:sneakers_tag
)
Array
(
fetch
(
:sneakers_queue
)).
each
do
|
queue
|
args
.
push
"--queue
#{
queue
}
"
end
args
.
push
"--config
#{
fetch
(
:sneakers_config
)
}
"
if
fetch
(
:sneakers_config
)
args
.
push
"--concurrency
#{
fetch
(
:sneakers_concurrency
)
}
"
if
fetch
(
:sneakers_concurrency
)
# use sneakers_options for special options
args
.
push
fetch
(
:sneakers_options
)
if
fetch
(
:sneakers_options
)
if
defined?
(
JRUBY_VERSION
)
args
.
push
'>/dev/null 2>&1 &'
warn
'Since JRuby doesn\'t support Process.daemon, sneakers will not be running as a daemon.'
else
args
.
push
'--daemon'
end
if
fetch
(
:start_sneakers_in_background
,
fetch
(
:sneakers_run_in_background
))
background
:bundle
,
:exec
,
:sneakers
,
args
.
compact
.
join
(
' '
)
else
execute
:bundle
,
:exec
,
:sneakers
,
args
.
compact
.
join
(
' '
)
end
end
end
...
...
lib/generators/capistrano/sneakers/monit/template_generator.rb
0 → 100644
View file @
1afdcc0b
require
'rails/generators/base'
module
Capistrano
module
Sneakers
module
Monit
module
Generators
class
TemplateGenerator
<
Rails
::
Generators
::
Base
namespace
"capistrano:sneakers:monit:template"
desc
"Create local monitrc.erb, and erb files for monitored processes for customization"
source_root
File
.
expand_path
(
'../templates'
,
__FILE__
)
argument
:templates_path
,
type: :string
,
default:
"config/deploy/templates"
,
banner:
"path to templates"
def
copy_template
copy_file
"sneakers_monit.conf.erb"
,
"
#{
templates_path
}
/sidekiq_monit.erb"
end
end
end
end
end
end
lib/
capistrano
/templates/sneakers_monit.conf.erb
→
lib/
generators/capistrano/sneakers/monit
/templates/sneakers_monit.conf.erb
View file @
1afdcc0b
# Monit configuration for Sneakers
# Service name:
<%=
sneakers_
monit_
service_name
%>
# Service name:
<%=
sneakers_service_name
%>
#
check process
<%=
sneakers_
monit_
service_name
%>
check process
<%=
sneakers_service_name
%>
with pidfile "
<%=
fetch
(
:sneakers_pid
)
%>
"
start program = "/usr/bin/sudo -iu
<%=
sneakers_user
(
@role
)
%>
/bin/bash -c 'cd
<%=
current_path
%>
&&
RAILS_ENV=
<%=
fetch
(
:sneakers_env
)
%>
WORKERS=
<%=
fetch
(
:sneakers_workers
).
join
(
','
)
%>
<%=
SSHKit
.
config
.
command_map
[
:rake
]
%>
sneakers:run'"
stop program = "/usr/bin/sudo -iu
<%=
sneakers_user
(
@role
)
%>
/bin/bash -c 'kill -SIGTERM `cat
<%=
fetch
(
:sneakers_pid
)
%>
`'"
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