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 +28 -27
- data/Rakefile +7 -4
- data/VERSION.yml +1 -1
- data/cap-recipes.gemspec +1 -1
- data/lib/cap_recipes/tasks/apache/install.rb +5 -1
- data/lib/cap_recipes/tasks/aptitude/manage.rb +8 -10
- data/lib/cap_recipes/tasks/delayed_job/manage.rb +2 -0
- data/lib/cap_recipes/tasks/juggernaut/manage.rb +2 -0
- data/lib/cap_recipes/tasks/memcache/install.rb +3 -1
- data/lib/cap_recipes/tasks/memcache/manage.rb +2 -0
- data/lib/cap_recipes/tasks/passenger/install.rb +2 -2
- data/lib/cap_recipes/tasks/passenger/manage.rb +1 -2
- data/lib/cap_recipes/tasks/rails/hooks.rb +0 -2
- data/lib/cap_recipes/tasks/rails/manage.rb +0 -2
- data/lib/cap_recipes/tasks/ruby/install.rb +3 -2
- data/lib/cap_recipes/tasks/rubygems/manage.rb +2 -0
- data/lib/cap_recipes/tasks/utilities.rb +7 -10
- data/lib/cap_recipes/tasks/whenever/manage.rb +0 -2
- metadata +1 -1
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
|
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
|
-
|
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,
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
286
|
+
install.rb
|
286
287
|
|
287
288
|
* memcache:install - Installs memcache aptitude package and rubygem
|
288
289
|
|
289
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
6
|
-
|
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
data/cap-recipes.gemspec
CHANGED
@@ -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
|
-
|
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 '
|
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
|
5
|
+
desc "Updates all installed packages on aptitude package system"
|
6
6
|
task :updates do
|
7
7
|
sudo "apt-get -qy update"
|
8
|
-
|
8
|
+
utilities.apt_upgrade
|
9
9
|
sudo "apt-get -qy autoremove"
|
10
10
|
end
|
11
11
|
|
12
|
-
desc "Installs a specified
|
12
|
+
desc "Installs a specified aptitude package"
|
13
13
|
task :install do
|
14
|
-
|
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.
|
19
|
+
utilities.apt_install deb_pkg_name
|
21
20
|
end
|
22
21
|
|
23
|
-
desc "Removes a specified
|
22
|
+
desc "Removes a specified aptitude package"
|
24
23
|
task :remove do
|
25
|
-
|
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,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
|
-
|
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,6 +1,6 @@
|
|
1
|
-
require '
|
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
|
@@ -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
|
|