georgia_recipes 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.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +48 -0
  6. data/Rakefile +1 -0
  7. data/georgia_recipes.gemspec +24 -0
  8. data/lib/georgia_recipes/all.rb +24 -0
  9. data/lib/georgia_recipes/apache.rb +10 -0
  10. data/lib/georgia_recipes/assets.rb +36 -0
  11. data/lib/georgia_recipes/base.rb +54 -0
  12. data/lib/georgia_recipes/carrierwave.rb +39 -0
  13. data/lib/georgia_recipes/chef.rb +10 -0
  14. data/lib/georgia_recipes/elasticsearch.rb +21 -0
  15. data/lib/georgia_recipes/errbit.rb +25 -0
  16. data/lib/georgia_recipes/georgia.rb +53 -0
  17. data/lib/georgia_recipes/helper_methods.rb +90 -0
  18. data/lib/georgia_recipes/imagemagick.rb +10 -0
  19. data/lib/georgia_recipes/memcached.rb +27 -0
  20. data/lib/georgia_recipes/mongodb.rb +15 -0
  21. data/lib/georgia_recipes/monit.rb +56 -0
  22. data/lib/georgia_recipes/mysql.rb +62 -0
  23. data/lib/georgia_recipes/newrelic.rb +39 -0
  24. data/lib/georgia_recipes/nginx.rb +28 -0
  25. data/lib/georgia_recipes/nodejs.rb +12 -0
  26. data/lib/georgia_recipes/postgresql.rb +92 -0
  27. data/lib/georgia_recipes/rbenv.rb +40 -0
  28. data/lib/georgia_recipes/redis.rb +18 -0
  29. data/lib/georgia_recipes/sidekiq.rb +22 -0
  30. data/lib/georgia_recipes/solr.rb +77 -0
  31. data/lib/georgia_recipes/templates/chef-solo.rb.erb +4 -0
  32. data/lib/georgia_recipes/templates/memcached.erb +16 -0
  33. data/lib/georgia_recipes/templates/monit/mysql.erb +6 -0
  34. data/lib/georgia_recipes/templates/monit/nginx.erb +5 -0
  35. data/lib/georgia_recipes/templates/monit/postgresql.erb +5 -0
  36. data/lib/georgia_recipes/templates/monit/sidekiq.erb +4 -0
  37. data/lib/georgia_recipes/templates/monit/solr.erb +4 -0
  38. data/lib/georgia_recipes/templates/monit/unicorn.erb +15 -0
  39. data/lib/georgia_recipes/templates/monit.node.json.erb +14 -0
  40. data/lib/georgia_recipes/templates/nginx.erb +40 -0
  41. data/lib/georgia_recipes/templates/postgresql.yml.erb +8 -0
  42. data/lib/georgia_recipes/templates/sidekiq.yml.erb +7 -0
  43. data/lib/georgia_recipes/templates/solr.chef.node.json.erb +11 -0
  44. data/lib/georgia_recipes/templates/unicorn.rb.erb +36 -0
  45. data/lib/georgia_recipes/templates/unicorn_init.erb +84 -0
  46. data/lib/georgia_recipes/unicorn.rb +156 -0
  47. data/lib/georgia_recipes/version.rb +3 -0
  48. data/lib/georgia_recipes.rb +5 -0
  49. metadata +134 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a16213f5c7060bbd035be7076e9d42a599f2e732
