cap-recipes 0.3.26 → 0.3.27

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -3,13 +3,14 @@ h1. cap-recipes
3
3
  A collection of useful capistrano recipes I have been using in production on a number of sites.
4
4
 
5
5
  This gem is best suited for ruby (and rails) projects which deploy using Apache and Phusion Passenger.
6
- Worth noting is that the installation tasks are for linux distributions using apt-get packages.
7
- Feel free to contribute to this collection and make it even better!
6
+ Worth noting is that the installation tasks are for systems using aptitude package management.
8
7
 
9
8
  The overall vision for this project is simply to collect a number of classic, generic recipes
10
- for common issues which can then be used by the community.
9
+ for common issues which can then be used by the community.
11
10
 
12
- Currently included:
11
+ Feel free to improve upon this recipe collection by adding your own!
12
+
13
+ Currently included recipes in this gem:
13
14
 
14
15
  * Ruby Setup
15
16
  * Rubygems Management
@@ -43,7 +44,7 @@ Then, include into your @deploy.rb@ configuration file for Capistrano:
43
44
  # tasks for managing and tasks for installing):
44
45
  require 'cap_recipes/tasks/memcache'
45
46
  require 'cap_recipes/tasks/passenger'
46
- # or rails, apache, rubygems, delayed_job, juggernaut, backgroundrb, aptitude, whenever
47
+ # or ruby, rubygems, rails, apache, delayed_job, juggernaut, backgroundrb, aptitude, whenever
47
48
 
48
49
  # OR
49
50
  # only use managing tasks:
@@ -69,13 +70,13 @@ h4. Configuration
69
70
 
70
71
  h4. Tasks
71
72
 
72
- h5. manage.rb
73
+ manage.rb
73
74
 
74
75
  * apache:stop - stops the apache server
75
76
  * apache:start - starts the apache server
76
77
  * apache:restart - restarts the apache server
77
78
 
78
- h5. install.rb
79
+ install.rb
79
80
 
80
81
  * apache:install - installs apache and dependencies onto a debian system
81
82
 
@@ -87,7 +88,7 @@ h4. Configuration
87
88
 
88
89
  h4. Tasks
89
90
 
90
- h5. install.rb
91
+ install.rb
91
92
 
92
93
  * ruby:setup - Installs ruby 1.8 using standard aptitude packages
93
94
 
@@ -100,7 +101,7 @@ h4. Configuration
100
101
 
101
102
  h4. Tasks
102
103
 
103
- h5. manage.rb
104
+ manage.rb
104
105
 
105
106
  * rubygems:full_update - Upgrades rubygems, updates all installed rubygems and performs a cleanup
106
107
  * rubygems:upgrade - Upgrades rubygems version (if available)
@@ -109,7 +110,7 @@ h5. manage.rb
109
110
  * rubygems:install - Installs a specifed gem from name inputted on console
110
111
  * rubygems:uninstall - Removes a specified rubygem from name inputted on console
111
112
 
112
- h5. install.rb
113
+ install.rb
113
114
 
114
115
  * rubygems:install - Installs rubygems by downloading package and running setup.rb
115
116
 
@@ -130,13 +131,13 @@ The following files and folders are expected to exist:
130
131
 
131
132
  h4. Tasks
132
133
 
133
- h5. manage.rb
134
+ manage.rb
134
135
 
135
136
  * deploy:start - Starts the apache server (if needed)
136
137
  * deploy:stop - Stops the apache server (if needed)
137
138
  * deploy:restart - Touches the restart.txt file
138
139
 
139
- h5. install.rb
140
+ install.rb
140
141
 
141
142
  * passenger:install - Installs the passenger gem, compiles the module silently, and adds the necessary configuration
142
143
 
@@ -144,7 +145,7 @@ h3. Aptitude
144
145
 
145
146
  h4. Tasks
146
147
 
147
- h5. manage.rb
148
+ manage.rb
148
149
 
149
150
  * aptitude:install - Installs a specified aptitude package from name inputted on console
150
151
  * aptitude:remove - Removes a specified aptitude package from name inputted on console
@@ -156,7 +157,7 @@ These recipes support rails-specific functionality
156
157
 
157
158
  h4. Tasks
158
159
 
159
- h5. manage.rb
160
+ manage.rb
160
161
 
161
162
  * rails:symlink_db_config - Symlinks the database.yml file from shared/config to release path
162
163
  * rails:repair_permissions - Forces the permissions on the rails app to make permission errors a thing of the past
@@ -165,7 +166,7 @@ h5. manage.rb
165
166
  * rails:sweep:cache - performs a file cache sweep in production
166
167
  * rails:sweep:log - performs a log sweep in production
167
168
 
168
- h5. hooks.rb
169
+ hooks.rb
169
170
 
