crossroads_capistrano 1.3.0 → 1.3.2

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.
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "crossroads_capistrano"
6
- s.version = "1.3.0"
6
+ s.version = "1.3.2"
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Steve Kenworthy", "Ben Tillman", "Nathan Broadbent"]
9
9
  s.email = ["it_dept@crossroads.org.hk"]
@@ -1,19 +1,27 @@
1
- # crossroads_recipes for using RVM on a server with capistrano.
2
- unless Capistrano::Configuration.respond_to?(:instance)
3
- abort "rvm/capistrano requires Capistrano >= 2."
4
- end
1
+ if defined? Capistrano
2
+ # Crossroads shared capistrano recipes
3
+ require 'capistrano/ext/multistage'
4
+ require 'bundler/capistrano' unless $no_bundler rescue LoadError
5
+ require 'capistrano_colors' rescue LoadError puts "Capistrano Colors is not installed."
6
+
7
+ unless Capistrano::Configuration.respond_to?(:instance)
8
+ abort "rvm/capistrano requires Capistrano >= 2."
9
+ end
10
+
11
+ Capistrano::Configuration.instance(:must_exist).load do
12
+ set :rails_root, Dir.pwd # For tasks that need the root directory
5
13
 
6
- Capistrano::Configuration.instance(:must_exist).load do
7
- def load_crossroads_recipes(recipes)
8
- if recipes == :all
9
- # Load all available crossroads_recipes.
10
- recipes = Dir.glob(File.join(File.dirname(__FILE__),
11
- 'crossroads_capistrano', 'recipes', '*.rb'))
12
- recipes.each{|f| load f}
13
- else
14
- # Load each specified recipe.
15
- recipes.each{|r| load File.join(File.dirname(__FILE__),
16
- "crossroads_capistrano/recipes/#{r}.rb")}
14
+ def load_crossroads_recipes(recipes)
15
+ if recipes == :all
16
+ # Load all available crossroads_recipes.
17
+ recipes = Dir.glob(File.join(File.dirname(__FILE__),
18
+ 'crossroads_capistrano', 'recipes', '*.rb'))
19
+ recipes.each{|f| load f}
20
+ else
21
+ # Load each specified recipe.
22
+ recipes.each{|r| load File.join(File.dirname(__FILE__),
23
+ "crossroads_capistrano/recipes/#{r}.rb")}
24
+ end
17
25
  end
18
26
  end
19
27
  end
@@ -0,0 +1,22 @@
1
+ namespace :cache do
2
+ namespace :clear do
3
+ desc "Clear view cache and memcache but NOT page cache (images/videos). Usually called after a restart."
4
+ task :all do
5
+ view
6
+ memcache
7
+ end
8
+ desc "Clear memcache"
9
+ task :memcache, :only => { :primary => true } do
10
+ run "cd #{current_path} && RAILS_ENV=production rake cache:clear"
11
+ end
12
+ desc "Clear view cache (tmp/cache/) used when memcached is unavailable"
13
+ task :view do
14
+ run "cd #{current_path} && rm -rf tmp/cache/views/"
15
+ end
16
+ desc "Clear page cache (public/en/) used for images and videos"
17
+ task :page do
18
+ run "cd #{current_path} && rm -rf public/en/"
19
+ end
20
+ end
21
+ end
22
+
@@ -1,17 +1,17 @@
1
1
  namespace :delayed_job do
2
2
  desc "Stop the delayed_job process"
3
3
  task :stop, :roles => :app do
4
- run "cd #{current_path}; RAILS_ENV=production script/delayed_job stop"
4
+ run "cd #{current_path}; RAILS_ENV=production bundle exec ./script/delayed_job stop"
5
5
  end
6
6
 
7
7
  desc "Start the delayed_job process"
8
8
  task :start, :roles => :app do
9
- run "cd #{current_path}; RAILS_ENV=production script/delayed_job start"
9
+ run "cd #{current_path}; RAILS_ENV=production bundle exec ./script/delayed_job start"
10
10
  end
11
11
 
12
12
  desc "Restart the delayed_job process"
13
13
  task :restart, :roles => :app do
14
- run "cd #{current_path}; RAILS_ENV=production script/delayed_job restart"
14
+ run "cd #{current_path}; RAILS_ENV=production bundle exec ./script/delayed_job restart"
15
15
  end
16
16
 
17
17
  desc "delayed_job status"
@@ -19,3 +19,4 @@ namespace :delayed_job do
19
19
  run "ps aux | grep 'delayed_job'"
20
20
  end
21
21
  end
