dark-capistrano-recipes 0.6.17 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -3,3 +3,5 @@
3
3
  coverage
4
4
  rdoc
5
5
  pkg
6
+ *.gem
7
+
data/README.rdoc CHANGED
@@ -7,11 +7,16 @@ Useful Capistrano recipes including:
7
7
  * Log rotation and tailing commands
8
8
  * Restart and profile Phusion Passenger application server
9
9
  * Configure, start/stop/restart Unicorn application server
10
+ * Send commands to God or Bluepill monitoring tools
11
+ * Send commands to Thinking Sphinx
10
12
 
11
13
  ==Included Tasks
12
14
 
13
15
  * cap db:create_yaml
14
16
  * cap db:mysql:setup
17
+ * cap db:mysql:dump
18
+ * cap db:mysql:fetch_dump
19
+ * cap db:mysql:restore
15
20
  * cap log:rotate
16
21
  * cap log:tail
17
22
  * cap passenger:bounce
@@ -27,6 +32,27 @@ Useful Capistrano recipes including:
27
32
  * cap unicorn:restart
28
33
  * cap unicorn:setup
29
34
  * cap symlinks:make
35
+ * cap god:setup
36
+ * cap god:implode
37
+ * cap god:restart
38
+ * cap god:reload
39
+ * cap god:status
40
+ * cap god:terminate
41
+ * cap god:start
42
+ * cap god:stop
43
+ * cap god:quit
44
+ * cap bluepill:install
45
+ * cap bluepill:init
46
+ * cap bluepill:start
47
+ * cap bluepill:restart
48
+ * cap bluepill:stop
49
+ * cap bluepill:status
50
+ * cap sphinx:config
51
+ * cap sphinx:start
52
+ * cap sphinx:stop
53
+ * cap sphinx:rebuild
54
+ * cap sphinx:index
55
+ * cap sphinx:symlinks
30
56
 
31
57
  ==Installation
32
58
 
@@ -43,7 +69,7 @@ Optionally install the Capistrano extensions gem to give you multistage support:
43
69
  Install this gem:
44
70
 
45
71
  sudo gem install capistrano-recipes --source=http://gemcutter.com
46
-
72
+
47
73
  To setup the initial Capistrano deploy file, go to your Rails app folder via command line and enter:
48
74
 
49
75
  capify .
@@ -52,8 +78,10 @@ To setup the initial Capistrano deploy file, go to your Rails app folder via com
52
78
 
53
79
  Inside the newly created config/deploy.rb, add:
54
80
 
55
- require 'capistrano_recipes'
56
81
  require 'capistrano/ext/multistage' # only require if you've installed Cap ext gem
82
+
83
+ # This one should go at the end of your deploy.rb
84
+ require 'capistrano_recipes'
57
85
 
58
86
  ===RVM
59
87
 
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
- :patch: 17
2
+ :patch: 0
3
3
  :major: 0
4
4
  :build:
5
- :minor: 6
5
+ :minor: 7
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
2
+ # DO NOT EDIT THIS FILE
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dark-capistrano-recipes}
8
- s.version = "0.6.17"
8
+ s.version = "0.7.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Phil Misiowiec", "Leonardo Bighetti"]
12
- s.date = %q{2010-11-30}
12
+ s.date = %q{2011-02-10}
13
13
  s.description = %q{Extend the Capistrano gem with these useful recipes}
14
14
  s.email = %q{leonardobighetti@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
32
32
  "lib/capistrano_recipes.rb",
33
33
  "lib/helpers.rb",
34
34
  "lib/recipes/application.rb",
35
+ "lib/recipes/bluepill.rb",
35
36
  "lib/recipes/bundler.rb",
36
37
  "lib/recipes/db.rb",
37
38
  "lib/recipes/deploy.rb",
@@ -40,18 +41,18 @@ Gem::Specification.new do |s|
40
41
  "lib/recipes/log.rb",
41
42
  "lib/recipes/nginx.rb",
42
43
  "lib/recipes/passenger.rb",
43
- "lib/recipes/rvm.rb",
44
+ "lib/recipes/resque.rb",
45
+ "lib/recipes/sphinx.rb",
44
46
  "lib/recipes/symlinks.rb",
45
47
  "lib/recipes/unicorn.rb"
46
48
  ]
47
49
  s.homepage = %q{http://github.com/darkside/capistrano-recipes}
48
50
  s.rdoc_options = ["--charset=UTF-8"]
49
51
  s.require_paths = ["lib"]
50
- s.rubygems_version = %q{1.3.7}
52
+ s.rubygems_version = %q{1.5.0}
51
53
  s.summary = %q{Darkside's Capistrano recipes}
52
54
 
53
55
  if s.respond_to? :specification_version then
54
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
55
56
  s.specification_version = 3
56
57
 
57
58
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
@@ -66,4 +67,3 @@ Gem::Specification.new do |s|
66
67
  s.add_dependency(%q<capistrano-ext>, [">= 1.2.1"])
67
68
  end
68
69
  end
69
-
@@ -32,10 +32,13 @@
32
32
  }
33
33
 
34
34
  location / {
35
+ <% if is_using_passenger %>
36
+ rails_env <%= rails_env %>;
37
+ passenger_enabled on;
38
+ <% end %>
39
+
35
40
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
36
- #proxy_set_header X-Forwarded-Proto https;
37
41
  proxy_set_header Host $http_host;
38
- #proxy_redirect off;
39
42
 
40
43
  # If the file exists as a static file serve it directly without
41
44
  # running all the other rewite tests on it
@@ -62,28 +65,62 @@
62
65
  rewrite (.*) $1.html break;
63
66
  }
64
67
 
65
-
66
68
  <% if is_using_unicorn %>
67
69
  if (!-f $request_filename) {
68
70
  proxy_pass http://<%= application %>_app_server;
69
71
  break;
70
72
  }
71
73
  <% end %>
72
-
73
74
  }