170
171
  <pre>
171
172
  <code>
@@ -187,13 +188,13 @@ h4. Configuration
187
188
 
188
189
  h4. Tasks
189
190
 
190
- h5. manage.rb
191
+ manage.rb
191
192
 
192
193
  * delayed_job:stop - stops the delayed_job workers
193
194
  * delayed_job:start - starts the delayed_job workers
194
195
  * delayed_job:restart - restarts the delayed_job workers
195
196
 
196
- h5. hooks.rb
197
+ hooks.rb
197
198
 
198
199
  <pre>
199
200
  <code>
@@ -215,7 +216,7 @@ h4. Configuration
215
216
 
216
217
  h4. Tasks
217
218
 
218
- h5. manage.rb
219
+ manage.rb
219
220
 
220
221
  * backgroundrb:stop - stop backgroundrb workers
221
222
  * backgroundrb:start - start backgroundrb workers
@@ -223,7 +224,7 @@ h5. manage.rb
223
224
  * backgroundrb:symlink_config - copy backgroundrb.yml from shared/config to release
224
225
  * backgroundrb:tail - tails the backgroundrb log file in production
225
226
 
226
- h5. hooks.rb
227
+ hooks.rb
227
228
 
228
229
  <pre>
229
230
  <code>
@@ -245,7 +246,7 @@ h4. Configuration
245
246
 
246
247
  h4. Tasks
247
248
 
248
- h5. manage.rb
249
+ manage.rb
249
250
 
250
251
  * juggernaut:start - starts the juggernaut push server
251
252
  * juggernaut:stop - stop the juggernaut push server
@@ -253,7 +254,7 @@ h5. manage.rb
253
254
  * juggernaut:symlink_config - copy juggernaut.yml from shared/config to release
254
255
  * juggernaut:tail - tails the juggernaut log file in production
255
256
 
256
- h5. hooks.rb
257
+ hooks.rb
257
258
 
258
259
  <pre>
259
260
  <code>
@@ -276,17 +277,17 @@ h4. Configuration
276
277
 
277
278
  h4. Tasks
278
279
 
279
- h5. manage.rb
280
+ manage.rb
280
281
 
281
282
  * memcache:start - starts the memcache daemon
282
283
  * memcache:stop - stops the memcache daemon
283
284
  * memcache:restart - restarts the memcache daemon
284
285
 
285
- h5. install.rb
286
+ install.rb
286
287
 
287
288
  * memcache:install - Installs memcache aptitude package and rubygem
288
289
 
289
- h5. hooks
290
+ hooks.rb
290
291
 
291
292
  <pre>
292
293
  <code>
@@ -304,11 +305,11 @@ h4. Configuration
304
305
 
305
306
  h4. Tasks
306
307
 
307
- h5. manage.rb
308
+ manage.rb
308
309
 
309
310
  * whenever:update_crontab - Performs an update applying the schedule.rb file to your server's cron
310
311
 
311
- h5. hooks
312
+ hooks.rb
312
313
 
313
314
  <pre>
314
315
  <code>
@@ -401,7 +402,7 @@ to browse all available utility methods. A few are listed below:
401
402
  ** Forces tasks in block to execute only within specific role(s)
402
403
  ** This is useful because of certain limitations in the role declaration in capistrano
403
404
 
404
- * utilities.with_credentials { ... }
405
+ * utilities.with_credentials(:user => 'jsmith', :password => 'secret') { ... }
405
406
  ** Forces tasks in block to execute using the given user/password credentials
406
407
  ** This is useful because of certain limitations in capistrano
407
408
 
data/Rakefile CHANGED
@@ -1,9 +1,12 @@
1
1
  =begin
2
- Using Jeweler for Gem Packaging
3
- Update the version and release version to github:
2
+ Using Jeweler for Gem Packaging...
3
+
4
+ * Update the version and release version to github:
4
5
  $ rake version:bump:patch && rake release && rake gemcutter:release
5
- Build and install the latest version locally:
6
- $ rake build && rake install && sudo gem cleanup
6
+
7
+ * Build and install the latest version locally:
8
+ $ rake install
9
+
7
10
  =end
8
11
 
9
12
  require 'rake'
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 3
4
- :patch: 26
4
+ :patch: 27
data/cap-recipes.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cap-recipes}
8
- s.version = "0.3.26"
8
+ s.version = "0.3.27"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Nathan Esquenazi"]
@@ -1,3 +1,5 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../utilities')
2
+
1
3
  Capistrano::Configuration.instance(true).load do
2
4
 
3
5
  namespace :apache do
@@ -5,7 +7,9 @@ Capistrano::Configuration.instance(true).load do
5
7
  desc 'Installs apache 2 and development headers to compile passenger'