22
+
@@ -0,0 +1,34 @@
1
+ # For apps that are deployed with user permissions.
2
+ # ----------------------------------------------------------
3
+
4
+ # Our developers use different users on their local machines.
5
+ set :user, case sysuser = `echo $USER`.strip
6
+ when 'warp' then 'bstillman'
7
+ when 'steve' then 'swkenworthy'
8
+ else sysuser
9
+ end
10
+
11
+ namespace :deploy do
12
+ desc "Deploy permissions (give user access to everything)"
13
+ task :user_permissions do
14
+ sudo "chown -R #{user} #{deploy_to}"
15
+ $apache_permissions = false
16
+ end
17
+ desc "Apache permissions (for passenger)"
18
+ task :apache_permissions do
19
+ unless $apache_permissions
20
+ sudo "chown -R #{httpd_user}:#{httpd_grp} #{current_path}/"
21
+ sudo "chown -R #{httpd_user}:#{httpd_grp} #{deploy_to}/shared/"
22
+ $apache_permissions = true
23
+ end
24
+ end
25
+ end
26
+
27
+ # Set user permissions before running each task, and apache permission when tasks finish.
28
+ (ARGV - %w(preview live)).each do |t|
29
+ before t, "deploy:user_permissions"
30
+ after t, "deploy:apache_permissions"
31
+ end
32
+
33
+ before "deploy:restart", "deploy:apache_permissions"
34
+
@@ -0,0 +1,33 @@
1
+ # Faster deploy:notify_hoptoad (without extra rake task)
2
+ # Sends information about the deploy to Hoptoad.
3
+
4
+ namespace :deploy do
5
+ desc "Notify Hoptoad of the deployment"
6
+ task :notify_hoptoad, :except => { :no_release => true } do
7
+ require 'active_support/core_ext/string' rescue false
8
+ require 'hoptoad_notifier'
9
+ require File.join(rails_root,'config','initializers','hoptoad')
10
+ require 'hoptoad_tasks'
11
+
12
+ rails_env = fetch(:hoptoad_env, fetch(:rails_env, "production"))
13
+ local_user = ENV['USER'] || ENV['USERNAME']
14
+
15
+ puts %Q{
16
+ * \033[0;32m== Notifying Hoptoad of Deploy\033[0m
17
+ - \033[0;33mUser:\033[0m #{local_user}
18
+ - \033[0;33mRails Environment:\033[0m #{rails_env}
19
+ - \033[0;33mRevision:\033[0m #{current_revision}
20
+ - \033[0;33mRepository:\033[0m #{repository}\n\n}
21
+
22
+ HoptoadTasks.deploy(:rails_env => rails_env,
23
+ :scm_revision => current_revision,
24
+ :scm_repository => repository,
25
+ :local_username => local_user)
26
+
27
+ puts "\n Hoptoad Notification Complete.\n\n"
28
+ end
29
+ end
30
+
31
+ after "deploy", "deploy:notify_hoptoad"
32
+ after "deploy:migrations", "deploy:notify_hoptoad"
33
+
@@ -0,0 +1,33 @@
1
+ require File.join(File.dirname(__FILE__), 'prompt')
2
+
3
+ namespace :ldap do
4
+ desc "Create the LDAP configuration file"
5
+ task :config do
6
+ prompt_with_default("LDAP host", :ldap_host, "ldap.crossroadsint.org")
7
+ prompt_with_default("LDAP domain", :ldap_domain, "crossroadsint")
8
+ prompt_with_default("LDAP username", :ldap_bind_username, "ldapuser")
9
+ prompt_with_default("LDAP password", :ldap_bind_password, "")
10
+ prompt_with_default("LDAP search base", :ldap_base_dn, "dc=crossroadsint,dc=org")
11
+ prompt_with_default("LDAP port", :ldap_port, "389")
12
+ ldap_yml = <<-EOF
13
+ host: #{ldap_host}
14
+ port: #{ldap_port}
15
+ domain: #{ldap_domain}
16
+ base: #{ldap_base_dn}
17
+ username: #{ldap_bind_username}
18
+ password: #{ldap_bind_password}
19
+ EOF
20
+
21
+ put ldap_yml, "/tmp/ldap.yml"
22
+ sudo "mv /tmp/ldap.yml #{deploy_to}/shared/config/ldap.yml"
23
+ end
24
+
25
+ task :symlink do
26
+ sudo "ln -sf #{deploy_to}/shared/config/ldap.yml #{release_path}/config/ldap.yml"
27
+ end
28
+
29
+ end
30
+
31
+ before "deploy:cold", "ldap:config"
32
+ after "deploy:update_code", "ldap:symlink"
33
+
@@ -1,12 +1,34 @@
1
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
2
+ namespace :tail do
3
+ desc "Tail Rails production log file"
4
+ task :production, :roles => :app do
5
+ run "tail -f #{shared_path}/log/production.log" do |channel, stream, data|
6
+ puts "\n#{channel[:host]}: #{data}"
7
+ break if stream == :err
8
+ end
9
+ end
10
+ desc "Tail Apache access log file"
11
+ task :access, :roles => :app do
12
+ run "tail -f #{shared_path}/log/access_log" do |channel, stream, data|
13
+ puts "\n#{channel[:host]}: #{data}"
14
+ break if stream == :err
15
+ end
9
16
  end
10
17
  end
11
18
 
19
+ namespace :pull do
20
+ desc "Pull production log file to /tmp/production.log"
21
+ task :production, :roles => :app do
22
+ run "gzip -c #{shared_path}/log/production.log > #{shared_path}/log/production.log.gz"
23
+ `rm -f /tmp/production.log.gz`
24
+ puts "Downloading #{shared_path}/log/production.log...\n"
25
+ download("#{shared_path}/log/production.log.gz", "/tmp/production.log.gz", :via => :scp) do |channel, name, received, total|
26
+ print "\r #{name}: #{(Float(received)/total*100).to_i}% complete..."
27
+ end
28
+ run "rm -f #{shared_path}/log/production.log.gz"
29
+ `gzip -fd /tmp/production.log.gz`
30
+ puts "File can be accessed at /tmp/production.log"
31
+ end
32
+ end
12
33
  end
34
+
@@ -1,5 +1,4 @@
1
1
  namespace :newrelic do
2
-
3
2
  task :default do
4
3
  newrelic.yml
5
4
  end
@@ -8,7 +7,7 @@ namespace :newrelic do
8
7
  task :yml do
9
8
  run "ln -sf #{deploy_to}/shared/config/newrelic.yml #{release_path}/config/newrelic.yml"
10
9
  end
11
-
12
10
  end
13
11
 
14
12
  before "deploy:symlink", "newrelic:yml"
13
+
@@ -13,25 +13,20 @@
13
13
  #
14
14
 
15
15
  namespace :deploy do
16
-
17
16
  %w(start stop restart reload).each do |t|
18
17
  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}"
18
+ task t, :roles => :app, :except => { :no_release => true } do
19
+ sudo "/etc/init.d/httpd #{t}"
21
20
  end
22
21
  end
23
-
24
22
  end
25
23
 
26
24
  namespace :passenger do
27
-
28
25
  desc "Install Passenger"
29
26
  task :install, :roles => :web do
30
27
  install_deps
31
-
32
28
  run "if ! (gem list | grep passenger | grep #{passenger_version}); then gem install passenger --no-rdoc --no-ri --version #{passenger_version} && passenger-install-apache2-module --auto; fi"
33
29
  run "rvm wrapper #{rvm_ruby_string} passenger" if defined?(:rvm_ruby_string) # sets up wrapper for passenger so it can find bundler etc...
34
-
35
30
  end
36
31
 
37
32
  task :install_deps, :roles => :web do
@@ -40,14 +35,21 @@ namespace :passenger do
40
35
 
41
36
  desc "Apache config files: uses special variables @DEPLOY_TO@ @IP_ADDR@ @SERVER_NAME@ @PASSENGER_ROOT@ @RUBY_ROOT@"
42
37
  task :config, :roles => :web do
43
- 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"
44
- passenger_root = capture("pass_path=`gem which phusion_passenger` && echo ${pass_path%/lib/phusion_passenger.rb}")
45
- ruby_root = respond_to?(:rvm_ruby_string) ? "/usr/local/rvm/wrappers/#{rvm_ruby_string}/ruby" : capture("which ruby")
46
- sed_args = "-e 's,@PASSENGER_ROOT@,#{passenger_root.strip},g' -e 's,@RUBY_ROOT@,#{ruby_root.strip},g'"
47
- run "sed #{sed_args} #{release_path}/config/passenger.conf > /etc/httpd/mods-enabled/passenger.conf"
48
- end
38
+ sudo "bash -c \"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\""
39
+
40
+ if respond_to?(:rvm_ruby_string) # Deploying with RVM
41
+ ruby_root = "/usr/local/rvm/wrappers/#{rvm_ruby_string}/ruby"
42
+ passenger_root = "/usr/local/rvm/gems/#{rvm_ruby_string}/gems/passenger-#{passenger_version}"
43
+ else # System Ruby
44
+ ruby_root = capture("which ruby")
45
+ passenger_root = capture("pass_path=`gem which phusion_passenger` && echo ${pass_path%/lib/phusion_passenger.rb}")
46
+ end
47
+ sed_args = "-e 's%@PASSENGER_ROOT@%#{passenger_root.strip}%g' -e 's%@RUBY_ROOT@%#{ruby_root.strip}%g'"
49
48
 
49
+ sudo "bash -c \"sed #{sed_args} #{release_path}/config/passenger.conf > /etc/httpd/mods-enabled/passenger.conf\""
50
+ end
50
51
  end
51
52
 
52
53
  before "deploy:cold", "passenger:install"
53
54
  after "deploy:update_code", "passenger:config"
55
+
@@ -1,5 +1,4 @@
1
1
  namespace :postgresql do
2
-
3
2
  task :symlink do
4
3
  sudo "ln -sf #{deploy_to}/shared/config/database.yml #{release_path}/config/database.yml"
5
4
  end
@@ -23,7 +22,29 @@ namespace :postgresql do
23
22
  task :reload, :roles => :db do
24
23
  send(run_method, "/etc/init.d/postgresql reload")
25
24
  end
25
+ end
26
26
 
27
+ namespace :db do
28
+ desc "Download production database to local machine"
29
+ task :pull do
30
+ prompt_with_default("Database", :dbname, "#{application}_#{default_stage}")
31
+ prompt_with_default("Database user", :username, "postgres")
32
+ prompt_with_default("Local role", :local_role, "postgres")
33
+ prompt_with_default("Overwrite local db? (y/n)", :overwrite, "y")
34
+ host = find_servers(:roles => :db).map(&:to_s).first
35
+ run "pg_dump -U #{username} #{dbname} > /tmp/dump.sql", :hosts => host
36
+ get "/tmp/dump.sql", "tmp/dump.sql", :via => :scp, :hosts => host do |channel, name, received, total|
37
+ print "\r#{name}: #{(Float(received)/total*100).to_i}% complete"
38
+ end
39
+ run "rm -rf /tmp/dump.sql", :hosts => host
40
+ `sed -i s/stockit/#{local_role}/g tmp/dump.sql`
41
+ # Import data.
42
+ if overwrite.to_s.downcase[0,1] == "y"
43
+ `psql -d stockit_development < tmp/dump.sql`
44
+ end
45
+ end
27
46
  end
28
47
 
48
+
29
49
  after "deploy:update_code", "postgresql:symlink"
50
+
@@ -1,9 +1,11 @@
1
+ require 'rvm/capistrano'
2
+
1
3
  namespace :rvm do
2
4
 
3
5
  desc "Install rvm"
4
6
  task :install, :roles => :web do
5
7
  install_deps
6
- run "if ! (which rvm); then curl -s https://rvm.beginrescueend.com/install/rvm | bash; fi", :shell => 'sh'
8
+ run "if ! (which rvm); then bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head ); fi", :shell => 'sh'
7
9
  run "if ! (rvm list | grep #{rvm_ruby_string}); then rvm install #{rvm_ruby_string}; fi", :shell => 'sh'
8
10
  end
9
11
 
@@ -14,3 +16,4 @@ namespace :rvm do
14
16
  end
15
17
 
16
18
  before "deploy:cold", "rvm:install"
19
+
@@ -0,0 +1,49 @@
1
+ namespace :ts do
2
+
3
+ desc "Links the sphinx database files by inserting magic code"
4
+ task :symlink do
5
+ run "sed -i 's,@DEPLOY_TO@,#{deploy_to},g' #{release_path}/script/link_sphinx.rb"
6
+ run "#{release_path}/script/runner -e production #{release_path}/script/link_sphinx.rb"
7
+ end
8
+
9
+ desc "Index data for Sphinx using Thinking Sphinx's settings"
10
+ task :in do
11
+ run "cd #{current_path} && RAILS_ENV=production rake ts:in"
12
+ end
13
+
14
+ desc "Stop sphinx"
15
+ task :stop do
16
+ run "cd #{current_path} && RAILS_ENV=production rake ts:stop"
17
+ end
18
+
19
+ desc "Start sphinx"
20
+ task :start do
21
+ run "cd #{current_path} && RAILS_ENV=production rake ts:start"
22
+ run "chown apache:apache #{deploy_to}/shared/log/searchd.production.pid"
23
+ end
24
+
25
+ desc "Restart sphinx"
26
+ task :restart do
27
+ stop
28
+ start
29
+ end
30
+
31
+ desc "Stop sphinx, delete index files, reindex, and restart sphinx (last resort)"
32
+ task :recover do
33
+ stop
34
+ run "cd #{deploy_to}/shared/db/sphinx/ && rm -rf production"
35
+ run "cd #{current_path} && RAILS_ENV=production rake ts:in"
36
+ start
37
+ end
38
+
39
+ desc """Try to discover if the indexes are corrupted. Checks for index filenames containing 'new'. \
40
+ If they exist then either the files are currently being rotated (after a reindex) or they \
41
+ are stale and need removing with ts:recover. Run this command a few times over a period of \
42
+ a minute to determine if the files disappear - indicating a successfully completed rotation \
43
+ and no need for recovery."""
44
+ task :recovery_required? do
45
+ run "if [ x`find #{deploy_to}/shared/db/sphinx/production/ -name \*.new.\* | wc -l` == x\"0\" ]; then echo \"Sphinx indexes look intact. Run ts:in to regenerate.\"; else echo \"Sphinx index files *may* be stale. Wait 1 minute and run this command again. Consider running ts:recover if this message appears again\"; fi"
46
+ end
47
+
48
+ end
49
+
metadata CHANGED
@@ -1,43 +1,37 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: crossroads_capistrano
3
- version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease: false
6
- segments:
7
- - 1
8
- - 3
9
- - 0
10
- version: 1.3.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.2
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Steve Kenworthy
14
9
  - Ben Tillman
15
10
  - Nathan Broadbent
16
11
  autorequire:
17
12
  bindir: bin
18
13
  cert_chain: []
19
-
20
- date: 2011-05-19 00:00:00 +08:00
14
+ date: 2011-05-19 00:00:00.000000000 +08:00
21
15
  default_executable:
22
16
  dependencies: []
23
-
24
17
  description: A Crossroads Foundation collection of generic capistrano recipes.
25
- email:
18
+ email:
26
19
  - it_dept@crossroads.org.hk
27
20
  executables: []
28
-
29
21
  extensions: []
30
-
31
22
  extra_rdoc_files: []
32
-
33
- files:
23
+ files:
34
24
  - .gitignore
35
25
  - Gemfile
36
26
  - README.textile
37
27
  - Rakefile
38
28
  - crossroads_capistrano.gemspec
39
29
  - lib/crossroads_capistrano.rb
30
+ - lib/crossroads_capistrano/recipes/cache.rb
40
31
  - lib/crossroads_capistrano/recipes/delayed_job.rb
32
+ - lib/crossroads_capistrano/recipes/deploy_permissions.rb
33
+ - lib/crossroads_capistrano/recipes/hoptoad.rb
34
+ - lib/crossroads_capistrano/recipes/ldap.rb
41
35
  - lib/crossroads_capistrano/recipes/log.rb
42
36
  - lib/crossroads_capistrano/recipes/newrelic.rb
43
37
  - lib/crossroads_capistrano/recipes/passenger.rb
@@ -46,41 +40,32 @@ files:
46
40
  - lib/crossroads_capistrano/recipes/revisions.rb
47
41
  - lib/crossroads_capistrano/recipes/rvm.rb
48
42
  - lib/crossroads_capistrano/recipes/stack.rb
43
+ - lib/crossroads_capistrano/recipes/thinking_sphinx.rb
49
44
  - lib/crossroads_capistrano/recipes/whenever.rb
50
45
  - lib/crossroads_capistrano/recipes/yum.rb
51
46
  has_rdoc: true
52
47
  homepage: http://www.crossroads.org.hk
53
48
  licenses: []
54
-
55
49
  post_install_message:
56
50
  rdoc_options: []
57
-
58
- require_paths:
51
+ require_paths:
59
52
  - lib
60
- required_ruby_version: !ruby/object:Gem::Requirement
53
+ required_ruby_version: !ruby/object:Gem::Requirement
61
54
  none: false
62
- requirements:
63
- - - ">="
64
- - !ruby/object:Gem::Version
65
- hash: 3
66
- segments:
67
- - 0
68
- version: "0"
69
- required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
60
  none: false
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
74
- hash: 3
75
- segments:
76
- - 0
77
- version: "0"
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
78
65
  requirements: []
79
-
80
66
  rubyforge_project: crossroads_capistrano
81
- rubygems_version: 1.3.7
67
+ rubygems_version: 1.6.2
82
68
  signing_key:
83
69
  specification_version: 3
84
70
  summary: Crossroads capistrano recipes
85
71
  test_files: []
86
-