74
-
75
+
76
+ # Now this supposedly should work as it gets the filenames with querystrings that Rails provides.
77
+ # BUT there's a chance it could break the ajax calls.
78
+ location ~* \.(ico|css|gif|jpe?g|png)(\?[0-9]+)?$ {
79
+ expires max;
80
+ break;
81
+ }
82
+
83
+ location ~ ^/javascripts/.*\.js(\?[0-9]+)?$ {
84
+ expires max;
85
+ break;
86
+ }
87
+
88
+ # Now this supposedly should work as it gets the filenames with querystrings that Rails provides.
89
+ # BUT there's a chance it could break the ajax calls.
90
+ location ~* \.(ico|css|gif|jpe?g|png)(\?[0-9]+)?$ {
91
+ expires max;
92
+ break;
93
+ }
94
+
95
+ location ~ ^/javascripts/.*\.js(\?[0-9]+)?$ {
96
+ expires max;
97
+ break;
98
+ }
99
+
100
+ # if the request is for a static resource, nginx should serve it directly
101
+ # and add a far future expires header to it, making the browser
102
+ # cache the resource and navigate faster over the website
103
+ location ~ ^/(images|javascripts|stylesheets|system)/ {
104
+ root /home/deployer/shop/current/public;
105
+ expires max;
106
+ break;
107
+ }
108
+
75
109
  # Rails error pages
76
110
  error_page 500 502 503 504 /500.html;
77
111
  location = /500.html {
78
112
  root <%= deploy_to %>/current/public;
79
113
  }
80
114
  }
115
+
81
116
  <% if application_uses_ssl %>
117
+
82
118
  <% if is_using_unicorn %>
83
119
  upstream <%= application %>_app_ssl {
84
- server unix:<%= unicorn_socket %> fail_timeout=0;
120
+ server unix:<%= unicorn_socket %> fail_timeout=0;
85
121
  }
86
122
  <% end %>
123
+
87
124
  # This server is setup for ssl. Uncomment if
88
125
  # you are using ssl as well as port 80.
89
126
  server {
@@ -112,6 +149,11 @@
112
149
  }
113
150
 