4
+ data.tar.gz: 8e0528af4e1c100dbf30c1ab8865cf9d67593561
5
+ SHA512:
6
+ metadata.gz: 8e8c1f410092f0c794430dfbd194301a0ab30f845f2c1d5be338e180e2a59165daa41e82683aa0e59dd02444e981bf4fe8b6873a71f798f6007b0634f527480a
7
+ data.tar.gz: ad2049f9cdafd734c4b6ba89de97f314b6779dff19889341b2e87aa3ee6844c9d67ecdd9c91835e600eed03e711ef518582c7fe482457814af639d7491dcd171
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in georgia_recipes.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Mathieu Gagne
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,48 @@
1
+ # Georgia Recipes
2
+
3
+ Capistrano recipes for Georgia CMS. Helps you setup a VM with the necessary dependencies to run a full Rails stack with Georgia CMS
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'georgia_recipes', group: :development
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install georgia_recipes
18
+
19
+ ## Usage
20
+
21
+ Drop this line of code in your `config/deploy.rb` file to include additional recipes.
22
+
23
+ require 'georgia_recipes/all'
24
+
25
+ Or require them individually:
26
+
27
+ ``` ruby
28
+ require 'georgia_recipes/base'
29
+ require 'georgia_recipes/chef'
30
+ require 'georgia_recipes/elasticsearch'
31
+ require 'georgia_recipes/memcached'
32
+ require 'georgia_recipes/mongodb'
33
+ require 'georgia_recipes/nginx'
34
+ require 'georgia_recipes/unicorn'
35
+ require 'georgia_recipes/rbenv'
36
+ require 'georgia_recipes/redis'
37
+ require 'georgia_recipes/solr'
38
+ require 'georgia_recipes/postgresql'
39
+ ...
40
+ ```
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it ( http://github.com/<my-github-username>/georgia_recipes/fork )
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'georgia_recipes/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "georgia_recipes"
8
+ spec.version = GeorgiaRecipes::VERSION
9
+ spec.authors = ["Mathieu Gagne"]
10
+ spec.email = ["gagne.mathieu@hotmail.com"]
11
+ spec.description = %q{Capistrano recipes for Georgia CMS.}
12
+ spec.summary = %q{Capistrano recipes for Georgia CMS. Helps you setup a VM with the necessary dependencies to run a full Rails stack with Georgia CMS}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "capistrano", '~> 2'
22
+ spec.add_dependency "capistrano-ext"
23
+ spec.add_dependency "capistrano-maintenance"
24
+ end
@@ -0,0 +1,24 @@
1
+ require 'georgia_recipes/base'
2
+
3
+ # require 'georgia_recipes/apache'
4
+ require 'georgia_recipes/assets'
5
+ # require 'georgia_recipes/backup'
6
+ # require 'georgia_recipes/carrierwave'
7
+ require 'georgia_recipes/chef'
8
+ # require 'georgia_recipes/elasticsearch'
9
+ # require 'georgia_recipes/errbit'
10
+ require 'georgia_recipes/georgia'
11
+ require 'georgia_recipes/imagemagick'
12
+ require 'georgia_recipes/memcached'
13
+ # require 'georgia_recipes/mongodb'
14
+ require 'georgia_recipes/monit'
15
+ # require 'georgia_recipes/mysql'
16
+ require 'georgia_recipes/newrelic'
17
+ require 'georgia_recipes/nginx'
18
+ # require 'georgia_recipes/nodejs'
19
+ require 'georgia_recipes/postgresql'
20
+ require 'georgia_recipes/rbenv'
21
+ require 'georgia_recipes/redis'
22
+ require 'georgia_recipes/sidekiq'
23
+ require 'georgia_recipes/solr'
24
+ require 'georgia_recipes/unicorn'
@@ -0,0 +1,10 @@
1
+ Capistrano::Configuration.instance.load do
2
+
3
+ namespace :apache do
4
+ desc "Install Apache2"
5
+ task :install, roles: :web do
6
+ run "#{sudo} apt-get -y install apache2 apache2-prefork-dev libapr1-dev libaprutil1-dev libapache2-mod-php5"
7
+ end
8
+ end
9
+
10
+ end
@@ -0,0 +1,36 @@
1
+ Capistrano::Configuration.instance.load do
2
+
3
+ def precompile_assets
4
+ run_locally "bundle exec rake assets:precompile"
5
+ find_servers_for_task(current_task).each do |server|
6
+ run_locally "rsync -vr --exclude='.DS_Store' -e 'ssh -p #{ssh_options[:port] || 22}' public/assets #{user}@#{server.host}:#{shared_path}/"
7
+ end
8
+ run_locally "rm -Rf public/assets"
9
+ end
10
+
11
+ namespace :deploy do
12
+ namespace :assets do
13
+ desc "Precompile assets on local machine and upload them to the server if assets changed."
14
+ task :precompile, roles: :web, except: {no_release: true} do
15
+ begin
16
+ from = source.next_revision(current_revision)
17
+ if capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ app/assets/ | wc -l").to_i > 0
18
+ precompile_assets
19
+ else
20
+ logger.info "Skipping asset pre-compilation because there were no asset changes"
21
+ end
22
+ rescue
23
+ precompile_assets
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ namespace :assets do
30
+ desc "Compile assets on local machine and upload them to the server."
31
+ task :compile, roles: :web, except: {no_release: true} do
32
+ precompile_assets
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,54 @@
1
+ require 'capistrano'
2
+ require 'capistrano/cli'
3
+
4
+ Capistrano::Configuration.instance.load do
5
+
6
+ set_default(:host) { ask("What is the fully qualified domain name?") }
7
+ set_default(:remote_db_user) { db_config_file["#{rails_env}"]["username"] rescue ask("Remote database user: ") }
8
+ set_default(:remote_db_user) { db_config_file["#{rails_env}"]["database"] rescue ask("Remote database name: ") }
9
+ set_default(:remote_db_user) { db_config_file["#{rails_env}"]["password"] rescue ask("Remote database password: ") }
10
+ set_default(:local_db_user) { db_config_file["development"]["username"] rescue ask("Local database user: ") }
11
+ set_default(:local_db_user) { db_config_file["development"]["database"] rescue ask("Local database name: ") }
12
+ set_default(:local_db_user) { db_config_file["development"]["password"] rescue ask("Local database password: ") }
13
+
14
+ namespace :deploy do
15
+
16
+ desc "Adds user 'deployer' with your ssh keys"
17
+ task :bootstrap do
18
+ with_user('root') do
19
+ run "adduser --disabled-password --gecos '' deployer"
20
+ run "echo 'deployer ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers"
21
+ run "apt-get update ; apt-get -y install curl"
22
+ run "sudo -u deployer curl https://github.com/#{github_handle}.keys -o /home/deployer/.ssh/authorized_keys --create-dirs"
23
+ end
24
+ end
25
+ end
26
+
27
+ namespace :ssh do
28
+ task :reset_keys do
29
+ run "curl https://github.com/#{github_handle}.keys -o ~/.ssh/authorized_keys --create-dirs"
30
+ end
31
+ task :add_keys do
32
+ run "sed -i -e '$a\' ~/.ssh/authorized_keys"
33
+ run "curl https://github.com/#{github_handle}.keys | tee -a ~/.ssh/authorized_keys"
34
+ end
35
+ end
36
+
37
+ namespace :locale do
38
+ desc "Set locale to en_US.UTF-8"
39
+ task :setup, roles: :web do
40
+ run "#{sudo} apt-get -y install language-pack-en-base"
41
+ run "export LANGUAGE=en_US.UTF-8"
42
+ run "export LANG=en_US.UTF-8"
43
+ run "export LC_ALL=en_US.UTF-8"
44
+ run "export LC_CTYPE=en_US.UTF-8"
45
+ run "#{sudo} locale-gen en_US.UTF-8"
46
+ run "#{sudo} dpkg-reconfigure locales"
47
+ end
48
+ end
49
+
50
+ def github_handle
51
+ Capistrano::CLI.ui.ask "Which Github handle would you like to add?"
52
+ end
53
+
54
+ end
@@ -0,0 +1,39 @@
1
+ Capistrano::Configuration.instance.load do
2
+
3
+ # These tasks are meant to be use if you keep Carrierwave files locally
4
+ # instead of a Cloud Storage (Amazon S3, Rackspace Cloud Files, etc.)
5
+ namespace :carrierwave do
6
+
7
+ desc "Symlink public/uploads folder to shared files directories"
8
+ task :symlink, except: { no_release: true } do
9
+ run "rm -rf #{current_path}/public/uploads"
10
+ run "mkdir -p #{shared_path}/uploads"
11
+ run "ln -fns #{shared_path}/uploads #{current_path}/public/uploads"
12
+ end
13
+ after 'deploy:create_symlink', 'carrierwave:symlink'
14
+
15
+ namespace :uploads do
16
+
17
+ desc "Zip and pull all files from the public/uploads folder. remote => local"
18
+ task :pull, roles: :app do
19
+ run "cd #{shared_path} && tar -czvf /tmp/uploads_#{timestamp}.tar.gz uploads"
20
+ get "/tmp/uploads_#{timestamp}.tar.gz", "/tmp/uploads_#{timestamp}.tar.gz"
21
+ run "rm /tmp/uploads_#{timestamp}.tar.gz"
22
+ run_locally "cd public && tar -xzvf /tmp/uploads_#{timestamp}.tar.gz"
23
+ run_locally "rm /tmp/uploads_#{timestamp}.tar.gz"
24
+ end
25
+
26
+ desc "Zip and push all files to the public/uploads folder. local => remote"
27
+ task :push, roles: :app do
28
+ run_locally "cd public && tar -czvf /tmp/uploads_#{timestamp}.tar.gz uploads"
29
+ upload "/tmp/uploads_#{timestamp}.tar.gz", "/tmp/uploads_#{timestamp}.tar.gz"
30
+ run_locally "rm /tmp/uploads_#{timestamp}.tar.gz"
31
+ run "cd #{shared_path} && tar -xzvf /tmp/uploads_#{timestamp}.tar.gz"
32
+ run "rm /tmp/uploads_#{timestamp}.tar.gz"
33
+ end
34
+
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -0,0 +1,10 @@
1
+ Capistrano::Configuration.instance.load do
2
+
3
+ namespace :chef do
4
+
5
+ task :install, roles: :app do
6
+ run "curl -L https://www.opscode.com/chef/install.sh | sudo bash"
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,21 @@
1
+ Capistrano::Configuration.instance.load do
2
+
3
+ set_default :es_version, "0.90.11"
4
+
5
+ namespace :elasticsearch do
6
+ desc "Install latest stable release of elasticsearch"
7
+ task :install, roles: :web do
8
+ run "wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-#{es_version}.deb"
9
+ run "#{sudo} dpkg -i elasticsearch-#{es_version}.deb"
10
+ run "rm elasticsearch-#{es_version}.deb"
11
+ end
12
+
13
+ %w[start stop restart force_reload status].each do |command|
14
+ desc "#{command} elasticsearch"
15
+ task command, roles: :web do
16
+ run "#{sudo} service elasticsearch #{command}"
17
+ end
18
+ end
19
+ end
20
+
21
+ end
@@ -0,0 +1,25 @@
1
+ Capistrano::Configuration.instance.load do
2
+
3
+ def username
4
+ @username ||= run_locally("git config user.email")
5
+ @username[0..-2] #strips the \n from stdout
6
+ end
7
+
8
+ def revision
9
+ @revision ||= run_locally('git rev-parse --short HEAD')
10
+ @revision[0..-2] #strips the \n from stdout
11
+ end
12
+
13
+ unless exists? :stage
14
+ set(:stage) { 'production' }
15
+ end
16
+
17
+ namespace :errbit do
18
+ desc "Notifiy Errbit of a new deploy"
19
+ task :notify, roles: :app do
20
+ run "cd #{current_path} && bundle exec rake airbrake:deploy TO=#{stage} USER=#{username} REPO=#{repository} REVISION=#{revision} RAILS_ENV=#{rails_env}"
21
+ end
22
+ after "deploy", "errbit:notify"
23
+ end
24
+
25
+ end
@@ -0,0 +1,53 @@
1
+ Capistrano::Configuration.instance.load do
2
+ namespace :georgia do
3
+
4
+ desc "Install rails stack onto the server for Georgia CMS"
5
+ task :install do
6
+ run "#{sudo} apt-get -y update"
7
+ run "#{sudo} apt-get -y install vim python-software-properties software-properties-common subversion libxslt1-dev libxml2-dev git-core"
8
+ run "ssh-keyscan github.com >> ~/.ssh/known_hosts"
9
+ run "ssh-keyscan git.motioneleven.com >> ~/.ssh/known_hosts"
10
+ end
11
+ before "georgia:install", "locale:setup"
12
+ after "georgia:install", "rbenv:install"
13
+ after "georgia:install", "chef:install"
14
+ after "georgia:install", "monit:install"
15
+ after "georgia:install", "imagemagick:install"
16
+ after "georgia:install", "nginx:install"
17
+ after "georgia:install", "pg:install"
18
+ after "georgia:install", "memcached:install"
19
+ after "georgia:install", "redis:install"
20
+ after "georgia:install", "newrelic:install"
21
+ after "georgia:install", "backup:install"
22
+
23
+ task :setup do
24
+ # Trigger callbacks for setting up a rails stack after install
25
+ end
26
+ after "georgia:setup", "memcached:setup"
27
+ after "georgia:setup", "nginx:setup"
28
+ after "georgia:setup", "pg:setup"
29
+ after "georgia:setup", "unicorn:setup"
30
+ after "georgia:setup", "monit:setup"
31
+ after "georgia:setup", "backup:setup"
32
+ after "georgia:setup", "sidekiq:setup"
33
+ after "georgia:setup", "newrelic:setup"
34
+
35
+ task :seed, roles: :web do
36
+ run "cd #{current_path} && bundle exec rake georgia:seed RAILS_ENV=#{rails_env}"
37
+ end
38
+
39
+ desc "Run georgia:upgrade task"
40
+ task :upgrade, roles: :web do
41
+ run "cd #{current_path} && bundle exec rake georgia:upgrade RAILS_ENV=#{rails_env}"
42
+ end
43
+
44
+ namespace :tire do
45
+ task :reindex, roles: :app do
46
+ ['Georgia::Page', 'Ckeditor::Asset', 'Ckeditor::Picture', 'ActsAsTaggableOn::Tag'].each do |model|
47
+ run "cd #{current_path} && bundle exec rake environment tire:import CLASS=#{model} FORCE=true RAILS_ENV=#{rails_env}"
48
+ end
49
+ end
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,90 @@
1
+ def timestamp
2
+ @timestamp ||= Time.now.strftime('%Y%m%d%H%M%S')
3
+ end
4
+
5
+ def template(from, to)
6
+ erb = File.read(File.expand_path("../templates/#{from}", __FILE__))
7
+ put ERB.new(erb).result(binding), to
8
+ end
9
+
10
+ def set_default(name, *args, &block)
11
+ set(name, *args, &block) unless exists?(name)
12
+ end
13
+
14
+ def are_you_sure?
15
+ ask("Holy Moly! Are you sure you want to do that? (type 'yes' if so)") == 'yes'
16
+ end
17
+
18
+ def ask question
19
+ Capistrano::CLI.ui.ask question
20
+ end
21
+
22
+ # Methods taken from: https://github.com/donnoman/cap-recipes/blob/master/lib/cap_recipes/tasks/utilities.rb
23
+
24
+ ##
25
+ # Run a command and ask for input when input_query is seen.
26
+ # Sends the response back to the server.
27
+ #
28
+ # +input_query+ is a regular expression that defaults to /^Password/.
29
+ # Can be used where +run+ would otherwise be used.
30
+ # run_with_input 'ssh-keygen ...', /^Are you sure you want to overwrite\?/
31
+ def run_with_input(shell_command, input_query=/^Password/, response=nil)
32
+ handle_command_with_input(:run, shell_command, input_query, response)
33
+ end
34
+
35
+ ##
36
+ # Does the actual capturing of the input and streaming of the output.
37
+ #
38
+ # local_run_method: run or sudo
39
+ # shell_command: The command to run
40
+ # input_query: A regular expression matching a request for input: /^Please enter your password/
41
+ def handle_command_with_input(local_run_method, shell_command, input_query, response=nil)
42
+ send(local_run_method, shell_command, {:pty => true}) do |channel, stream, data|
43
+ if data =~ input_query
44
+ if response
45
+ logger.info "#{data} #{"*"*(rand(10)+5)}", channel[:host]
46
+ channel.send_data "#{response}\n"
47
+ else
48
+ logger.info data, channel[:host]
49
+ response = ::Capistrano::CLI.password_prompt "#{data}"
50
+ channel.send_data "#{response}\n"
51
+ end
52
+ else
53
+ logger.info data, channel[:host]
54
+ end
55
+ end
56
+ end
57
+
58
+ def git_pull_or_clone repo_name, repo_url
59
+ run "bash -c 'if cd #{repo_name}; then git pull origin master; else git clone #{repo_url} #{repo_name}; fi'"
60
+ end
61
+
62
+ # run a command on the server with a different user
63
+ def with_user(new_user, new_pass, &block)
64
+ old_user, old_pass = user, password
65
+ set_user(new_user, new_pass)
66
+ begin
67
+ yield
68
+ rescue Exception => e
69
+ set_user(old_user, old_pass)
70
+ raise e
71
+ end
72
+ set_user(old_user, old_pass)
73
+ end
74
+
75
+ # change the capistrano user
76
+ def set_user(user, pass)
77
+ set :user, user
78
+ set :password, pass
79
+ close_sessions
80
+ end
81
+
82
+ # disconnect all sessions
83
+ def close_sessions
84
+ sessions.values.each { |session| session.close }
85
+ sessions.clear
86
+ end
87
+
88
+ def db_config_file
89
+ @db_config_file ||= YAML.load(File.read('config/database.yml'))
90
+ end
@@ -0,0 +1,10 @@
1
+ Capistrano::Configuration.instance.load do
2
+
3
+ namespace :imagemagick do
4
+ desc "Install ImageMagick dependencies"
5
+ task :install, roles: :web do
6
+ run "#{sudo} apt-get -y install imagemagick libmagickcore-dev libmagickwand-dev"
7
+ end
8
+ end
9
+
10
+ end
@@ -0,0 +1,27 @@
1
+ Capistrano::Configuration.instance.load do
2
+
3
+ set_default :memcached_memory_limit, 64
4
+
5
+ namespace :memcached do
6
+ desc "Install Memcached"
7
+ task :install, roles: :app do
8
+ run "#{sudo} apt-get -y update"
9
+ run "#{sudo} apt-get install -y memcached"
10
+ end
11
+
12
+ desc "Setup Memcached"
13
+ task :setup, roles: :app do
14
+ template "memcached.erb", "/tmp/memcached.conf"
15
+ run "#{sudo} mv /tmp/memcached.conf /etc/memcached.conf"
16
+ restart
17
+ end
18
+
19
+ %w[start stop restart].each do |command|
20
+ desc "#{command} Memcached"
21
+ task command, roles: :app do
22
+ run "#{sudo} service memcached #{command}"
23
+ end
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,15 @@
1
+ Capistrano::Configuration.instance.load do
2
+
3
+ namespace :mongodb do
4
+
5
+ desc "Install MongoDB"
6
+ task :install, roles: :app do
7
+ run "#{sudo} apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10"
8
+ run "echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | #{sudo} tee /etc/apt/sources.list.d/mongodb.list"
9
+ run "#{sudo} apt-get -y update"
10
+ run "#{sudo} apt-get -y install mongodb-10gen"
11
+ end
12
+
13
+ end
14
+
15
+ end
@@ -0,0 +1,56 @@
1
+ Capistrano::Configuration.instance.load do
2
+ namespace :monit do
3
+
4
+ desc "Install Monit. Requires Chef (chef:install)"
5
+ task :install, roles: :app do
6
+ run "mkdir -p cookbooks"
7
+ git_pull_or_clone('cookbooks/yum', 'git@github.com:opscode-cookbooks/yum.git')
8
+ git_pull_or_clone('cookbooks/sysctl', 'git@github.com:rcbops-cookbooks/sysctl.git')
9
+ git_pull_or_clone('cookbooks/apt', 'git@github.com:opscode-cookbooks/apt.git')
10
+ git_pull_or_clone('cookbooks/osops-utils', 'git@github.com:rcbops-cookbooks/osops-utils.git')
11
+ git_pull_or_clone('cookbooks/monit', 'git@github.com:rcbops-cookbooks/monit.git')
12
+ config
13
+ end
14
+
15
+ task :config, roles: :app do
16
+ template "monit.node.json.erb", "node.json"
17
+ template "chef-solo.rb.erb", "solo.rb"
18
+ run "#{sudo} chef-solo -j node.json -c solo.rb"
19
+ end
20
+
21
+ %w[start stop restart syntax reload].each do |command|
22
+ desc "Run Monit #{command} script"
23
+ task command do
24
+ run "#{sudo} service monit #{command}"
25
+ end
26
+ end
27
+ before "deploy:stop", "monit:stop"
28
+ after "deploy:start", "monit:start"
29
+
30
+ desc "Setup all Monit configuration for default Rails stack"
31
+ task :setup do
32
+ nginx
33
+ postgresql
34
+ sidekiq
35
+ unicorn
36
+ syntax
37
+ reload
38
+ end
39
+
40
+ task(:nginx, roles: :web) { monit_config "nginx" }
41
+ task(:postgresql, roles: :db) { monit_config "postgresql" }
42
+ task(:unicorn, roles: :app) { monit_config "unicorn" }
43
+ task(:sidekiq, roles: :app) { monit_config "sidekiq" }
44
+ task(:solr, roles: :web) { monit_config "solr" }
45
+ task(:mysql, roles: :web) { monit_config "mysql" }
46
+
47
+ def monit_config(name, destination = nil)
48
+ destination ||= "/etc/monit/conf.d/#{name}.conf"
49
+ template "monit/#{name}.erb", "/tmp/monit_#{name}"
50
+ run "#{sudo} mv /tmp/monit_#{name} #{destination}"
51
+ run "#{sudo} chown root:root #{destination}"
52
+ run "#{sudo} chmod 600 #{destination}"
53
+ end
54
+
55
+ end
56
+ end