crossroads_capistrano 1.1.0

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.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in crossroads_capistrano.gemspec
4
+ gemspec
@@ -0,0 +1,18 @@
1
+ h1. Crossroads Capistrano
2
+
3
+ A "Crossroads":http://www.crossroads.org.hk specific set of generic capistrano recipes.
4
+
5
+ This gem can be included in all our rails apps that use Capistrano.
6
+
7
+ h3. Usage
8
+
9
+ Add the following to your project's *Gemfile* :
10
+
11
+ bc. gem 'crossroads_capistrano', :git => 'http://github.com/crossroads/crossroads_capistrano.git'
12
+
13
+ Add the following to your project's *config/deploy.rb* :
14
+
15
+ bc. require 'crossroads_capistrano'
16
+ CrossroadsCapistrano.load_recipes %w(prompt stack rvm passenger postgresql newrelic log)
17
+ # or ..
18
+ CrossroadsCapistrano.load_recipes :all
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "crossroads_capistrano"
6
+ s.version = "1.1.0"
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Steve Kenworthy", "Ben Tillman", "Nathan Broadbent"]
9
+ s.email = ["it_dept@crossroads.org.hk"]
10
+ s.homepage = "http://www.crossroads.org.hk"
11
+ s.summary = %q{Crossroads capistrano recipes}
12
+ s.description = %q{A Crossroads Foundation collection of generic capistrano recipes.}
13
+
14
+ s.rubyforge_project = "crossroads_capistrano"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+ end
@@ -0,0 +1,17 @@
1
+ module CrossroadsCapistrano
2
+ @@cap_config = Capistrano::Configuration.instance(:must_exist)
3
+ class << self
4
+ def load_recipes(recipes)
5
+ @@cap_config.load do
6
+ if recipes == :all
7
+ # Load all available recipes.
8
+ Dir.glob(File.join(File.dirname(__FILE__), 'crossroads_capistrano', '*.rb')).each{|f| load f}
9
+ else
10
+ # Load each specified recipe.
11
+ recipes.each {|r| load File.join(File.dirname(__FILE__),'crossroads_capistrano',"#{r}.rb")}
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+
@@ -0,0 +1,21 @@
1
+ namespace :delayed_job do
2
+ desc "Stop the delayed_job process"
3
+ task :stop, :roles => :app do
4
+ run "cd #{current_path}; RAILS_ENV=production script/delayed_job stop"
5
+ end
6
+
7
+ desc "Start the delayed_job process"
8
+ task :start, :roles => :app do
9
+ run "cd #{current_path}; RAILS_ENV=production script/delayed_job start"
10
+ end
11
+
12
+ desc "Restart the delayed_job process"
13
+ task :restart, :roles => :app do
14
+ run "cd #{current_path}; RAILS_ENV=production script/delayed_job restart"
15
+ end
16
+
17
+ desc "delayed_job status"
18
+ task :status, :roles => :app do
19
+ run "ps aux | grep 'delayed_job'"
20
+ end
21
+ end
@@ -0,0 +1,12 @@
1
+ namespace :log do
2
+
3
+ desc "tail production log files"
4
+ task :tail, :roles => :app do
5
+ run "tail -f #{shared_path}/log/production.log" do |channel, stream, data|
6
+ puts # for an extra line break before the host name
7
+ puts "#{channel[:host]}: #{data}"
8
+ break if stream == :err
9
+ end
10
+ end
11
+
12
+ end
@@ -0,0 +1,14 @@
1
+ namespace :newrelic do
2
+
3
+ task :default do
4
+ newrelic.yml
5
+ end
6
+
7
+ desc "Copy newrelic.yml"
8
+ task :yml do
9
+ run "ln -sf #{deploy_to}/shared/config/newrelic.yml #{release_path}/config/newrelic.yml"
10
+ end
11
+
12
+ end
13
+
14
+ before "deploy:symlink", "newrelic:yml"
@@ -0,0 +1,49 @@
1
+ #
2
+ # Adds passenger tasks to deploy stack
3
+ #
4
+ # Ensure the following variables are set in your deploy.rb
5
+ # - set :ip_address, "127.0.0.1"
6
+ # - set :site_domain_name, "www.example.com"
7
+ # - set :passenger_version, "3.0.0"
8
+ #
9
+ # And that the following files exist:
10
+ #
11
+ # config/httpd-rails.conf
12
+ # config/passenger.conf
13
+ #
14
+
15
+ namespace :deploy do
16
+
17
+ %w(start stop restart reload).each do |t|
18
+ desc "#{t.capitalize} passenger using httpd"
19
+ task "#{t.to_sym}", :roles => :app, :except => { :no_release => true } do
20
+ run "/etc/init.d/httpd #{t}"
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ namespace :passenger do
27
+
28
+ desc "Install Passenger"
29
+ task :install, :roles => :web do
30
+ install_deps
31
+
32
+ run "gem install passenger --no-rdoc --no-ri --version #{passenger_version}"
33
+ run "passenger-install-apache2-module --auto"
34
+ end
35
+
36
+ task :install_deps, :roles => :web do
37
+ yum.install( {:base => %w(curl-devel httpd-devel apr-devel)}, :stable )
38
+ end
39
+
40
+ desc "Apache config files"
41
+ task :config, :roles => :web do
42
+ run "sed -e 's,@DEPLOY_TO@,#{deploy_to},g' -e 's,@IP_ADDR@,#{ip_address},g' -e 's,@SERVER_NAME@,#{site_domain_name},g' #{release_path}/config/httpd-rails.conf > /etc/httpd/sites-enabled/010-#{application}-#{stage}.conf"
43
+ run "sed -e 's,@RVM_RUBY_STRING@,#{rvm_ruby_string},g' -e 's,@PASSENGER_VERSION@,#{passenger_version},g' #{release_path}/config/passenger.conf > /etc/httpd/mods-enabled/passenger.conf"
44
+ end
45
+
46
+ end
47
+
48
+ before "deploy:cold", "passenger:install"
49
+ after "deploy:update_code", "passenger:config"
@@ -0,0 +1,29 @@
1
+ namespace :postgresql do
2
+
3
+ task :symlink do
4
+ sudo "ln -sf #{deploy_to}/shared/config/database.yml #{release_path}/config/database.yml"
5
+ end
6
+
7
+ desc "Start PostgreSQL"
8
+ task :start, :roles => :db do
9
+ send(run_method, "/etc/init.d/postgresql start")
10
+ end
11
+
12
+ desc "Stop PostgreSQL"
13
+ task :stop, :roles => :db do
14
+ send(run_method, "/etc/init.d/postgresql stop")
15
+ end
16
+
17
+ desc "Restart PostgreSQL"
18
+ task :restart, :roles => :db do
19
+ send(run_method, "/etc/init.d/postgresql restart")
20
+ end
21
+
22
+ desc "Reload PostgreSQL"
23
+ task :reload, :roles => :db do
24
+ send(run_method, "/etc/init.d/postgresql reload")
25
+ end
26
+
27
+ end
28
+
29
+ after "deploy:update_code", "postgresql:symlink"
@@ -0,0 +1,12 @@
1
+ # Helper function which prompts for user input, if none selected the returned
2
+ # variable is set to the default.
3
+ # 'prompt' -> user prompt
4
+ # 'var' -> variable
5
+ # 'default' -> default value set if no user input is received.
6
+
7
+ def prompt_with_default(prompt, var, default)
8
+ set(var) do
9
+ Capistrano::CLI.ui.ask "#{prompt} [#{default}]: "
10
+ end
11
+ set var, default if eval("#{var.to_s}.empty?")
12
+ end
@@ -0,0 +1,17 @@
1
+ namespace :rvm do
2
+
3
+ desc "Install rvm"
4
+ task :install, :roles => :web do
5
+ install_deps
6
+
7
+ #~ run "if ! (which rvm); then curl -L http://bit.ly/rvm-install-system-wide | bash; fi"
8
+ run "if ! (rvm list | grep #{rvm_ruby_string}); then rvm install #{rvm_ruby_string}; fi"
9
+ end
10
+
11
+ task :install_deps, :roles => :web do
12
+ yum.install( {:base => %w(curl git gcc-c++ patch readline readline-devel zlib zlib-devel libyaml-devel libffi-devel)}, :stable )
13
+ end
14
+
15
+ end
16
+
17
+ before "deploy:cold", "rvm:install"
@@ -0,0 +1,57 @@
1
+ require File.expand_path('../yum', __FILE__)
2
+
3
+ #
4
+ # Capistrano recipes for cold deployments
5
+ #
6
+ # Usage (add the following to your deploy.rb):
7
+ #
8
+ # load 'recipes/stack'
9
+ # set :gems_for_project, ""
10
+ # ...
11
+ #
12
+ # Then just run "cap deploy:cold" and this stack will hook into it
13
+ #
14
+
15
+ namespace :stack do
16
+
17
+ # Override this if you don't want particular stack items
18
+ desc "Setup operating system and rails environment"
19
+ task :default do
20
+ yum.update
21
+ yum.install( {:base => packages_for_project}, :stable ) if packages_for_project
22
+ gems
23
+
24
+ deploy.setup
25
+ shared.setup
26
+ end
27
+
28
+ desc "Install required gems"
29
+ task :gems do
30
+ run "gem install #{gems_for_project} --no-rdoc --no-ri"
31
+ end
32
+
33
+ end
34
+
35
+ namespace 'shared' do
36
+
37
+ desc "Setup shared directory"
38
+ task :setup do
39
+ sudo "mkdir -p #{deploy_to}/shared/config"
40
+ end
41
+
42
+ desc "Setting proper permissions on shared directory"
43
+ task :permissions do
44
+ run "chown -R apache:apache #{deploy_to}/shared/"
45
+ #~ run "chmod -R 755 #{deploy_to}/shared/"
46
+ # during deployments
47
+ run "if [ -d #{release_path}/ ]; then chown -R apache:apache #{release_path}/; fi"
48
+ run "if [ -d #{release_path}/ ]; then chmod -R 755 #{release_path}/; fi"
49
+ end
50
+
51
+ end
52
+
53
+ #
54
+ # Hooks
55
+ #
56
+ before "deploy:cold", "stack"
57
+ before "deploy:symlink", "shared:permissions"
@@ -0,0 +1,12 @@
1
+ #
2
+ # Updates the crontab using wheneverize
3
+ #
4
+
5
+ after "deploy:symlink", "deploy:update_crontab"
6
+
7
+ namespace :deploy do
8
+ desc "Update the crontab file"
9
+ task :update_crontab, :roles => :db do
10
+ run "cd #{current_path} && bundle exec whenever --update-crontab #{application}"
11
+ end
12
+ end
@@ -0,0 +1,66 @@
1
+ require 'capistrano'
2
+
3
+ # = Purpose
4
+ # yum is a Capistrano plugin module providing a set of methods
5
+ # that invoke the *yum* package manager (as used in Centos)
6
+ #
7
+ # Installs within Capistrano as the plugin _yum_.
8
+ #
9
+ # =Usage
10
+ #
11
+ # require 'recipes/yum'
12
+ #
13
+ # Prefix all calls to the library with <tt>yum.</tt>
14
+ #
15
+ module Yum
16
+
17
+ # Default yum command - reduces any interactivity to the minimum.
18
+ YUM_COMMAND="yum -y"
19
+
20
+ # Run the yum install program across the package list in 'packages'.
21
+ # Select those packages referenced by <tt>:base</tt> and the +version+
22
+ # of the distribution you want to use.
23
+ def install(packages, version, options={})
24
+ special_options = options[:repositories].collect { |repository| " --enablerepo=#{repository}"} if (options && options[:repositories].is_a?(Array))
25
+ send(run_method, %{
26
+ sh -c "#{YUM_COMMAND} #{special_options.to_s} install #{package_list(packages, version)}"
27
+ }, options)
28
+ end
29
+
30
+ # Run a yum clean
31
+ def clean(options={})
32
+ send(run_method, %{sh -c "#{YUM_COMMAND} -qy clean"}, options)
33
+ end
34
+
35
+ # Run a yum autoclean
36
+ def autoclean(options={})
37
+ send(run_method, %{sh -c "#{YUM_COMMAND} -qy autoclean"}, options)
38
+ end
39
+
40
+ # Run a yum distribution upgrade
41
+ def dist_upgrade(options={})
42
+ send(run_method, %{sh -c "#{YUM_COMMAND} -qy dist-upgrade"}, options)
43
+ end
44
+
45
+ # Run a yum upgrade. Use dist_upgrade instead if you want to upgrade
46
+ # the critical base packages.
47
+ def upgrade(options={})
48
+ send(run_method, %{sh -c "#{YUM_COMMAND} -qy upgrade"}, options)
49
+ end
50
+
51
+ # Run a yum update.
52
+ def update(options={})
53
+ send(run_method, %{sh -c "#{YUM_COMMAND} -qy update"}, options)
54
+ end
55
+
56
+ private
57
+
58
+ # Provides a string containing all the package names in the base
59
+ #list plus those in +version+.
60
+ def package_list(packages, version)
61
+ packages[:base].to_a.join(' ') + ' ' + packages[version].to_a.join(' ')
62
+ end
63
+
64
+ end
65
+
66
+ Capistrano.plugin :yum, Yum
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: crossroads_capistrano
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 1
8
+ - 0
9
+ version: 1.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Steve Kenworthy
13
+ - Ben Tillman
14
+ - Nathan Broadbent
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-01-22 00:00:00 +08:00
20
+ default_executable:
21
+ dependencies: []
22
+
23
+ description: A Crossroads Foundation collection of generic capistrano recipes.
24
+ email:
25
+ - it_dept@crossroads.org.hk
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files: []
31
+
32
+ files:
33
+ - .gitignore
34
+ - Gemfile
35
+ - README.textile
36
+ - Rakefile
37
+ - crossroads_capistrano.gemspec
38
+ - lib/crossroads_capistrano.rb
39
+ - lib/crossroads_capistrano/delayed_job.rb
40
+ - lib/crossroads_capistrano/log.rb
41
+ - lib/crossroads_capistrano/newrelic.rb
42
+ - lib/crossroads_capistrano/passenger.rb
43
+ - lib/crossroads_capistrano/postgresql.rb
44
+ - lib/crossroads_capistrano/prompt.rb
45
+ - lib/crossroads_capistrano/rvm.rb
46
+ - lib/crossroads_capistrano/stack.rb
47
+ - lib/crossroads_capistrano/whenever.rb
48
+ - lib/crossroads_capistrano/yum.rb
49
+ has_rdoc: true
50
+ homepage: http://www.crossroads.org.hk
51
+ licenses: []
52
+
53
+ post_install_message:
54
+ rdoc_options: []
55
+
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ requirements: []
75
+
76
+ rubyforge_project: crossroads_capistrano
77
+ rubygems_version: 1.3.7
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: Crossroads capistrano recipes
81
+ test_files: []
82
+