114
151
  location / {
152
+ <% if is_using_passenger %>
153
+ rails_env <%= rails_env %>;
154
+ passenger_enabled on;
155
+ <% end %>
156
+
115
157
  # needed to forward user's IP address to rails
116
158
  proxy_set_header X-Real-IP $remote_addr;
117
159
 
data/lib/helpers.rb CHANGED
@@ -28,8 +28,8 @@ def is_using_unicorn
28
28
  is_using('unicorn',:app_server)
29
29
  end
30
30
 
31
- def is_using_god
32
- is_using('god',:monitorer)
31
+ def is_app_monitored?
32
+ is_using('bluepill', :monitorer) || is_using('god', :monitorer)
33
33
  end
34
34
 
35
35
  def is_using(something, with_some_var)
@@ -56,12 +56,11 @@ def parse_config(file)
56
56
  return ERB.new(template).result(binding) # parse it
57
57
  end
58
58
 
59
-
60
- # Prompts the user for a message to agree/decline,
61
- #
59
+ # =========================================================================
60
+ # Prompts the user for a message to agree/decline
61
+ # =========================================================================
62
62
  def ask(message, default=true)
63
63
  Capistrano::CLI.ui.agree(message)
64
-
65
64
  end
66
65
 
67
66
  # Generates a configuration file parsing through ERB
@@ -75,8 +74,10 @@ def generate_config(local_file,remote_file)
75
74
  `rm #{temp_file}`
76
75
  end
77
76
 
78
- # Execute a rake task, example:
79
- # run_rake log:clear
77
+ # =========================================================================
78
+ # Executes a basic rake task.
79
+ # Example: run_rake log:clear
80
+ # =========================================================================
80
81
  def run_rake(task)
81
82
  run "cd #{current_path} && rake #{task} RAILS_ENV=#{environment}"
82
- end
83
+ end
@@ -1,22 +1,16 @@
1
- Capistrano::Configuration.instance(:must_exist).load do
2
-
1
+ Capistrano::Configuration.instance.load do
3
2
  # User settings
4
3
  set :user, 'deploy' unless exists?(:user)
5
4
  set :group,'www-data' unless exists?(:group)
6
5
 
7
-
8
6
  # Server settings
9
- set :app_server, :unicorn unless exists?(:app_server)
10
- set :web_server, :nginx unless exists?(:web_server)
11
- set :runner, user unless exists?(:runner)
12
- # The port to listen to, normally we default to 80
13
- set :application_port, 80 unless exists?(:application_port)
14
-
15
- # Are we using ssl as well? Used by generators to configure a ssl host
7
+ set :app_server, :unicorn unless exists?(:app_server)
8
+ set :web_server, :nginx unless exists?(:web_server)
9
+ set :runner, user unless exists?(:runner)
10
+ set :application_port, 80 unless exists?(:application_port)
11
+
16
12
  set :application_uses_ssl, true unless exists?(:application_uses_ssl)
17
-
18
- # The port to listen to https requests, usually 443
19
- set :application_port_ssl, 443 unless exists?(:application_port_ssl)
13
+ set :application_port_ssl, 443 unless exists?(:application_port_ssl)
20
14
 
21
15
  # Database settings
22
16
  set :database, :mysql unless exists?(:database)
@@ -37,8 +31,14 @@ Capistrano::Configuration.instance(:must_exist).load do
37
31
 
38
32
  # RVM settings
39
33
  set :using_rvm, true unless exists?(:using_rvm)
40
- # Sets the rvm to a specific version (or whatever env you want it to run in)
41
- set :rvm_ruby_string, 'ree' unless exists?(:rvm_ruby_string)
34
+
35
+ if using_rvm
36
+ $:.unshift(File.expand_path('./lib', ENV['rvm_path'])) # Add RVM's lib directory to the load path.
37
+ require "rvm/capistrano" # Load RVM's capistrano plugin.
38
+
39
+ # Sets the rvm to a specific version (or whatever env you want it to run in)
40
+ set :rvm_ruby_string, 'ree' unless exists?(:rvm_ruby_string)
41
+ end
42
42
 
43
43
  # Daemons settings
44
44
  # The unix socket that unicorn will be attached to.
@@ -51,10 +51,10 @@ Capistrano::Configuration.instance(:must_exist).load do
51
51
  # a good choice as any.
52
52
  set(:pids_path) { File.join(shared_path, "pids") } unless exists?(:pids_path)
53
53
 
54
- set :monitorer, 'god' unless exists?(:monitorer)
54
+ set :monitorer, 'bluepill' unless exists?(:monitorer)
55
55
 
56
56
  # Application settings
57
- set :shared_dirs, %w( config uploads backup bundle tmp ) unless exists?(:shared_dirs)
57
+ set :shared_dirs, %w(config uploads backup bundle tmp) unless exists?(:shared_dirs)
58
58
 
59
59
  namespace :app do
60
60
  task :setup, :roles => :app do
@@ -0,0 +1,53 @@
1
+ Capistrano::Configuration.instance.load do
2
+ namespace :bluepill do
3
+ desc "|DarkRecipes| Install the bluepill monitoring tool"
4
+ task :install, :roles => [:app] do
5
+ sudo "gem install bluepill"
6
+ end
7
+
8
+ desc "|DarkRecipes| Stop processes that bluepill is monitoring and quit bluepill"
9
+ task :quit, :roles => [:app] do
10
+ args = options || ""
11
+ begin
12
+ sudo "bluepill stop #{args}"
13
+ rescue
14
+ puts "Bluepill was unable to finish gracefully all the process"
15
+ ensure
16
+ sudo "bluepill quit"
17
+ end
18
+ end
19
+
20
+ desc "|DarkRecipes| Load the pill from {your-app}/config/pills/{app-name}.pill"
21
+ task :init, :roles =>[:app] do
22
+ sudo "bluepill load #{current_path}/config/pills/#{application}.pill"
23
+ end
24
+
25
+ desc "|DarkRecipes| Starts your previous stopped pill"
26
+ task :start, :roles =>[:app] do
27
+ args = options || ""
28
+ sudo "bluepill start #{args}"
29
+ end
30
+
31
+ desc "|DarkRecipes| Stops some bluepill monitored process"
32
+ task :stop, :roles =>[:app] do
33
+ args = options || ""
34
+ sudo "bluepill stop #{args}"
35
+ end
36
+
37
+ desc "|DarkRecipes| Restarts the pill from {your-app}/config/pills/{app-name}.pill"
38
+ task :restart, :roles =>[:app] do
39
+ args = options || ""
40
+ sudo "bluepill restart #{args}"
41
+ end
42
+
43
+ desc "|DarkRecipes| Prints bluepills monitored processes statuses"
44
+ task :status, :roles => [:app] do
45
+ args = options || ""
46
+ sudo "bluepill status #{args}"
47
+ end
48
+ end
49
+
50
+ after 'deploy:setup' do
51
+ bluepill.install if Capistrano::CLI.ui.agree("Do you want to install the bluepill monitor? [Yn]")
52
+ end if is_using('bluepill', :monitorer)
53
+ end
@@ -1,19 +1,14 @@
1
- # Bundler
2
- # Manages gems in a sane way.
3
- # http://gembundler.com/
4
- Capistrano::Configuration.instance(:must_exist).load do
1
+ Capistrano::Configuration.instance.load do
5
2
  namespace :bundler do
6
- set :bundler_ver, '1.0.0'
7
- desc "Installs bundler gem to your server"
3
+ desc "|DarkRecipes| Installs bundler gem to your server"
8
4
  task :setup, :roles => :app do
9
- run "if ! gem list | grep --silent -e 'bundler.*#{bundler_ver}'; then #{try_sudo} gem uninstall bundler; #{try_sudo} gem install --no-rdoc --no-ri bundler; fi"
5
+ run "if ! gem list | grep --silent -e 'bundler'; then #{try_sudo} gem uninstall bundler; #{try_sudo} gem install --no-rdoc --no-ri bundler; fi"
10
6
  end
11
7
 
12
- # [internal] runs bundle install on the app server
8
+ desc "|DarkRecipes| Runs bundle install on the app server (internal task)"
13
9
  task :install, :roles => :app, :except => { :no_release => true } do
14
10
  run "cd #{current_path} && bundle install --deployment --without=development test"
15
11
  end
16
- end
17
-
12
+ end
18
13
  end
19
14
 
data/lib/recipes/db.rb CHANGED
@@ -1,32 +1,10 @@
1
1
  require 'erb'
2
2
 
3
- Capistrano::Configuration.instance(:must_exist).load do
3
+ Capistrano::Configuration.instance.load do
4
4
  namespace :db do
5
5
  namespace :mysql do
6
-
7
- # Sets database variables from remote database.yaml
8
- def prepare_from_yaml
9
- set(:db_file) { "#{application}-dump.sql.bz2" }
10
- set(:db_remote_file) { "#{shared_path}/backup/#{db_file}" }
11
- set(:db_local_file) { "tmp/#{db_file}" }
12
- set(:db_user) { db_config[rails_env]["username"] }
13
- set(:db_pass) { db_config[rails_env]["password"] }
14
- set(:db_host) { db_config[rails_env]["host"] }
15
- set(:db_name) { db_config[rails_env]["database"] }
16
- end
17
-
18
- def db_config
19
- @db_config ||= fetch_db_config
20
- end
21
-
22
- def fetch_db_config
23
- require 'yaml'
24
- file = capture "cat #{shared_path}/config/database.yml"
25
- db_config = YAML.load(file)
26
- end
27
-
28
6
  desc <<-EOF
29
- Performs a compressed database dump. \
7
+ |DarkRecipes| Performs a compressed database dump. \
30
8
  WARNING: This locks your tables for the duration of the mysqldump.
31
9
  Don't run it madly!
32
10
  EOF
@@ -38,7 +16,7 @@ Capistrano::Configuration.instance(:must_exist).load do
38
16
  end
39
17
  end
40
18
 
41
- desc "Restores the database from the latest compressed dump"
19
+ desc "|DarkRecipes| Restores the database from the latest compressed dump"
42
20
  task :restore, :roles => :db, :only => { :primary => true } do
43
21
  prepare_from_yaml
44
22
  run "bzcat #{db_remote_file} | mysql --user=#{db_user} -p --host=#{db_host} #{db_name}" do |ch, stream, out|
@@ -47,14 +25,13 @@ Capistrano::Configuration.instance(:must_exist).load do
47
25
  end
48
26
  end
49
27
 
50
- desc "Downloads the compressed database dump to this machine"
28
+ desc "|DarkRecipes| Downloads the compressed database dump to this machine"
51
29
  task :fetch_dump, :roles => :db, :only => { :primary => true } do
52
30
  prepare_from_yaml
53
31
  download db_remote_file, db_local_file, :via => :scp
54
32
  end
55
33
 
56
-
57
- desc "Create MySQL database and user for this environment using prompted values"
34
+ desc "|DarkRecipes| Create MySQL database and user for this environment using prompted values"
58
35
  task :setup, :roles => :db, :only => { :primary => true } do
59
36
  prepare_for_db_command
60
37
 
@@ -69,10 +46,31 @@ Capistrano::Configuration.instance(:must_exist).load do
69
46
  channel.send_data "#{pass}\n"
70
47
  end
71
48
  end
72
- end
49
+ end
50
+
51
+ # Sets database variables from remote database.yaml
52
+ def prepare_from_yaml
53
+ set(:db_file) { "#{application}-dump.sql.bz2" }
54
+ set(:db_remote_file) { "#{shared_path}/backup/#{db_file}" }
55
+ set(:db_local_file) { "tmp/#{db_file}" }
56
+ set(:db_user) { db_config[rails_env]["username"] }
57
+ set(:db_pass) { db_config[rails_env]["password"] }
58
+ set(:db_host) { db_config[rails_env]["host"] }
59
+ set(:db_name) { db_config[rails_env]["database"] }
60
+ end
61
+
62
+ def db_config
63
+ @db_config ||= fetch_db_config
64
+ end
65
+
66
+ def fetch_db_config
67
+ require 'yaml'
68
+ file = capture "cat #{shared_path}/config/database.yml"
69
+ db_config = YAML.load(file)
70
+ end
73
71
  end
74
72
 
75
- desc "Create database.yml in shared path with settings for current stage and test env"
73
+ desc "|DarkRecipes| Create database.yml in shared path with settings for current stage and test env"
76
74
  task :create_yaml do
77
75
  set(:db_user) { Capistrano::CLI.ui.ask "Enter #{environment} database username:" }
78
76
  set(:db_pass) { Capistrano::CLI.password_prompt "Enter #{environment} database password:" }
@@ -109,4 +107,8 @@ Capistrano::Configuration.instance(:must_exist).load do
109
107
  Capistrano::CLI.ui.say "Populating the database..."
110
108
  run "cd #{current_path}; rake RAILS_ENV=#{variables[:rails_env]} db:seed"
111
109
  end
110
+
111
+ after "deploy:setup" do
112
+ db.create_yaml if Capistrano::CLI.ui.agree("Create database.yml in app's shared path? [Yn]")
113
+ end
112
114
  end
@@ -1,65 +1,61 @@
1
- Capistrano::Configuration.instance(:must_exist).load do
1
+ Capistrano::Configuration.instance.load do
2
2
  set :shared_children, %w(system log pids config)
3
-
4
- after "deploy:setup" do
5
- db.create_yaml if Capistrano::CLI.ui.agree("Create database.yml in app's shared path? [Yn]")
6
- end
7
-
8
3
 
9
4
  namespace :deploy do
10
- desc "Deploy it, github-style."
5
+ desc "|DarkRecipes| Deploy it, github-style."
11
6
  task :default, :roles => :app, :except => { :no_release => true } do
12
7
  update
13
8
  restart
14
9
  end
15
10
 
16
- desc "[Seppuku] Destroy everything"
11
+ desc "|DarkRecipes| Destroys everything"
17
12
  task :seppuku, :roles => :app, :except => { :no_release => true } do
18
13
  run "rm -rf #{current_path}; rm -rf #{shared_path}"
19
- rubycas.seppuku
20
14
  end
21
15
 
22
- task :setup_dirs, :roles => :app, :except => { :no_release => true } do
16
+ desc "|DarkRecipes| Create shared dirs"
17
+ task :setup_dirs, :roles => :app, :except => { :no_release => true } do
23
18
  commands = shared_dirs.map do |path|
24
19
  "mkdir -p #{shared_path}/#{path}"
25
20
  end
26
21
  run commands.join(" && ")
27
22
  end
28
23
 
29
- desc "Uploads your local config.yml to the server"
24
+ desc "|DarkRecipes| Uploads your local config.yml to the server"
30
25
  task :configure, :roles => :app, :except => { :no_release => true } do
31
26
  generate_config('config/config.yml', "#{shared_path}/config/config.yml")
32
27
  end
33
28
 
34
- desc "Setup a GitHub-style deployment."
29
+ desc "|DarkRecipes| Setup a GitHub-style deployment."
35
30
  task :setup, :roles => :app, :except => { :no_release => true } do
36
31
  run "rm -rf #{current_path}"
37
32
  setup_dirs
38
33
  run "git clone #{repository} #{current_path}"
39
34
  end
40
35
 
41
- desc "Update the deployed code."
36
+ desc "|DarkRecipes| Update the deployed code."
42
37
  task :update_code, :roles => :app, :except => { :no_release => true } do
43
38
  run "cd #{current_path}; git fetch origin; git reset --hard #{branch}"
44
39
  end
45
40
 
41
+ desc "|DarkRecipes| Alias for symlinks:make"
46
42
  task :symlink, :roles => :app, :except => { :no_release => true } do
47
43
  symlinks.make
48
44
  end
49
45
 
50
- desc "Deploys and runs any pending migrations"
46
+ desc "|DarkRecipes| Remote run for rake db:migrate"
51
47
  task :migrate, :roles => :app, :except => { :no_release => true } do
52
48
  run "cd #{current_path}; bundle exec rake RAILS_ENV=#{rails_env} db:migrate"
53
49
  end
54
50
 
55
- desc "[Obsolete] Nothing to cleanup when using reset --hard on git"
51
+ desc "|DarkRecipes| [Obsolete] Nothing to cleanup when using reset --hard on git"
56
52
  task :cleanup, :roles => :app, :except => { :no_release => true } do
57
53
  #nothing to cleanup, we're not working with 'releases'
58
54
  puts "Nothing to cleanup, yay!"
59
55
  end
60
56
 
61
57
  namespace :rollback do
62
- desc "Rollback , :except => { :no_release => true }a single commit."
58
+ desc "|DarkRecipes| Rollback , :except => { :no_release => true }a single commit."
63
59
  task :default, :roles => :app, :except => { :no_release => true } do
64
60
  set :branch, "HEAD^"
65
61
  deploy.default
@@ -67,7 +63,7 @@ Capistrano::Configuration.instance(:must_exist).load do
67
63
  end
68
64
 
69
65
  desc <<-DESC
70
- Restarts your application. This depends heavily on what server you're running.
66
+ |DarkRecipes| Restarts your application. This depends heavily on what server you're running.
71
67
  If you are running Phusion Passenger, you can explicitly set the server type:
72
68
 
73
69
  set :server, :passenger
@@ -87,12 +83,12 @@ Capistrano::Configuration.instance(:must_exist).load do
87
83
 
88
84
  set :server, :unicorn
89
85
 
90
- By default, this will be invoked via sudo as the `app' user. If \
86
+ By default, this will be |DarkRecipes| d via sudo as the `app' user. If \
91
87
  you wish to run it as a different user, set the :runner variable to \
92
88
  that user. If you are in an environment where you can't use sudo, set \
93
89
  the :use_sudo variable to false:
94
90
 
95
- set :use_sudo, false
91
+ set :use_sudo, false
96
92
  DESC
97
93
  task :restart, :roles => :app, :except => { :no_release => true } do
98
94
  if exists?(:app_server)
@@ -100,7 +96,7 @@ Capistrano::Configuration.instance(:must_exist).load do
100
96
  when 'passenger'
101
97
  passenger.bounce
102
98
  when 'unicorn'
103
- is_using_god ? god.restart.app : unicorn.restart
99
+ is_using('god', :monitorer) ? god.restart.app : unicorn.restart
104
100
  end
105
101
  else
106
102
  puts "Dunno how to restart your internets! kthx!"
data/lib/recipes/god.rb CHANGED
@@ -2,13 +2,13 @@
2
2
  # God is a Process Monitoring Framework written in Ruby
3
3
  # More info at http://god.rubyforge.org/
4
4
  #------------------------------------------------------------------------------
5
- Capistrano::Configuration.instance(:must_exist).load do
5
+ Capistrano::Configuration.instance.load do
6
6
  _cset(:god_local_config) { "#{templates_path}/app.god.erb" }
7
7
  _cset(:god_remote_config) { "#{shared_path}/config/app.god" }
8
8
 
9
9
  namespace :god do
10
10
 
11
- desc "Parses and uploads god configuration for this app"
11
+ desc "|DarkRecipes| Parses and uploads god configuration for this app"
12
12
  task :setup, :roles => :app do
13
13
  generate_config(god_local_config, god_remote_config)
14
14
  end
@@ -25,7 +25,6 @@ Capistrano::Configuration.instance(:must_exist).load do
25
25
  _cset :god_conf_temp, '/tmp/god.conf'
26
26
  _cset :god_conf_remote, '/etc/god/god.conf'
27
27
 
28
-
29
28
  task :setup_temp, :roles => :app do
30
29
  sudo "rm -f #{god_conf_remote} #{god_init_remote} #{god_defo_remote}"
31
30
  end
@@ -50,7 +49,7 @@ Capistrano::Configuration.instance(:must_exist).load do
50
49
  sudo "mv #{god_defo_temp} #{god_defo_remote}"
51
50
  end
52
51
 
53
- desc "Bootstraps god on your server. Be careful with this."
52
+ desc "|DarkRecipes| Bootstraps god on your server. Be careful with this."
54
53
  task :bootstrap, :roles => :app do
55
54
  setup_temp
56
55
  setup_defo
@@ -60,7 +59,7 @@ Capistrano::Configuration.instance(:must_exist).load do
60
59
  puts "God is bootstrapped. To remove use 'cap god:implode'"
61
60
  end
62
61
 
63
- desc "(Seppuku) Completely remove god from the system init"
62
+ desc "|DarkRecipes| (Seppuku) Completely remove god from the system init"
64
63
  task :implode, :roles => :app do
65
64
  # Removing any system startup links for /etc/init.d/god ...
66
65
  sudo "update-rc.d -f god remove"
@@ -72,54 +71,55 @@ Capistrano::Configuration.instance(:must_exist).load do
72
71
  puts "God is no more."
73
72
  end
74
73
 
75
- desc "Restarts everything"
74
+ desc "|DarkRecipes| Use god to restart the app"
76
75
  namespace :restart do
77
76
  task :default, :roles => :app, :except => { :no_release => true } do
78
77
  sudo "#{bin_god} restart #{application}"
79
78
  end
80
-
81
- desc "Restarts the app server"
79
+
80
+ desc "|DarkRecipes| Restarts the app server"
82
81
  task :app, :roles => :app, :except => { :no_release => true } do
83
82
  sudo "#{bin_god} restart #{application}-#{app_server.to_s.downcase}"
84
83
  end
85
84
  end
86
85
 
87
- desc "Fetches the log for the whole group"
86
+ desc "|DarkRecipes| Fetches the log for the whole group"
88
87
  task :log, :roles => :app do
89
88
  sudo "#{bin_god} log #{application}"
90
89
  end
91
90
 
92
- desc "Reload config"
91
+ desc "|DarkRecipes| Reload config"
93
92
  task :reload, :roles => :app do
94
93
  sudo "#{bin_god} load #{god_remote_config}"
95
94
  end
96
95
 
97
- desc "Start god service"
96
+ desc "|DarkRecipes| Start god service"
98
97
  task :start, :roles => :app do
99
98
  sudo "service god start"
100
99
  end
101
100
 
102
- desc "Stops god service"
101
+ desc "|DarkRecipes| Stops god service"
103
102
  task :stop, :roles => :app do
104
103
  sudo "service god stop"
105
104
  end
106
105
 
107
- desc "Quit god, but not the processes it's monitoring"
106
+ desc "|DarkRecipes| Quit god, but not the processes it's monitoring"
108
107
  task :quit, :roles => :app do
109
108
  sudo "#{bin_god} quit"
110
109
  end
111
110
 
112
- desc "Terminate god and all monitored processes"
111
+ desc "|DarkRecipes| Terminate god and all monitored processes"
113
112
  task :terminate, :roles => :app do
114
113
  sudo "#{bin_god} terminate"
115
114
  end
116
115
 
117
- desc "Describe the status of the running tasks"
116
+ desc "|DarkRecipes| Describe the status of the running tasks"
118
117
  task :status, :roles => :app do
119
118
  sudo "#{bin_god} status"
120
119
  end
121
120
  end
121
+
122
122
  after 'deploy:setup' do
123
123
  god.setup if Capistrano::CLI.ui.agree("Create app.god in app's shared path? [Yn]")
124
- end if is_using_god
124
+ end if is_using('god', :monitorer)
125
125
  end
data/lib/recipes/hooks.rb CHANGED
@@ -1,14 +1,13 @@
1
1
  # Common hooks for all scenarios.
2
- Capistrano::Configuration.instance(:must_exist).load do
2
+ Capistrano::Configuration.instance.load do
3
3
  after 'deploy:setup' do
4
4
  app.setup
5
- bundler.setup
5
+ bundler.setup if Capistrano::CLI.ui.agree("Do you need to install the bundler gem? [Yn]")
6
6
  end
7
7
 
8
8
  after "deploy:update_code" do
9
9
  symlinks.make
10
10
  bundler.install
11
- deploy.cleanup
12
11
  end
13
12
  end
14
13
 
data/lib/recipes/log.rb CHANGED
@@ -1,6 +1,6 @@
1
- Capistrano::Configuration.instance(:must_exist).load do
1
+ Capistrano::Configuration.instance.load do
2
2
  namespace :log do
3
- desc "Tail all application log files"
3
+ desc "|DarkRecipes| Tail all application log files"
4
4
  task :tail, :roles => :app do
5
5
  run "tail -f #{shared_path}/log/*.log" do |channel, stream, data|
6
6
  puts "#{channel[:host]}: #{data}"
@@ -9,7 +9,7 @@ Capistrano::Configuration.instance(:must_exist).load do
9
9
  end
10
10
 
11
11
  desc <<-DESC
12
- Install log rotation script; optional args: days=7, size=5M, group (defaults to same value as :user)
12
+ |DarkRecipes| Install log rotation script; optional args: days=7, size=5M, group (defaults to same value as :user)
13
13
  DESC
14
14
  task :rotate, :roles => :app do
15
15
  rotate_script = %Q{#{shared_path}/log/#{environment}.log {
data/lib/recipes/nginx.rb CHANGED
@@ -1,7 +1,6 @@
1
- Capistrano::Configuration.instance(:must_exist).load do
1
+ Capistrano::Configuration.instance.load do
2
2
 
3
- # Where your nginx lives. Usually /opt/nginx or /usr/local/nginx for source
4
- # compiled.
3
+ # Where your nginx lives. Usually /opt/nginx or /usr/local/nginx for source compiled.
5
4
  set :nginx_path_prefix, "/opt/nginx" unless exists?(:nginx_path_prefix)
6
5
 
7
6
  # Path to the nginx erb template to be parsed before uploading to remote
@@ -15,42 +14,39 @@ Capistrano::Configuration.instance(:must_exist).load do
15
14
  # Nginx tasks are not *nix agnostic, they assume you're using Debian/Ubuntu.
16
15
  # Override them as needed.
17
16
  namespace :nginx do
18
-
19
- desc "Parses and uploads nginx configuration for this app."
17
+ desc "|DarkRecipes| Parses and uploads nginx configuration for this app."
20
18
  task :setup, :roles => :app , :except => { :no_release => true } do
21
19
  generate_config(nginx_local_config, nginx_remote_config)
22
20
  end
23
21
 
24
- # [internal] Parses config file and outputs it to STDOUT
22
+ desc "|DarkRecipes| Parses config file and outputs it to STDOUT (internal task)"
25
23
  task :parse, :roles => :app , :except => { :no_release => true } do
26
24
  puts parse_config(nginx_local_config)
27
25
  end
28
26
 
29
- desc "Restart nginx"
27
+ desc "|DarkRecipes| Restart nginx"
30
28
  task :restart, :roles => :app , :except => { :no_release => true } do
31
29
  sudo "service nginx restart"
32
30
  end
33
31
 
34
- desc "Stop nginx"
32
+ desc "|DarkRecipes| Stop nginx"
35
33
  task :stop, :roles => :app , :except => { :no_release => true } do
36
34
  sudo "service nginx stop"
37
35
  end
38
36
 
39
- desc "Start nginx"
37
+ desc "|DarkRecipes| Start nginx"
40
38
  task :start, :roles => :app , :except => { :no_release => true } do
41
39
  sudo "service nginx start"
42
40
  end
43
41
 
44
- desc "Show nginx status"
42
+ desc "|DarkRecipes| Show nginx status"
45
43
  task :status, :roles => :app , :except => { :no_release => true } do
46
44
  sudo "service nginx status"
47
45
  end
48
-
49
46
  end
50
47
 
51
48
  after 'deploy:setup' do
52
49
  nginx.setup if Capistrano::CLI.ui.agree("Create nginx configuration file? [Yn]")
53
- end if is_using_nginx
54
-
50
+ end if is_using_nginx
55
51
  end
56
52
 
@@ -1,18 +1,18 @@
1
- Capistrano::Configuration.instance(:must_exist).load do
1
+ Capistrano::Configuration.instance.load do
2
2
  namespace :passenger do
3
- desc "Restart Rails app running under Phusion Passenger by touching restart.txt"
3
+ desc "|DarkRecipes| Restart Rails app running under Phusion Passenger by touching restart.txt"
4
4
  task :bounce, :roles => :app do
5
5
  run "#{sudo} touch #{current_path}/tmp/restart.txt"
6
6
  end
7
7
 
8
- desc "Inspect Phusion Passenger's memory usage. Assumes binaries are located in /opt/ruby-enterprise."
8
+ desc "|DarkRecipes| Inspect Phusion Passenger's memory usage."
9
9
  task :memory, :roles => :app do
10
- run "#{sudo} /opt/ruby-enterprise/bin/passenger-memory-stats"
10
+ run "sudo passenger-memory-stats"
11
11
  end
12
12
 
13
- desc "Inspect Phusion Passenger's internal status. Assumes binaries are located in /opt/ruby-enterprise."
13
+ desc "|DarkRecipes| Inspect Phusion Passenger's internal status."
14
14
  task :status, :roles => :app do
15
- run "#{sudo} /opt/ruby-enterprise/bin/passenger-status"
15
+ run "sudo passenger-status"
16
16
  end
17
17
  end
18
18
  end
@@ -0,0 +1,48 @@
1
+ Capistrano::Configuration.instance.load do
2
+ namespace :resque do
3
+ namespace :worker do
4
+ desc "|DarkRecipes| List all workers"
5
+ task :list, :roles => :app do
6
+ run "cd #{current_path} && #{sudo} resque list"
7
+ end
8
+
9
+ desc "|DarkRecipes| Starts the workers"
10
+ task :start, :roles => :app do
11
+ run "cd #{current_path} && #{sudo} god start #{resque_service}"
12
+ end
13
+
14
+ desc "|DarkRecipes| Stops the workers"
15
+ task :stop, :roles => :app do
16
+ run "cd #{current_path} && #{sudo} god stop #{resque_service}"
17
+ end
18
+
19
+ desc "|DarkRecipes| Restart all workers"
20
+ task :restart, :roles => :app do
21
+ run "cd #{current_path} && #{sudo} god restart #{resque_service}"
22
+ end
23
+ end
24
+
25
+ namespace :web do
26
+ desc "|DarkRecipes| Starts the resque web interface"
27
+ task :start, :roles => :app do
28
+ run "cd #{current_path}; resque-web -p 9000 -e #{rails_env} "
29
+ end
30
+
31
+ desc "|DarkRecipes| Stops the resque web interface"
32
+ task :stop, :roles => :app do
33
+ run "cd #{current_path}; resque-web -K"
34
+ end
35
+
36
+ desc "|DarkRecipes| Restarts the resque web interface "
37
+ task :restart, :roles => :app do
38
+ stop
39
+ start
40
+ end
41
+
42
+ desc "|DarkRecipes| Shows the status of the resque web interface"
43
+ task :status, :roles => :app do
44
+ run "cd #{current_path}; resque-web -S"
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,39 @@
1
+ Capistrano::Configuration.instance.load do
2
+ namespace :sphinx do
3
+ desc "|DarkRecipes| Generates Configuration file for TS"
4
+ task :config, :roles => :app do
5
+ run "cd #{current_path}; #{rake_bin} RAILS_ENV=#{rails_env} ts:config"
6
+ end
7
+
8
+ desc "|DarkRecipes| Starts TS"
9
+ task :start, :roles => :app do
10
+ run "cd #{current_path}; #{rake_bin} RAILS_ENV=#{rails_env} ts:start"
11
+ end
12
+
13
+ desc "|DarkRecipes| Stops TS"
14
+ task :stop, :roles => :app do
15
+ run "cd #{current_path}; #{rake_bin} RAILS_ENV=#{rails_env} ts:stop"
16
+ end
17
+
18
+ desc "|DarkRecipes| Rebuild TS"
19
+ task :rebuild, :roles => :app do
20
+ run "cd #{current_path}; #{rake_bin} RAILS_ENV=#{rails_env} ts:rebuild"
21
+ end
22
+
23
+ desc "|DarkRecipes| Indexes TS"
24
+ task :index, :roles => :app do
25
+ run "cd #{current_path}; #{rake_bin} RAILS_ENV=#{rails_env} ts:in"
26
+ end
27
+
28
+ desc "|DarkRecipes| Re-establishes symlinks"
29
+ task :symlinks do
30
+ run <<-CMD
31
+ rm -rf #{current_path}/db/sphinx && ln -nfs #{shared_path}/db/sphinx #{current_path}/db/sphinx
32
+ CMD
33
+ end
34
+ end
35
+
36
+ after "deploy:migrate" do
37
+ sphinx.rebuild
38
+ end unless is_app_monitored?
39
+ end
@@ -1,19 +1,13 @@
1
- Capistrano::Configuration.instance(:must_exist).load do
1
+ Capistrano::Configuration.instance.load do
2
2
  # These are set to the same structure in shared <=> current
3
- set :normal_symlinks, %w(
4
- tmp
5
- log
6
- config/database.yml
7
- ) unless exists?(:normal_symlinks)
3
+ set :normal_symlinks, %w(tmp log config/database.yml) unless exists?(:normal_symlinks)
8
4
 
9
5
  # Weird symlinks go somewhere else. Weird.
10
- set :weird_symlinks, {
11
- 'bundle' => 'vendor/bundle',
12
- 'pids' => 'tmp/pids'
13
- } unless exists?(:weird_symlinks)
6
+ set :weird_symlinks, { 'bundle' => 'vendor/bundle',
7
+ 'pids' => 'tmp/pids' } unless exists?(:weird_symlinks)
14
8
 
15
9
  namespace :symlinks do
16
- desc "Make all the damn symlinks in a single run"
10
+ desc "|DarkRecipes| Make all the symlinks in a single run"
17
11
  task :make, :roles => :app, :except => { :no_release => true } do
18
12
  commands = normal_symlinks.map do |path|
19
13
  "rm -rf #{current_path}/#{path} && \
@@ -25,12 +19,9 @@ Capistrano::Configuration.instance(:must_exist).load do
25
19
  ln -s #{shared_path}/#{from} #{current_path}/#{to}"
26
20
  end
27
21
 
28
-
29
22
  run <<-CMD
30
- cd #{current_path} &&
31
- #{commands.join(" && ")}
23
+ cd #{current_path} && #{commands.join(" && ")}
32
24
  CMD
33
25
  end
34
26
  end
35
-
36
27
  end
@@ -1,4 +1,4 @@
1
- Capistrano::Configuration.instance(:must_exist).load do
1
+ Capistrano::Configuration.instance.load do
2
2
  # Number of workers (Rule of thumb is 2 per CPU)
3
3
  # Just be aware that every worker needs to cache all classes and thus eat some
4
4
  # of your RAM.
@@ -15,15 +15,12 @@ Capistrano::Configuration.instance(:must_exist).load do
15
15
 
16
16
  # The wrapped bin to start unicorn
17
17
  # This is necessary if you're using rvm
18
- set :unicorn_bin, 'unicorn_rails' unless exists?(:unicorn_bin)
19
-
20
-
18
+ set :unicorn_bin, 'bundle exec unicorn' unless exists?(:unicorn_bin)
21
19
  set :unicorn_socket, File.join(sockets_path,'unicorn.sock') unless exists?(:unicorn_socket)
22
20
 
23
21
  # Defines where the unicorn pid will live.
24
22
  set(:unicorn_pid) { File.join(pids_path, "unicorn.pid") } unless exists?(:unicorn_pid)
25
23
 
26
-
27
24
  # Our unicorn template to be parsed by erb
28
25
  # You may need to generate this file the first time with the generator
29
26
  # included in the gem
@@ -47,30 +44,34 @@ Capistrano::Configuration.instance(:must_exist).load do
47
44
  # Unicorn
48
45
  #------------------------------------------------------------------------------
49
46
  namespace :unicorn do
50
- desc "Starts unicorn directly"
47
+ desc "|DarkRecipes| Starts unicorn directly"
51
48
  task :start, :roles => :app do
52
49
  run unicorn_start_cmd
53
50
  end
54
51
 
55
- desc "Stops unicorn directly"
52
+ desc "|DarkRecipes| Stops unicorn directly"
56
53
  task :stop, :roles => :app do
57
54
  run unicorn_stop_cmd
58
55
  end
59
56
 
60
- desc "Restarts unicorn directly"
57
+ desc "||DarkRecipes|| Restarts unicorn directly"
61
58
  task :restart, :roles => :app do
62
59
  run unicorn_restart_cmd
63
60
  end
64
61
 
65
62
  desc <<-EOF
66
- Parses the configuration file through ERB to fetch our variables and \
63
+ |DarkRecipes| Parses the configuration file through ERB to fetch our variables and \
67
64
  uploads the result to #{unicorn_remote_config}, to be loaded by whoever is booting \
68
65
  up the unicorn.
69
66
  EOF
70
67
  task :setup, :roles => :app , :except => { :no_release => true } do
71
68
  # TODO: refactor this to a more generic setup task once we have more socket tasks.
72
- run "#{try_sudo} mkdir -p #{sockets_path}"
73
- run "#{try_sudo} chown #{user}:#{group} #{sockets_path} -R"
69
+ commands = []
70
+ commands << "mkdir -p #{sockets_path}"
71
+ commands << "chown #{user}:#{group} #{sockets_path} -R"
72
+ commands << "chmod +rw #{sockets_path}"
73
+
74
+ run commands.join(" && ")
74
75
  generate_config(unicorn_local_config,unicorn_remote_config)
75
76
  end
76
77
  end
@@ -78,6 +79,4 @@ Capistrano::Configuration.instance(:must_exist).load do
78
79
  after 'deploy:setup' do
79
80
  unicorn.setup if Capistrano::CLI.ui.agree("Create unicorn configuration file? [Yn]")
80
81
  end if is_using_unicorn
81
-
82
82
  end
83
-
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dark-capistrano-recipes
3
3
  version: !ruby/object:Gem::Version
4
- hash: 37
5
- prerelease: false
4
+ hash: 3
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 6
9
- - 17
10
- version: 0.6.17
8
+ - 7
9
+ - 0
10
+ version: 0.7.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Phil Misiowiec
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-11-30 00:00:00 -02:00
19
+ date: 2011-02-10 00:00:00 -02:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -76,6 +76,7 @@ files:
76
76
  - lib/capistrano_recipes.rb
77
77
  - lib/helpers.rb
78
78
  - lib/recipes/application.rb
79
+ - lib/recipes/bluepill.rb
79
80
  - lib/recipes/bundler.rb
80
81
  - lib/recipes/db.rb
81
82
  - lib/recipes/deploy.rb
@@ -84,7 +85,8 @@ files:
84
85
  - lib/recipes/log.rb
85
86
  - lib/recipes/nginx.rb
86
87
  - lib/recipes/passenger.rb
87
- - lib/recipes/rvm.rb
88
+ - lib/recipes/resque.rb
89
+ - lib/recipes/sphinx.rb
88
90
  - lib/recipes/symlinks.rb
89
91
  - lib/recipes/unicorn.rb
90
92
  has_rdoc: true
@@ -117,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
119
  requirements: []
118
120
 
119
121
  rubyforge_project:
120
- rubygems_version: 1.3.7
122
+ rubygems_version: 1.5.0
121
123
  signing_key:
122
124
  specification_version: 3
123
125
  summary: Darkside's Capistrano recipes
data/lib/recipes/rvm.rb DELETED
@@ -1,11 +0,0 @@
1
- # RVM jazz
2
- #------------------------------------------------------------------------------
3
- Capistrano::Configuration.instance(:must_exist).load do
4
- if defined?(using_rvm) && using_rvm
5
- # Add RVM's lib directory to the load path.
6
- $:.unshift(File.expand_path('./lib', ENV['rvm_path']))
7
-
8
- # Load RVM's capistrano plugin.
9
- require "rvm/capistrano"
10
- end
11
- end