6
8
  task :install, :roles => :web do
7
9
  puts 'Installing apache 2'
8
- try_sudo 'apt-get install apache2 apache2.2-common apache2-mpm-prefork apache2-utils libexpat1 ssl-cert libapr1 libapr1-dev libaprutil1 libmagic1 libpcre3 libpq5 openssl apache2-prefork-dev -y'
10
+ utilities.apt_install %w[apache2 apache2.2-common apache2-mpm-prefork apache2-utils
11
+ libexpat1 ssl-cert libapr1 libapr1-dev libaprutil1 libmagic1
12
+ libpcre3 libpq5 openssl apache2-prefork-dev]
9
13
  end
10
14
 
11
15
  end
@@ -1,29 +1,27 @@
1
- require 'cap_recipes/tasks/utilities.rb'
1
+ require File.expand_path(File.dirname(__FILE__) + '/../utilities')
2
2
 
3
3
  Capistrano::Configuration.instance(true).load do
4
4
  namespace :aptitude do
5
- desc "Updates all installed packages on apt-get package system"
5
+ desc "Updates all installed packages on aptitude package system"
6
6
  task :updates do
7
7
  sudo "apt-get -qy update"
8
- sudo "apt-get -qy upgrade"
8
+ utilities.apt_upgrade
9
9
  sudo "apt-get -qy autoremove"
10
10
  end
11
11
 
12
- desc "Installs a specified apt-get package"
12
+ desc "Installs a specified aptitude package"
13
13
  task :install do
14
- puts "What is the name of the package(s) you wish to install?"
15
- deb_pkg_name = $stdin.gets.chomp
14
+ deb_pkg_name = utilities.ask "Enter name of the package(s) you wish to install:"
16
15
  raise "Please specify deb_pkg_name" if deb_pkg_name == ''
17
16
  logger.info "Updating packages..."
18
17
  sudo "aptitude update"
19
18
  logger.info "Installing #{deb_pkg_name}..."
20
- utilities.sudo_with_input "apt-get install #{deb_pkg_name}", /^Do you want to continue\?/
19
+ utilities.apt_install deb_pkg_name
21
20
  end
22
21
 
23
- desc "Removes a specified apt-get package"
22
+ desc "Removes a specified aptitude package"
24
23
  task :remove do
25
- puts "What is the name of the package(s) you wish to install?"
26
- deb_pkg_name = $stdin.gets.chomp
24
+ deb_pkg_name = utilities.ask "Enter name of the package(s) you wish to remove:"
27
25
  raise "Please specify deb_pkg_name" if deb_pkg_name == ''
28
26
  logger.info "Updating packages..."
29
27
  sudo "aptitude update"
@@ -1,3 +1,5 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../utilities')
2
+
1
3
  Capistrano::Configuration.instance(true).load do
2
4
  set :delayed_script_path, "#{current_path}/script/delayed_job"
3
5
  set :delayed_job_env, 'production'
@@ -1,3 +1,5 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../utilities')
2
+
1
3
  Capistrano::Configuration.instance(true).load do
2
4
  set :juggernaut_config, "#{current_path}/config/juggernaut.yml"
3
5
  set :juggernaut_pid, "#{current_path}/tmp/pids/juggernaut.pid"
@@ -1,10 +1,12 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../utilities')
2
+
1
3
  Capistrano::Configuration.instance(true).load do
2
4
  namespace :memcache do
3
5
 
4
6
  desc 'Installs memcache and the ruby gem'
5
7
  task :install, :roles => :app do
6
8
  puts 'Installing memcache'
7
- try_sudo 'apt-get install memcached'
9
+ utilities.apt_install 'memcached'
8
10
  try_sudo "#{base_ruby_path}/bin/gem install memcache-client --no-ri --no-rdoc"
9
11
  memcache.start
10
12
  end
@@ -1,3 +1,5 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../utilities')
2
+
1
3
  Capistrano::Configuration.instance(true).load do
2
4
 
3
5
  set :memcache_init_path, "/etc/init.d/memcached"
@@ -1,6 +1,6 @@
1
- require 'cap_recipes/tasks/utilities.rb'
1
+ require File.expand_path(File.dirname(__FILE__) + '/../utilities')
2
+ require File.expand_path(File.dirname(__FILE__) + '/../apache/manage')
2
3
 
3
- #TODO add something like require that a task named apache:restart exists
4
4
  Capistrano::Configuration.instance(true).load do
5
5
  set :base_ruby_path, '/usr'
6
6
  set :confd_passenger_filename, 'passenger'
@@ -1,5 +1,3 @@
1
- require 'cap_recipes/tasks/utilities.rb'
2
-
3
1
  Capistrano::Configuration.instance(true).load do
