magic_recipes_two 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +34 -0
- data/lib/capistrano/magic_recipes/assets.rb +1 -0
- data/lib/capistrano/magic_recipes/base_helpers.rb +63 -0
- data/lib/capistrano/magic_recipes/db.rb +1 -0
- data/lib/capistrano/magic_recipes/exception_pages.rb +1 -0
- data/lib/capistrano/magic_recipes/inform_slack.rb +1 -0
- data/lib/capistrano/magic_recipes/monit.rb +1 -0
- data/lib/capistrano/magic_recipes/nginx.rb +1 -0
- data/lib/capistrano/magic_recipes/redis.rb +1 -0
- data/lib/capistrano/magic_recipes/secrets.rb +1 -0
- data/lib/capistrano/magic_recipes/sidekiq.rb +1 -0
- data/lib/capistrano/magic_recipes/thin.rb +1 -0
- data/lib/capistrano/magic_recipes/version.rb +5 -0
- data/lib/capistrano/magic_recipes.rb +0 -0
- data/lib/capistrano/tasks/assets.rake +45 -0
- data/lib/capistrano/tasks/db.rake +20 -0
- data/lib/capistrano/tasks/exception_pages.rake +18 -0
- data/lib/capistrano/tasks/inform_slack.rake +37 -0
- data/lib/capistrano/tasks/monit.rake +173 -0
- data/lib/capistrano/tasks/monit_sidekiq.rake +44 -0
- data/lib/capistrano/tasks/nginx.rake +105 -0
- data/lib/capistrano/tasks/redis.rake +32 -0
- data/lib/capistrano/tasks/secrets.rake +43 -0
- data/lib/capistrano/tasks/sidekiq.rake +217 -0
- data/lib/capistrano/tasks/thin.rake +48 -0
- data/lib/generators/capistrano/magic_recipes/templates/capistrano3_nginx_conf.erb +68 -0
- data/lib/generators/capistrano/magic_recipes/templates/monit/monitrc.erb +67 -0
- data/lib/generators/capistrano/magic_recipes/templates/monit/nginx.erb +9 -0
- data/lib/generators/capistrano/magic_recipes/templates/monit/postgresql.erb +6 -0
- data/lib/generators/capistrano/magic_recipes/templates/monit/redis.erb +10 -0
- data/lib/generators/capistrano/magic_recipes/templates/monit/sidekiq.erb +30 -0
- data/lib/generators/capistrano/magic_recipes/templates/monit/thin.erb +13 -0
- data/lib/generators/capistrano/magic_recipes/templates/monit/website.erb +9 -0
- data/lib/generators/capistrano/magic_recipes/templates/nginx.conf.erb +139 -0
- data/lib/generators/capistrano/magic_recipes/templates/postgresql.yml.erb +8 -0
- data/lib/generators/capistrano/magic_recipes/templates/secrets_yml.erb +2 -0
- data/lib/generators/capistrano/magic_recipes/templates/thin_app_yml.erb +19 -0
- data/lib/magic_recipes_two/version.rb +3 -0
- data/lib/magic_recipes_two.rb +2 -0
- data/lib/tasks/magic_recipes_two_tasks.rake +4 -0
- metadata +183 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 56effa6ddf903dbc84cbfc4acced248845b2a662
|
4
|
+
data.tar.gz: ed01018984b79af0391bd7c2d8c0b0c88c1e3902
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1ac9e72c5703e3942ce69e9b946dcaec8976ac6ce491ab0478c3fb19751d4805e7077dbfb09ddc0fd71910836fc95b7dde57dc4ec92677bfe0d0a5d06afc7235
|
7
|
+
data.tar.gz: 9966fb7bfc7d42028bc4b14868f6a77e0ae108b3ff2cbd589c44a9be9fac3bbf21397d8333954fde3b24e3fb8d3e205b08ab38db8d89c80435e7389a39523916
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2015 Torsten Wetzel
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'MagicRecipesTwo'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
Bundler::GemHelper.install_tasks
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'lib'
|
28
|
+
t.libs << 'test'
|
29
|
+
t.pattern = 'test/**/*_test.rb'
|
30
|
+
t.verbose = false
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
task default: :test
|
@@ -0,0 +1 @@
|
|
1
|
+
load File.expand_path("../../tasks/assets.rake", __FILE__)
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
module Capistrano
|
4
|
+
module MagicRecipes
|
5
|
+
module BaseHelpers
|
6
|
+
|
7
|
+
|
8
|
+
def template(from, to)
|
9
|
+
# => erb = File.read(File.expand_path("../../../../config/deploy/templates/#{from}", __FILE__))
|
10
|
+
# => upload ERB.new(erb).result(binding), to, via: :scp
|
11
|
+
# on hosts do |host|
|
12
|
+
# upload! ERB.new(erb).result(binding), to
|
13
|
+
# end
|
14
|
+
# => erb = File.read(File.expand_path("../../../../config/deploy/templates/#{from}", __FILE__))
|
15
|
+
if File.file?(from)
|
16
|
+
config = ERB.new( File.read(from) ).result(binding)
|
17
|
+
upload! StringIO.new(config), to
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def magic_template(from, to)
|
22
|
+
erb = get_template_file(from)
|
23
|
+
upload! StringIO.new( ERB.new(erb).result(binding) ), to
|
24
|
+
end
|
25
|
+
|
26
|
+
def generate_secrect_key
|
27
|
+
SecureRandom.hex(123)
|
28
|
+
end
|
29
|
+
|
30
|
+
def template_with_role(from, to, role = nil)
|
31
|
+
erb = get_template_file(from)
|
32
|
+
upload! StringIO.new(ERB.new(erb).result(binding)), to
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def get_template_file( from )
|
37
|
+
[
|
38
|
+
File.join('config', 'deploy', 'templates', "#{from}.rb.erb"),
|
39
|
+
File.join('config', 'deploy', 'templates', "#{from}.rb"),
|
40
|
+
File.join('config', 'deploy', 'templates', "#{from}.erb"),
|
41
|
+
File.join('config', 'deploy', 'templates', "#{from}"),
|
42
|
+
File.join('lib', 'capistrano', 'templates', "#{from}.rb.erb"),
|
43
|
+
File.join('lib', 'capistrano', 'templates', "#{from}.rb"),
|
44
|
+
File.join('lib', 'capistrano', 'templates', "#{from}.erb"),
|
45
|
+
File.join('lib', 'capistrano', 'templates', "#{from}"),
|
46
|
+
File.expand_path("../../../generators/capistrano/magic_recipes/templates/#{from}.rb.erb", __FILE__),
|
47
|
+
File.expand_path("../../../generators/capistrano/magic_recipes/templates/#{from}.rb", __FILE__),
|
48
|
+
File.expand_path("../../../generators/capistrano/magic_recipes/templates/#{from}.erb", __FILE__),
|
49
|
+
File.expand_path("../../../generators/capistrano/magic_recipes/templates/#{from}", __FILE__)
|
50
|
+
].each do |path|
|
51
|
+
return File.read(path) if File.file?(path)
|
52
|
+
end
|
53
|
+
# false
|
54
|
+
raise "File '#{from}' was not found!!!"
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
load File.expand_path("../../tasks/db.rake", __FILE__)
|
@@ -0,0 +1 @@
|
|
1
|
+
load File.expand_path("../../tasks/exception_pages.rake", __FILE__)
|
@@ -0,0 +1 @@
|
|
1
|
+
load File.expand_path("../../tasks/inform_slack.rake", __FILE__)
|
@@ -0,0 +1 @@
|
|
1
|
+
load File.expand_path("../../tasks/monit.rake", __FILE__)
|
@@ -0,0 +1 @@
|
|
1
|
+
load File.expand_path("../../tasks/nginx.rake", __FILE__)
|
@@ -0,0 +1 @@
|
|
1
|
+
load File.expand_path("../../tasks/redis.rake", __FILE__)
|
@@ -0,0 +1 @@
|
|
1
|
+
load File.expand_path("../../tasks/secrets.rake", __FILE__)
|
@@ -0,0 +1 @@
|
|
1
|
+
load File.expand_path("../../tasks/sidekiq.rake", __FILE__)
|
@@ -0,0 +1 @@
|
|
1
|
+
load File.expand_path("../../tasks/thin.rake", __FILE__)
|
File without changes
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# Clear existing task so we can replace it rather than "add" to it.
|
2
|
+
Rake::Task["deploy:compile_assets"].clear
|
3
|
+
|
4
|
+
namespace :deploy do
|
5
|
+
|
6
|
+
desc 'Compile assets'
|
7
|
+
task :compile_assets => [:set_rails_env] do
|
8
|
+
# invoke 'deploy:assets:precompile'
|
9
|
+
invoke 'deploy:assets:precompile_local'
|
10
|
+
invoke 'deploy:assets:backup_manifest'
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
namespace :assets do
|
15
|
+
|
16
|
+
desc "Precompile assets locally and then rsync to web servers"
|
17
|
+
task :precompile_local do
|
18
|
+
# compile assets locally
|
19
|
+
# run_locally do
|
20
|
+
# with rails_env: fetch(:stage) do
|
21
|
+
# execute :bundle, "exec rake assets:precompile"
|
22
|
+
# end
|
23
|
+
# end
|
24
|
+
run_locally do
|
25
|
+
execute "RAILS_ENV=#{fetch(:stage)} bundle exec rake assets:precompile"
|
26
|
+
end
|
27
|
+
|
28
|
+
# rsync to each server
|
29
|
+
local_dir = "./public/assets/"
|
30
|
+
on roles( fetch(:assets_roles, [:web]) ) do
|
31
|
+
# this needs to be done outside run_locally in order for host to exist
|
32
|
+
remote_dir = "#{host.user}@#{host.hostname}:#{release_path}/public/assets/"
|
33
|
+
|
34
|
+
run_locally { execute "rsync -av --delete #{local_dir} #{remote_dir}" }
|
35
|
+
|
36
|
+
execute :sudo, :chmod, "-R 777 #{release_path}/public"
|
37
|
+
end
|
38
|
+
|
39
|
+
# clean up
|
40
|
+
run_locally { execute "rm -rf #{local_dir}" }
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
namespace :load do
|
2
|
+
task :defaults do
|
3
|
+
set :db_roles, -> { :db }
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
namespace :db do
|
8
|
+
|
9
|
+
|
10
|
+
desc "seed the database"
|
11
|
+
task :seed do
|
12
|
+
on release_roles fetch(:db_roles) do
|
13
|
+
within current_path do
|
14
|
+
execute :bundle, :exec, :rake, "db:seed RAILS_ENV=#{fetch(:stage)}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
namespace :deploy do
|
2
|
+
namespace :assets do
|
3
|
+
|
4
|
+
desc "Copy Exception Pages from assests to public folder."
|
5
|
+
task :copy_exceptions do
|
6
|
+
on roles(:web) do
|
7
|
+
within release_path do
|
8
|
+
execute :sudo, :cp, "-f public/assets/404.html public/"
|
9
|
+
execute :sudo, :cp, "-f public/assets/422.html public/"
|
10
|
+
execute :sudo, :cp, "-f public/assets/500.html public/"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
after "deploy:compile_assets", "deploy:assets:copy_exceptions"
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "uri"
|
2
|
+
require "net/http"
|
3
|
+
|
4
|
+
namespace :load do
|
5
|
+
task :defaults do
|
6
|
+
set :slack_token, -> { "xxx-xxx-xxx-xxx" }
|
7
|
+
set :slack_channel, -> { "xxx-xxx-xxx-xxx" }
|
8
|
+
set :slack_text, -> { "New Deployment on *#{ fetch(:stage) }* ... check: #{fetch(:nginx_use_ssl) ? 'https': 'htpp'}://#{ fetch(:nginx_major_domain) ? fetch(:nginx_major_domain).gsub(/^\*?\./, "") : Array( fetch(:nginx_domains) ).first.gsub(/^\*?\./, "") }" }
|
9
|
+
set :slack_username, -> { "capistrano (#{fetch(:stage)})" }
|
10
|
+
set :slack_production_icon, -> { "http://icons.iconarchive.com/icons/itzikgur/my-seven/128/Backup-IBM-Server-icon.png" }
|
11
|
+
set :slack_staging_icon, -> { "http://itekblog.com/wp-content/uploads/2012/07/railslogo.png" }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
namespace :deploy do
|
17
|
+
|
18
|
+
desc "inform slack about upload"
|
19
|
+
task :inform_slack do
|
20
|
+
|
21
|
+
params = {
|
22
|
+
token: fetch(:slack_token),
|
23
|
+
channel: fetch(:slack_channel),
|
24
|
+
text: fetch(:slack_channel),
|
25
|
+
parse: "full",
|
26
|
+
mrkdwn: true,
|
27
|
+
username: fetch(:slack_username),
|
28
|
+
icon_url: "#{ fetch(:stage) == :production ? fetch(:slack_production_icon) : fetch(:slack_staging_icon) }"
|
29
|
+
}
|
30
|
+
|
31
|
+
Net::HTTP.post_form(URI.parse('https://slack.com/api/chat.postMessage'), params)
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
after :finished, :inform_slack
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
require 'capistrano/magic_recipes/base_helpers'
|
2
|
+
include Capistrano::MagicRecipes::BaseHelpers
|
3
|
+
|
4
|
+
namespace :load do
|
5
|
+
task :defaults do
|
6
|
+
set :monit_roles, -> { :web }
|
7
|
+
set :monit_interval, -> { 30 }
|
8
|
+
## Mailer
|
9
|
+
set :monit_mail_server, -> { "smtp.gmail.com" }
|
10
|
+
set :monit_mail_port, -> { 587 }
|
11
|
+
set :monit_mail_authentication, -> { false } # SSLAUTO|SSLV2|SSLV3|TLSV1|TLSV11|TLSV12
|
12
|
+
set :monit_mail_username, -> { "foo@example.com" }
|
13
|
+
set :monit_mail_password, -> { "secret" }
|
14
|
+
set :monit_mail_to, -> { "foo@example.com" }
|
15
|
+
set :monit_mail_from, -> { "monit@foo.bar" }
|
16
|
+
set :monit_mail_reply_to, -> { "support@foo.bar" }
|
17
|
+
## Additional stuff for postrgres
|
18
|
+
set :postgresql_roles, -> { :db }
|
19
|
+
set :postgresql_pid, -> { "/var/run/postgresql/9.1-main.pid" }
|
20
|
+
## WebClient
|
21
|
+
set :monit_http_client, -> { true }
|
22
|
+
set :monit_http_domain, -> { false }
|
23
|
+
set :monit_http_port, -> { 2812 }
|
24
|
+
set :monit_http_use_ssl, -> { false }
|
25
|
+
set :monit_http_pemfile, -> { "/etc/monit/monit.pem" }
|
26
|
+
set :monit_http_username, -> { "admin" }
|
27
|
+
set :monit_http_password, -> { "monitor" }
|
28
|
+
##v Website
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
namespace :monit do
|
33
|
+
desc "Install Monit"
|
34
|
+
task :install do
|
35
|
+
on release_roles fetch(:monit_roles) do
|
36
|
+
execute :sudo, "apt-get update"
|
37
|
+
execute :sudo, "apt-get -y install monit"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
# after "deploy:install", "monit:install"
|
41
|
+
|
42
|
+
desc "Setup all Monit configuration"
|
43
|
+
task :setup do
|
44
|
+
on release_roles fetch(:monit_roles) do
|
45
|
+
monit_config "monitrc", "/etc/monit/monitrc"
|
46
|
+
# invoke "monit:nginx"
|
47
|
+
# invoke "monit:postgresql"
|
48
|
+
# invoke "monit:sidekiq"
|
49
|
+
# invoke "monit:redis"
|
50
|
+
# invoke "monit:thin"
|
51
|
+
# invoke "monit:configure_website"
|
52
|
+
|
53
|
+
%w[nginx postgresql redis sidekiq thin].each do |command|
|
54
|
+
invoke "monit:configure_#{command}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
invoke "monit:syntax"
|
58
|
+
invoke "monit:reload"
|
59
|
+
end
|
60
|
+
# after "deploy:setup", "monit:setup"
|
61
|
+
|
62
|
+
# task(:nginx, roles: :web) { monit_config "nginx" }
|
63
|
+
# task(:postgresql, roles: :db) { monit_config "postgresql" }
|
64
|
+
# task(:unicorn, roles: :app) { monit_config "unicorn" }
|
65
|
+
|
66
|
+
## Server specific tasks (gets overwritten by other environments!)
|
67
|
+
|
68
|
+
|
69
|
+
%w[nginx postgresql redis sidekiq thin].each do |process|
|
70
|
+
|
71
|
+
%w[monitor unmonitor start stop restart].each do |command|
|
72
|
+
desc "#{command} monit-service for: #{process}"
|
73
|
+
task "#{command}_#{process}" do
|
74
|
+
on roles(fetch(:sidekiq_roles)) do
|
75
|
+
if process == "sidekiq"
|
76
|
+
fetch(:sidekiq_processes).times do |idx|
|
77
|
+
sudo "#{fetch(:monit_bin)} #{command} #{sidekiq_service_name(idx)}"
|
78
|
+
end
|
79
|
+
elsif process == "thin"
|
80
|
+
fetch(:app_instances).times do |idx|
|
81
|
+
sudo "#{fetch(:monit_bin)} #{command} #{fetch(:application)}_#{fetch(:stage)}_thin_#{idx}"
|
82
|
+
end
|
83
|
+
else
|
84
|
+
sudo "#{fetch(:monit_bin)} #{command} #{process}"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
if %w[nginx postgresql redis].include?(process)
|
91
|
+
## Server specific tasks (gets overwritten by other environments!)
|
92
|
+
desc "Upload Monit #{process} config file (server specific)"
|
93
|
+
task "configure_#{process}" do
|
94
|
+
on release_roles fetch("#{process}_roles".to_sym) do |role|
|
95
|
+
monit_config( process, nil, role )
|
96
|
+
end
|
97
|
+
end
|
98
|
+
elsif %w[sidekiq thin].include?(process)
|
99
|
+
## App specific tasks (unique for app and environment)
|
100
|
+
desc "Upload Monit #{process} config file (app specific)"
|
101
|
+
task "configure_#{process}" do
|
102
|
+
on release_roles fetch("#{process}_roles".to_sym) do |role|
|
103
|
+
monit_config process, "/etc/monit/conf.d/#{fetch(:application)}_#{fetch(:stage)}_#{process}.conf", role
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
# => desc "Upload Monit website config file (server specific)"
|
111
|
+
# => task :configure_website do
|
112
|
+
# => on release_roles :web do |role|
|
113
|
+
# => monit_config( "website", nil, role )
|
114
|
+
# => end
|
115
|
+
# => end
|
116
|
+
|
117
|
+
# => %w[nginx postgresql redis].each do |command|
|
118
|
+
# => desc "Upload Monit #{command} config file (server specific)"
|
119
|
+
# => task command do
|
120
|
+
# => on release_roles fetch("#{command}_roles".to_sym) do |role|
|
121
|
+
# => monit_config( command, nil, role )
|
122
|
+
# => end
|
123
|
+
# => end
|
124
|
+
# => end
|
125
|
+
# =>
|
126
|
+
# => ## App specific tasks (unique for app and environment)
|
127
|
+
# => %w[sidekiq thin].each do |command|
|
128
|
+
# => desc "Upload Monit #{command} config file (app specific)"
|
129
|
+
# => task command do
|
130
|
+
# => on release_roles fetch("#{command}_roles".to_sym) do |role|
|
131
|
+
# => monit_config command, "/etc/monit/conf.d/#{fetch(:application)}_#{fetch(:stage)}_#{command}.conf", role
|
132
|
+
# => end
|
133
|
+
# => end
|
134
|
+
# => end
|
135
|
+
|
136
|
+
%w[start stop restart syntax reload].each do |command|
|
137
|
+
desc "Run Monit #{command} script"
|
138
|
+
task command do
|
139
|
+
on release_roles fetch(:monit_roles) do
|
140
|
+
execute :sudo, :service, :monit, "#{command}"
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def monit_config( name, destination = nil, role = nil )
|
147
|
+
@role = role
|
148
|
+
destination ||= "/etc/monit/conf.d/#{name}.conf"
|
149
|
+
template_with_role "monit/#{name}", "/tmp/monit_#{name}", @role
|
150
|
+
# erb = File.read(File.expand_path("../../../../config/deploy/templates/monit/#{name}.erb", __FILE__))
|
151
|
+
# config = ERB.new(erb).result(binding)
|
152
|
+
# upload! StringIO.new(config), "/tmp/monit_#{name}"
|
153
|
+
# run "#{sudo} mv /tmp/monit_#{name} #{destination}"
|
154
|
+
# run "#{sudo} chown root #{destination}"
|
155
|
+
# run "#{sudo} chmod 600 #{destination}"
|
156
|
+
execute :sudo, "mv /tmp/monit_#{name} #{destination}"
|
157
|
+
execute :sudo, "chown root #{destination}"
|
158
|
+
execute :sudo, "chmod 600 #{destination}"
|
159
|
+
end
|
160
|
+
|
161
|
+
|
162
|
+
namespace :deploy do
|
163
|
+
before :starting, :stop_monitoring do
|
164
|
+
%w[sidekiq thin].each do |command|
|
165
|
+
invoke "monit:unmonitor_#{command}"
|
166
|
+
end
|
167
|
+
end
|
168
|
+
after :finished, :restart_monitoring do
|
169
|
+
%w[sidekiq thin].each do |command|
|
170
|
+
invoke "monit:monitor_#{command}"
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# https://github.com/seuros/capistrano-sidekiq
|
2
|
+
|
3
|
+
require 'capistrano/magic_recipes/base_helpers'
|
4
|
+
include Capistrano::MagicRecipes::BaseHelpers
|
5
|
+
|
6
|
+
namespace :load do
|
7
|
+
task :defaults do
|
8
|
+
set :sidekiq_monit_conf_dir, -> { '/etc/monit/conf.d' }
|
9
|
+
set :monit_bin, -> { '/usr/bin/monit' }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
namespace :sidekiq do
|
15
|
+
namespace :monit do
|
16
|
+
desc 'Config Sidekiq monit-service'
|
17
|
+
task :config do
|
18
|
+
on roles(fetch(:sidekiq_roles)) do |role|
|
19
|
+
@role = role
|
20
|
+
template_with_role 'sidekiq', "#{fetch(:tmp_dir)}/monit.conf", @role
|
21
|
+
sudo "mv #{fetch(:tmp_dir)}/monit.conf #{fetch(:sidekiq_monit_conf_dir)}/#{sidekiq_service_name}.conf"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
## Server specific tasks (gets overwritten by other environments!)
|
27
|
+
%w[monitor unmonitor start stop restart].each do |command|
|
28
|
+
desc "#{command} Sidekiq monit-service"
|
29
|
+
task command do
|
30
|
+
on roles(fetch(:sidekiq_roles)) do
|
31
|
+
fetch(:sidekiq_processes).times do |idx|
|
32
|
+
sudo "#{fetch(:monit_bin)} #{command} #{sidekiq_service_name(idx)}"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def sidekiq_service_name(index=nil)
|
40
|
+
fetch(:sidekiq_service_name, "#{fetch(:application)}_#{fetch(:stage)}_sidekiq_") + index.to_s
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'capistrano/magic_recipes/base_helpers'
|
2
|
+
include Capistrano::MagicRecipes::BaseHelpers
|
3
|
+
|
4
|
+
|
5
|
+
namespace :load do
|
6
|
+
task :defaults do
|
7
|
+
set :nginx_domains, -> { [] }
|
8
|
+
set :default_site, -> { false }
|
9
|
+
set :app_instances, -> { 1 }
|
10
|
+
set :nginx_service_path, -> { 'service nginx' }
|
11
|
+
set :nginx_roles, -> { :web }
|
12
|
+
set :nginx_log_path, -> { "#{shared_path}/log" }
|
13
|
+
set :nginx_root_path, -> { "/etc/nginx" }
|
14
|
+
set :nginx_static_dir, -> { "public" }
|
15
|
+
set :nginx_sites_enabled, -> { "sites-enabled" }
|
16
|
+
set :nginx_sites_available, -> { "sites-available" }
|
17
|
+
set :nginx_template, -> { :default }
|
18
|
+
set :nginx_use_ssl, -> { false }
|
19
|
+
set :nginx_ssl_certificate, -> { "#{fetch(:application)}.crt" }
|
20
|
+
set :nginx_ssl_certificate_path, -> { '/etc/ssl/certs' }
|
21
|
+
set :nginx_ssl_certificate_key, -> { "#{fetch(:application)}.crt" }
|
22
|
+
set :nginx_ssl_certificate_key_path, -> { '/etc/ssl/private' }
|
23
|
+
set :app_server_ip, -> { "127.0.0.1" }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
namespace :nginx do
|
28
|
+
task :load_vars do
|
29
|
+
set :sites_available, -> { File.join(fetch(:nginx_root_path), fetch(:nginx_sites_available)) }
|
30
|
+
set :sites_enabled, -> { File.join(fetch(:nginx_root_path), fetch(:nginx_sites_enabled)) }
|
31
|
+
set :enabled_application, -> { File.join(fetch(:sites_enabled), "#{fetch(:application)}_#{fetch(:stage)}") }
|
32
|
+
set :available_application, -> { File.join(fetch(:sites_available), "#{fetch(:application)}_#{fetch(:stage)}") }
|
33
|
+
end
|
34
|
+
|
35
|
+
%w[start stop restart reload].each do |command|
|
36
|
+
desc "#{command.capitalize} nginx service"
|
37
|
+
task command do
|
38
|
+
nginx_service = fetch(:nginx_service_path)
|
39
|
+
on release_roles fetch(:nginx_roles) do
|
40
|
+
if command === 'stop' || (test "[ $(sudo #{nginx_service} configtest | grep -c 'fail') -eq 0 ]")
|
41
|
+
execute :sudo, "#{nginx_service} #{command}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
after 'deploy:check', nil do
|
48
|
+
on release_roles fetch(:nginx_roles) do
|
49
|
+
execute :mkdir, '-pv', fetch(:nginx_log_path)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
namespace :site do
|
54
|
+
desc 'Creates the site configuration and upload it to the available folder'
|
55
|
+
task :add => ['nginx:load_vars'] do
|
56
|
+
on release_roles fetch(:nginx_roles) do
|
57
|
+
within fetch(:sites_available) do
|
58
|
+
config_file = fetch(:nginx_template)
|
59
|
+
if config_file == :default
|
60
|
+
# config_file = File.expand_path("../../../../config/deploy/templates/nginx.conf.erb", __FILE__)
|
61
|
+
magic_template("nginx.conf", '/tmp/nginx.conf')
|
62
|
+
end
|
63
|
+
# config = ERB.new(File.read(config_file)).result(binding)
|
64
|
+
# upload! StringIO.new(config), '/tmp/nginx.conf'
|
65
|
+
template(config_file, '/tmp/nginx.conf')
|
66
|
+
|
67
|
+
execute :sudo, :mv, '/tmp/nginx.conf', "#{fetch(:application)}_#{fetch(:stage)}"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
desc 'Enables the site creating a symbolic link into the enabled folder'
|
73
|
+
task :enable => ['nginx:load_vars'] do
|
74
|
+
on release_roles fetch(:nginx_roles) do
|
75
|
+
if test "! [ -h #{fetch(:enabled_application)} ]"
|
76
|
+
within fetch(:sites_enabled) do
|
77
|
+
execute :sudo, :ln, '-nfs', fetch(:available_application), fetch(:enabled_application)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
desc 'Disables the site removing the symbolic link located in the enabled folder'
|
84
|
+
task :disable => ['nginx:load_vars'] do
|
85
|
+
on release_roles fetch(:nginx_roles) do
|
86
|
+
if test "[ -f #{fetch(:enabled_application)} ]"
|
87
|
+
within fetch(:sites_enabled) do
|
88
|
+
execute :sudo, :rm, '-f', "#{fetch(:application)}_#{fetch(:stage)}"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
desc 'Removes the site removing the configuration file from the available folder'
|
95
|
+
task :remove => ['nginx:load_vars'] do
|
96
|
+
on release_roles fetch(:nginx_roles) do
|
97
|
+
if test "[ -f #{fetch(:available_application)} ]"
|
98
|
+
within fetch(:sites_available) do
|
99
|
+
execute :sudo, :rm, "#{fetch(:application)}_#{fetch(:stage)}"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
namespace :load do
|
3
|
+
task :defaults do
|
4
|
+
set :redis_roles, -> { :web }
|
5
|
+
set :redis_pid, -> { "/var/run/redis/redis-server.pid" }
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
namespace :redis do
|
10
|
+
desc "Install the latest release of Redis"
|
11
|
+
task :install do
|
12
|
+
|
13
|
+
on release_roles fetch(:redis_roles) do
|
14
|
+
execute :sudo, "apt-get -y update"
|
15
|
+
execute :sudo, "apt-get -y upgrade"
|
16
|
+
execute :sudo, "apt-get -y install redis-server"
|
17
|
+
# save default config, for security
|
18
|
+
execute :sudo, :cp, "/etc/redis/redis.conf /etc/redis/redis.conf.default"
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
# => after "deploy:install", "redis:install"
|
23
|
+
|
24
|
+
%w[start stop restart].each do |command|
|
25
|
+
desc "#{command} REDIS server"
|
26
|
+
task command do
|
27
|
+
on release_roles fetch(:redis_roles) do
|
28
|
+
execute :sudo, :service, "redis-server #{command}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|