4
2
  namespace :deploy do
5
3
 
@@ -17,6 +15,7 @@ Capistrano::Configuration.instance(true).load do
17
15
 
18
16
  desc "Restarts the phusion passenger server"
19
17
  task :restart, :roles => :web do
18
+ puts "Restarting passenger by touching restart.txt"
20
19
  run "touch #{current_path}/tmp/restart.txt"
21
20
  end
22
21
 
@@ -1,5 +1,3 @@
1
- require 'cap_recipes/tasks/utilities.rb'
2
-
3
1
  Capistrano::Configuration.instance(true).load do
4
2
  after "deploy:update_code", "rails:symlink_db_config" # copy database.yml file to release path
5
3
  after "deploy:update_code", "rails:sweep:cache" # clear cache after updating code
@@ -1,5 +1,3 @@
1
- require 'cap_recipes/tasks/utilities.rb'
2
-
3
1
  Capistrano::Configuration.instance(true).load do
4
2
  set :local_ping_path, 'http://localhost'
5
3
 
@@ -1,5 +1,6 @@
1
- require 'cap_recipes/tasks/utilities.rb'
2
-
1
+ require File.expand_path(File.dirname(__FILE__) + '/../utilities')
2
+ require File.expand_path(File.dirname(__FILE__) + '/../aptitude/manage')
3
+
3
4
  Capistrano::Configuration.instance(true).load do
4
5
 
5
6
  namespace :ruby do
@@ -1,3 +1,5 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../utilities')
2
+
1
3
  Capistrano::Configuration.instance(true).load do
2
4
  set :rubygem_paths, '/usr/bin/gem'
3
5
 
@@ -25,12 +25,10 @@ module Utilities
25
25
  ask(question).downcase.include? 'y'
26
26
  end
27
27
 
28
- def space(str)
29
- "\n#{'=' * 80}\n#{str}"
30
- end
31
-
32
28
  # utilities.apt_install %w[package1 package2]
29
+ # utilities.apt_install "package1 package2"
33
30
  def apt_install(packages)
31
+ packages = packages.split(/\s+/) if packages.respond_to?(:split)
34
32
  packages = Array(packages)
35
33
  apt_get="DEBCONF_TERSE='yes' DEBIAN_PRIORITY='critical' DEBIAN_FRONTEND=noninteractive apt-get"
36
34
  sudo "#{apt_get} -qyu --force-yes install #{packages.join(" ")}"
@@ -70,6 +68,7 @@ module Utilities
70
68
  end
71
69
  end
72
70
 
71
+ # utilities.with_credentials(:user => 'xxxx', :password => 'secret')
73
72
  # options = { :user => 'xxxxx', :password => 'xxxxx' }
74
73
  def with_credentials(options={}, &block)
75
74
  original_username, original_password = user, password
@@ -83,16 +82,17 @@ module Utilities
83
82
  end
84
83
  end
85
84
 
85
+ def space(str)
86
+ "\n#{'=' * 80}\n#{str}"
87
+ end
88
+
86
89
  ##
87
90
  # Run a command and ask for input when input_query is seen.
88
91
  # Sends the response back to the server.
89
92
  #
90
93
  # +input_query+ is a regular expression that defaults to /^Password/.
91
- #
92
94
  # Can be used where +run+ would otherwise be used.
93
- #
94
95
  # run_with_input 'ssh-keygen ...', /^Are you sure you want to overwrite\?/
95
-
96
96
  def run_with_input(shell_command, input_query=/^Password/, response=nil)
97
97
  handle_command_with_input(:run, shell_command, input_query, response)
98
98
  end
@@ -102,9 +102,7 @@ module Utilities
102
102
  # Sends the response back to the server.
103
103
  #
104
104
  # See also +run_with_input+
105
- #
106
105
  # +input_query+ is a regular expression
107
-
108
106
  def sudo_with_input(shell_command, input_query=/^Password/, response=nil)
109
107
  handle_command_with_input(:sudo, shell_command, input_query, response)
110
108
  end
@@ -121,7 +119,6 @@ module Utilities
121
119
  # local_run_method: run or sudo
122
120
  # shell_command: The command to run
123
121
  # input_query: A regular expression matching a request for input: /^Please enter your password/
124
-
125
122
  def handle_command_with_input(local_run_method, shell_command, input_query, response=nil)
126
123
  send(local_run_method, shell_command, {:pty => true}) do |channel, stream, data|
127
124
 
@@ -1,5 +1,3 @@
1
- require 'cap_recipes/tasks/utilities.rb'
2
-
3
1
  Capistrano::Configuration.instance(true).load do
4
2
  namespace :whenever do
5
3
  desc "Update the crontab file"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cap-recipes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.26
4
+ version: 0.3.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Esquenazi