capistrano 1.4.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. data/CHANGELOG +140 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README +22 -14
  4. data/bin/cap +1 -8
  5. data/bin/capify +77 -0
  6. data/examples/sample.rb +10 -109
  7. data/lib/capistrano.rb +1 -0
  8. data/lib/capistrano/callback.rb +41 -0
  9. data/lib/capistrano/cli.rb +17 -317
  10. data/lib/capistrano/cli/execute.rb +82 -0
  11. data/lib/capistrano/cli/help.rb +102 -0
  12. data/lib/capistrano/cli/help.txt +53 -0
  13. data/lib/capistrano/cli/options.rb +183 -0
  14. data/lib/capistrano/cli/ui.rb +28 -0
  15. data/lib/capistrano/command.rb +62 -29
  16. data/lib/capistrano/configuration.rb +25 -226
  17. data/lib/capistrano/configuration/actions/file_transfer.rb +35 -0
  18. data/lib/capistrano/configuration/actions/inspect.rb +46 -0
  19. data/lib/capistrano/configuration/actions/invocation.rb +127 -0
  20. data/lib/capistrano/configuration/callbacks.rb +148 -0
  21. data/lib/capistrano/configuration/connections.rb +159 -0
  22. data/lib/capistrano/configuration/execution.rb +126 -0
  23. data/lib/capistrano/configuration/loading.rb +112 -0
  24. data/lib/capistrano/configuration/namespaces.rb +190 -0
  25. data/lib/capistrano/configuration/roles.rb +51 -0
  26. data/lib/capistrano/configuration/servers.rb +75 -0
  27. data/lib/capistrano/configuration/variables.rb +127 -0
  28. data/lib/capistrano/errors.rb +15 -0
  29. data/lib/capistrano/extensions.rb +27 -8
  30. data/lib/capistrano/gateway.rb +54 -29
  31. data/lib/capistrano/logger.rb +11 -11
  32. data/lib/capistrano/recipes/compat.rb +32 -0
  33. data/lib/capistrano/recipes/deploy.rb +483 -0
  34. data/lib/capistrano/recipes/deploy/dependencies.rb +44 -0
  35. data/lib/capistrano/recipes/deploy/local_dependency.rb +46 -0
  36. data/lib/capistrano/recipes/deploy/remote_dependency.rb +65 -0
  37. data/lib/capistrano/recipes/deploy/scm.rb +19 -0
  38. data/lib/capistrano/recipes/deploy/scm/base.rb +180 -0
  39. data/lib/capistrano/recipes/deploy/scm/bzr.rb +86 -0
  40. data/lib/capistrano/recipes/deploy/scm/cvs.rb +151 -0
  41. data/lib/capistrano/recipes/deploy/scm/darcs.rb +85 -0
  42. data/lib/capistrano/recipes/deploy/scm/mercurial.rb +129 -0
  43. data/lib/capistrano/recipes/deploy/scm/perforce.rb +126 -0
  44. data/lib/capistrano/recipes/deploy/scm/subversion.rb +103 -0
  45. data/lib/capistrano/recipes/deploy/strategy.rb +19 -0
  46. data/lib/capistrano/recipes/deploy/strategy/base.rb +64 -0
  47. data/lib/capistrano/recipes/deploy/strategy/checkout.rb +20 -0
  48. data/lib/capistrano/recipes/deploy/strategy/copy.rb +143 -0
  49. data/lib/capistrano/recipes/deploy/strategy/export.rb +20 -0
  50. data/lib/capistrano/recipes/deploy/strategy/remote.rb +52 -0
  51. data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +47 -0
  52. data/lib/capistrano/recipes/deploy/templates/maintenance.rhtml +53 -0
  53. data/lib/capistrano/recipes/standard.rb +26 -276
  54. data/lib/capistrano/recipes/templates/maintenance.rhtml +1 -1
  55. data/lib/capistrano/recipes/upgrade.rb +33 -0
  56. data/lib/capistrano/server_definition.rb +51 -0
  57. data/lib/capistrano/shell.rb +125 -81
  58. data/lib/capistrano/ssh.rb +80 -36
  59. data/lib/capistrano/task_definition.rb +69 -0
  60. data/lib/capistrano/upload.rb +146 -0
  61. data/lib/capistrano/version.rb +13 -17
  62. data/test/cli/execute_test.rb +132 -0
  63. data/test/cli/help_test.rb +139 -0
  64. data/test/cli/options_test.rb +226 -0
  65. data/test/cli/ui_test.rb +28 -0
  66. data/test/cli_test.rb +17 -0
  67. data/test/command_test.rb +284 -25
  68. data/test/configuration/actions/file_transfer_test.rb +40 -0
  69. data/test/configuration/actions/inspect_test.rb +62 -0
  70. data/test/configuration/actions/invocation_test.rb +195 -0
  71. data/test/configuration/callbacks_test.rb +206 -0
  72. data/test/configuration/connections_test.rb +288 -0
  73. data/test/configuration/execution_test.rb +159 -0
  74. data/test/configuration/loading_test.rb +119 -0
  75. data/test/configuration/namespace_dsl_test.rb +283 -0
  76. data/test/configuration/roles_test.rb +47 -0
  77. data/test/configuration/servers_test.rb +90 -0
  78. data/test/configuration/variables_test.rb +180 -0
  79. data/test/configuration_test.rb +60 -212
  80. data/test/deploy/scm/base_test.rb +55 -0
  81. data/test/deploy/strategy/copy_test.rb +146 -0
  82. data/test/extensions_test.rb +69 -0
  83. data/test/fixtures/cli_integration.rb +5 -0
  84. data/test/fixtures/custom.rb +2 -2
  85. data/test/gateway_test.rb +167 -0
  86. data/test/logger_test.rb +123 -0
  87. data/test/server_definition_test.rb +108 -0
  88. data/test/shell_test.rb +64 -0
  89. data/test/ssh_test.rb +67 -154
  90. data/test/task_definition_test.rb +101 -0
  91. data/test/upload_test.rb +131 -0
  92. data/test/utils.rb +31 -39
  93. data/test/version_test.rb +24 -0
  94. metadata +145 -98
  95. data/THANKS +0 -4
  96. data/lib/capistrano/actor.rb +0 -567
  97. data/lib/capistrano/generators/rails/deployment/deployment_generator.rb +0 -25
  98. data/lib/capistrano/generators/rails/deployment/templates/capistrano.rake +0 -49
  99. data/lib/capistrano/generators/rails/deployment/templates/deploy.rb +0 -122
  100. data/lib/capistrano/generators/rails/loader.rb +0 -20
  101. data/lib/capistrano/scm/base.rb +0 -61
  102. data/lib/capistrano/scm/baz.rb +0 -118
  103. data/lib/capistrano/scm/bzr.rb +0 -70
  104. data/lib/capistrano/scm/cvs.rb +0 -129
  105. data/lib/capistrano/scm/darcs.rb +0 -27
  106. data/lib/capistrano/scm/mercurial.rb +0 -83
  107. data/lib/capistrano/scm/perforce.rb +0 -139
  108. data/lib/capistrano/scm/subversion.rb +0 -128
  109. data/lib/capistrano/transfer.rb +0 -97
  110. data/lib/capistrano/utils.rb +0 -26
  111. data/test/actor_test.rb +0 -402
  112. data/test/scm/cvs_test.rb +0 -196
  113. data/test/scm/subversion_test.rb +0 -145
@@ -0,0 +1,32 @@
1
+ # A collection of compatibility scripts, to ease the transition between
2
+ # Capistrano 1.x and Capistrano 2.x.
3
+
4
+ # Depends on the deployment system
5
+ load 'deploy'
6
+
7
+ map = { "diff_from_last_deploy" => "deploy:pending:diff",
8
+ "update" => "deploy:update",
9
+ "update_code" => "deploy:update_code",
10
+ "symlink" => "deploy:symlink",
11
+ "restart" => "deploy:restart",
12
+ "rollback" => "deploy:rollback",
13
+ "cleanup" => "deploy:cleanup",
14
+ "disable_web" => "deploy:web:disable",
15
+ "enable_web" => "deploy:web:enable",
16
+ "cold_deploy" => "deploy:cold",
17
+ "deploy_with_migrations" => "deploy:migrations" }
18
+
19
+ map.each do |old, new|
20
+ desc "DEPRECATED: See #{new}."
21
+ eval "task(#{old.inspect}) do
22
+ warn \"[DEPRECATED] `#{old}' is deprecated. Use `#{new}' instead.\"
23
+ find_and_execute_task(#{new.inspect})
24
+ end"
25
+ end
26
+
27
+ desc "DEPRECATED: See deploy:start."
28
+ task :spinner do
29
+ warn "[DEPRECATED] `spinner' is deprecated. Use `deploy:start' instead."
30
+ set :runner, fetch(:spinner_user, "app")
31
+ deploy.start
32
+ end
@@ -0,0 +1,483 @@
1
+ require 'yaml'
2
+ require 'capistrano/recipes/deploy/scm'
3
+ require 'capistrano/recipes/deploy/strategy'
4
+
5
+ def _cset(name, *args, &block)
6
+ unless exists?(name)
7
+ set(name, *args, &block)
8
+ end
9
+ end
10
+
11
+ # =========================================================================
12
+ # These variables MUST be set in the client capfiles. If they are not set,
13
+ # the deploy will fail with an error.
14
+ # =========================================================================
15
+
16
+ _cset(:application) { abort "Please specify the name of your application, set :application, 'foo'" }
17
+ _cset(:repository) { abort "Please specify the repository that houses your application's code, set :repository, 'foo'" }
18
+
19
+ # =========================================================================
20
+ # These variables may be set in the client capfile if their default values
21
+ # are not sufficient.
22
+ # =========================================================================
23
+
24
+ _cset :scm, :subversion
25
+ _cset :deploy_via, :checkout
26
+
27
+ _cset(:deploy_to) { "/u/apps/#{application}" }
28
+ _cset(:revision) { source.head }
29
+
30
+ # =========================================================================
31
+ # These variables should NOT be changed unless you are very confident in
32
+ # what you are doing. Make sure you understand all the implications of your
33
+ # changes if you do decide to muck with these!
34
+ # =========================================================================
35
+
36
+ _cset(:source) { Capistrano::Deploy::SCM.new(scm, self) }
37
+ _cset(:real_revision) { source.local.query_revision(revision) { |cmd| with_env("LC_ALL", "C") { `#{cmd}` } } }
38
+
39
+ _cset(:strategy) { Capistrano::Deploy::Strategy.new(deploy_via, self) }
40
+
41
+ _cset(:release_name) { set :deploy_timestamped, true; Time.now.utc.strftime("%Y%m%d%H%M%S") }
42
+ _cset(:releases_path) { File.join(deploy_to, "releases") }
43
+ _cset(:shared_path) { File.join(deploy_to, "shared") }
44
+ _cset(:current_path) { File.join(deploy_to, "current") }
45
+ _cset(:release_path) { File.join(releases_path, release_name) }
46
+
47
+ _cset(:releases) { capture("ls -x #{releases_path}").split.sort }
48
+ _cset(:current_release) { File.join(releases_path, releases.last) }
49
+ _cset(:previous_release) { File.join(releases_path, releases[-2]) }
50
+
51
+ _cset(:current_revision) { capture("cat #{current_path}/REVISION").chomp }
52
+ _cset(:latest_revision) { capture("cat #{current_release}/REVISION").chomp }
53
+ _cset(:previous_revision) { capture("cat #{previous_release}/REVISION").chomp }
54
+
55
+ _cset(:run_method) { fetch(:use_sudo, true) ? :sudo : :run }
56
+
57
+ # some tasks, like symlink, need to always point at the latest release, but
58
+ # they can also (occassionally) be called standalone. In the standalone case,
59
+ # the timestamped release_path will be inaccurate, since the directory won't
60
+ # actually exist. This variable lets tasks like symlink work either in the
61
+ # standalone case, or during deployment.
62
+ _cset(:latest_release) { exists?(:deploy_timestamped) ? release_path : current_release }
63
+
64
+ # =========================================================================
65
+ # These are helper methods that will be available to your recipes.
66
+ # =========================================================================
67
+
68
+ # Auxiliary helper method for the `deploy:check' task. Lets you set up your
69
+ # own dependencies.
70
+ def depend(location, type, *args)
71
+ deps = fetch(:dependencies, {})
72
+ deps[location] ||= {}
73
+ deps[location][type] ||= []
74
+ deps[location][type] << args
75
+ set :dependencies, deps
76
+ end
77
+
78
+ # Temporarily sets an environment variable, yields to a block, and restores
79
+ # the value when it is done.
80
+ def with_env(name, value)
81
+ saved, ENV[name] = ENV[name], value
82
+ yield
83
+ ensure
84
+ ENV[name] = saved
85
+ end
86
+
87
+ # =========================================================================
88
+ # These are the tasks that are available to help with deploying web apps,
89
+ # and specifically, Rails applications. You can have cap give you a summary
90
+ # of them with `cap -T'.
91
+ # =========================================================================
92
+
93
+ namespace :deploy do
94
+ desc <<-DESC
95
+ Deploys your project. This calls both `update' and `restart'. Note that \
96
+ this will generally only work for applications that have already been deployed \
97
+ once. For a "cold" deploy, you'll want to take a look at the `deploy:cold' \
98
+ task, which handles the cold start specifically.
99
+ DESC
100
+ task :default do
101
+ update
102
+ restart
103
+ end
104
+
105
+ desc <<-DESC
106
+ Prepares one or more servers for deployment. Before you can use any \
107
+ of the Capistrano deployment tasks with your project, you will need to \
108
+ make sure all of your servers have been prepared with `cap setup'. When \
109
+ you add a new server to your cluster, you can easily run the setup task \
110
+ on just that server by specifying the HOSTS environment variable:
111
+
112
+ $ cap HOSTS=new.server.com setup
113
+
114
+ It is safe to run this task on servers that have already been set up; it \
115
+ will not destroy any deployed revisions or data.
116
+ DESC
117
+ task :setup, :except => { :no_release => true } do
118
+ dirs = [deploy_to, releases_path, shared_path]
119
+ dirs += %w(system log pids).map { |d| File.join(shared_path, d) }
120
+ run "umask 02 && mkdir -p #{dirs.join(' ')}"
121
+ end
122
+
123
+ desc <<-DESC
124
+ Copies your project and updates the symlink. It does this in a \
125
+ transaction, so that if either `update_code' or `symlink' fail, all \
126
+ changes made to the remote servers will be rolled back, leaving your \
127
+ system in the same state it was in before `update' was invoked. Usually, \
128
+ you will want to call `deploy' instead of `update', but `update' can be \
129
+ handy if you want to deploy, but not immediately restart your application.
130
+ DESC
131
+ task :update do
132
+ transaction do
133
+ update_code
134
+ symlink
135
+ end
136
+ end
137
+
138
+ desc <<-DESC
139
+ Copies your project to the remote servers. This is the first stage \
140
+ of any deployment; moving your updated code and assets to the deployment \
141
+ servers. You will rarely call this task directly, however; instead, you \
142
+ should call the `deploy' task (to do a complete deploy) or the `update' \
143
+ task (if you want to perform the `restart' task separately).
144
+
145
+ You will need to make sure you set the :scm variable to the source \
146
+ control software you are using (it defaults to :subversion), and the \
147
+ :deploy_via variable to the strategy you want to use to deploy (it \
148
+ defaults to :checkout).
149
+ DESC
150
+ task :update_code, :except => { :no_release => true } do
151
+ on_rollback { run "rm -rf #{release_path}; true" }
152
+ strategy.deploy!
153
+ finalize_update
154
+ end
155
+
156
+ desc <<-DESC
157
+ [internal] Touches up the released code. This is called by update_code \
158
+ after the basic deploy finishes. It assumes a Rails project was deployed, \
159
+ so if you are deploying something else, you may want to override this \
160
+ task with your own environment's requirements.
161
+
162
+ This task will make the release group-writable (if the :group_writable \
163
+ variable is set to true, which is the default). It will then set up \
164
+ symlinks to the shared directory for the log, system, and tmp/pids \
165
+ directories, and will lastly touch all assets in public/images, \
166
+ public/stylesheets, and public/javascripts so that the times are \
167
+ consistent (so that asset timestamping works).
168
+ DESC
169
+ task :finalize_update, :except => { :no_release => true } do
170
+ run "chmod -R g+w #{latest_release}" if fetch(:group_writable, true)
171
+
172
+ # mkdir -p is making sure that the directories are there for some SCM's that don't
173
+ # save empty folders
174
+ run <<-CMD
175
+ rm -rf #{latest_release}/log #{latest_release}/public/system #{latest_release}/tmp/pids &&
176
+ mkdir -p #{latest_release}/public &&
177
+ mkdir -p #{latest_release}/tmp &&
178
+ ln -s #{shared_path}/log #{latest_release}/log &&
179
+ ln -s #{shared_path}/system #{latest_release}/public/system &&
180
+ ln -s #{shared_path}/pids #{latest_release}/tmp/pids
181
+ CMD
182
+
183
+ stamp = Time.now.utc.strftime("%Y%m%d%H%M.%S")
184
+ asset_paths = %w(images stylesheets javascripts).map { |p| "#{latest_release}/public/#{p}" }.join(" ")
185
+ run "find #{asset_paths} -exec touch -t #{stamp} {} ';'; true", :env => { "TZ" => "UTC" }
186
+ end
187
+
188
+ desc <<-DESC
189
+ Updates the symlink to the most recently deployed version. Capistrano works \
190
+ by putting each new release of your application in its own directory. When \
191
+ you deploy a new version, this task's job is to update the `current' symlink \
192
+ to point at the new version. You will rarely need to call this task \
193
+ directly; instead, use the `deploy' task (which performs a complete \
194
+ deploy, including `restart') or the 'update' task (which does everything \
195
+ except `restart').
196
+ DESC
197
+ task :symlink, :except => { :no_release => true } do
198
+ on_rollback { run "rm -f #{current_path}; ln -s #{previous_release} #{current_path}; true" }
199
+ run "rm -f #{current_path} && ln -s #{latest_release} #{current_path}"
200
+ end
201
+
202
+ desc <<-DESC
203
+ Copy files to the currently deployed version. This is useful for updating \
204
+ files piecemeal, such as when you need to quickly deploy only a single \
205
+ file. Some files, such as updated templates, images, or stylesheets, \
206
+ might not require a full deploy, and especially in emergency situations \
207
+ it can be handy to just push the updates to production, quickly.
208
+
209
+ To use this task, specify the files and directories you want to copy as a \
210
+ comma-delimited list in the FILES environment variable. All directories \
211
+ will be processed recursively, with all files being pushed to the \
212
+ deployment servers. Any file or directory starting with a '.' character \
213
+ will be ignored.
214
+
215
+ $ cap deploy:upload FILES=templates,controller.rb
216
+ DESC
217
+ task :upload, :except => { :no_release => true } do
218
+ files = (ENV["FILES"] || "").
219
+ split(",").
220
+ map { |f| f.strip!; File.directory?(f) ? Dir["#{f}/**/*"] : f }.
221
+ flatten.
222
+ reject { |f| File.directory?(f) || File.basename(f)[0] == ?. }
223
+
224
+ abort "Please specify at least one file to update (via the FILES environment variable)" if files.empty?
225
+
226
+ files.each do |file|
227
+ put File.read(file), File.join(current_path, file)
228
+ end
229
+ end
230
+
231
+ desc <<-DESC
232
+ Restarts your application. This works by calling the script/process/reaper \
233
+ script under the current path. By default, this will be invoked via sudo, \
234
+ but if you are in an environment where sudo is not an option, or is not \
235
+ allowed, you can indicate that restarts should use `run' instead by \
236
+ setting the `use_sudo' variable to false:
237
+
238
+ set :use_sudo, false
239
+ DESC
240
+ task :restart, :roles => :app, :except => { :no_release => true } do
241
+ invoke_command "#{current_path}/script/process/reaper", :via => run_method
242
+ end
243
+
244
+ desc <<-DESC
245
+ Rolls back to the previously deployed version. The `current' symlink will \
246
+ be updated to point at the previously deployed version, and then the \
247
+ current release will be removed from the servers. You'll generally want \
248
+ to call `rollback' instead, as it performs a `restart' as well.
249
+ DESC
250
+ task :rollback_code, :except => { :no_release => true } do
251
+ if releases.length < 2
252
+ abort "could not rollback the code because there is no prior release"
253
+ else
254
+ run "rm #{current_path}; ln -s #{previous_release} #{current_path} && rm -rf #{current_release}"
255
+ end
256
+ end
257
+
258
+ desc <<-DESC
259
+ Rolls back to a previous version and restarts. This is handy if you ever \
260
+ discover that you've deployed a lemon; `cap rollback' and you're right \
261
+ back where you were, on the previously deployed version.
262
+ DESC
263
+ task :rollback do
264
+ rollback_code
265
+ restart
266
+ end
267
+
268
+ desc <<-DESC
269
+ Run the migrate rake task. By default, it runs this in most recently \
270
+ deployed version of the app. However, you can specify a different release \
271
+ via the migrate_target variable, which must be one of :latest (for the \
272
+ default behavior), or :current (for the release indicated by the \
273
+ `current' symlink). Strings will work for those values instead of symbols, \
274
+ too. You can also specify additional environment variables to pass to rake \
275
+ via the migrate_env variable. Finally, you can specify the full path to the \
276
+ rake executable by setting the rake variable. The defaults are:
277
+
278
+ set :rake, "rake"
279
+ set :rails_env, "production"
280
+ set :migrate_env, ""
281
+ set :migrate_target, :latest
282
+ DESC
283
+ task :migrate, :roles => :db, :only => { :primary => true } do
284
+ rake = fetch(:rake, "rake")
285
+ rails_env = fetch(:rails_env, "production")
286
+ migrate_env = fetch(:migrate_env, "")
287
+ migrate_target = fetch(:migrate_target, :latest)
288
+
289
+ directory = case migrate_target.to_sym
290
+ when :current then current_path
291
+ when :latest then current_release
292
+ else raise ArgumentError, "unknown migration target #{migrate_target.inspect}"
293
+ end
294
+
295
+ run "cd #{directory}; #{rake} RAILS_ENV=#{rails_env} #{migrate_env} db:migrate"
296
+ end
297
+
298
+ desc <<-DESC
299
+ Deploy and run pending migrations. This will work similarly to the \
300
+ `deploy' task, but will also run any pending migrations (via the \
301
+ `deploy:migrate' task) prior to updating the symlink. Note that the \
302
+ update in this case it is not atomic, and transactions are not used, \
303
+ because migrations are not guaranteed to be reversible.
304
+ DESC
305
+ task :migrations do
306
+ set :migrate_target, :latest
307
+ update_code
308
+ migrate
309
+ symlink
310
+ restart
311
+ end
312
+
313
+ desc <<-DESC
314
+ Clean up old releases. By default, the last 5 releases are kept on each \
315
+ server (though you can change this with the keep_releases variable). All \
316
+ other deployed revisions are removed from the servers. By default, this \
317
+ will use sudo to clean up the old releases, but if sudo is not available \
318
+ for your environment, set the :use_sudo variable to false instead.
319
+ DESC
320
+ task :cleanup, :except => { :no_release => true } do
321
+ count = fetch(:keep_releases, 5).to_i
322
+ if count >= releases.length
323
+ logger.important "no old releases to clean up"
324
+ else
325
+ logger.info "keeping #{count} of #{releases.length} deployed releases"
326
+
327
+ directories = (releases - releases.last(count)).map { |release|
328
+ File.join(releases_path, release) }.join(" ")
329
+
330
+ invoke_command "rm -rf #{directories}", :via => run_method
331
+ end
332
+ end
333
+
334
+ desc <<-DESC
335
+ Test deployment dependencies. Checks things like directory permissions, \
336
+ necessary utilities, and so forth, reporting on the things that appear to \
337
+ be incorrect or missing. This is good for making sure a deploy has a \
338
+ chance of working before you actually run `cap deploy'.
339
+
340
+ You can define your own dependencies, as well, using the `depend' method:
341
+
342
+ depend :remote, :gem, "tzinfo", ">=0.3.3"
343
+ depend :local, :command, "svn"
344
+ depend :remote, :directory, "/u/depot/files"
345
+ DESC
346
+ task :check, :except => { :no_release => true } do
347
+ dependencies = strategy.check!
348
+
349
+ other = fetch(:dependencies, {})
350
+ other.each do |location, types|
351
+ types.each do |type, calls|
352
+ if type == :gem
353
+ dependencies.send(location).command(fetch(:gem_command, "gem")).or("`gem' command could not be found. Try setting :gem_command")
354
+ end
355
+
356
+ calls.each do |args|
357
+ dependencies.send(location).send(type, *args)
358
+ end
359
+ end
360
+ end
361
+
362
+ if dependencies.pass?
363
+ puts "You appear to have all necessary dependencies installed"
364
+ else
365
+ puts "The following dependencies failed. Please check them and try again:"
366
+ dependencies.reject { |d| d.pass? }.each do |d|
367
+ puts "--> #{d.message}"
368
+ end
369
+ abort
370
+ end
371
+ end
372
+
373
+ desc <<-DESC
374
+ Deploys and starts a `cold' application. This is useful if you have not \
375
+ deployed your application before, or if your application is (for some \
376
+ other reason) not currently running. It will deploy the code, run any \
377
+ pending migrations, and then instead of invoking `deploy:restart', it will \
378
+ invoke `deploy:start' to fire up the application servers.
379
+ DESC
380
+ task :cold do
381
+ update
382
+ migrate
383
+ start
384
+ end
385
+
386
+ desc <<-DESC
387
+ Start the application servers. This will attempt to invoke a script \
388
+ in your application called `script/spin', which must know how to start \
389
+ your application listeners. For Rails applications, you might just have \
390
+ that script invoke `script/process/spawner' with the appropriate \
391
+ arguments.
392
+
393
+ By default, the script will be executed via sudo as the `app' user. If \
394
+ you wish to run it as a different user, set the :runner variable to \
395
+ that user. If you are in an environment where you can't use sudo, set \
396
+ the :use_sudo variable to false.
397
+ DESC
398
+ task :start, :roles => :app do
399
+ as = fetch(:runner, "app")
400
+ via = fetch(:run_method, :sudo)
401
+ invoke_command "sh -c 'cd #{current_path} && nohup script/spin'", :via => via, :as => as
402
+ end
403
+
404
+ desc <<-DESC
405
+ Stop the application servers. This will call script/process/reaper for \
406
+ both the spawner process, and all of the application processes it has \
407
+ spawned. As such, it is fairly Rails specific and may need to be \
408
+ overridden for other systems.
409
+
410
+ By default, the script will be executed via sudo as the `app' user. If \
411
+ you wish to run it as a different user, set the :runner variable to \
412
+ that user. If you are in an environment where you can't use sudo, set \
413
+ the :use_sudo variable to false.
414
+ DESC
415
+ task :stop, :roles => :app do
416
+ as = fetch(:runner, "app")
417
+ via = fetch(:run_method, :sudo)
418
+
419
+ invoke_command "#{current_path}/script/process/reaper -a kill -r dispatch.spawner.pid", :via => via, :as => as
420
+ invoke_command "#{current_path}/script/process/reaper -a kill", :via => via, :as => as
421
+ end
422
+
423
+ namespace :pending do
424
+ desc <<-DESC
425
+ Displays the `diff' since your last deploy. This is useful if you want \
426
+ to examine what changes are about to be deployed. Note that this might \
427
+ not be supported on all SCM's.
428
+ DESC
429
+ task :diff, :except => { :no_release => true } do
430
+ system(source.local.diff(current_revision))
431
+ end
432
+
433
+ desc <<-DESC
434
+ Displays the commits since your last deploy. This is good for a summary \
435
+ of the changes that have occurred since the last deploy. Note that this \
436
+ might not be supported on all SCM's.
437
+ DESC
438
+ task :default, :except => { :no_release => true } do
439
+ system(source.local.log(current_revision))
440
+ end
441
+ end
442
+
443
+ namespace :web do
444
+ desc <<-DESC
445
+ Present a maintenance page to visitors. Disables your application's web \
446
+ interface by writing a "maintenance.html" file to each web server. The \
447
+ servers must be configured to detect the presence of this file, and if \
448
+ it is present, always display it instead of performing the request.
449
+
450
+ By default, the maintenance page will just say the site is down for \
451
+ "maintenance", and will be back "shortly", but you can customize the \
452
+ page by specifying the REASON and UNTIL environment variables:
453
+
454
+ $ cap deploy:web:disable \\
455
+ REASON="hardware upgrade" \\
456
+ UNTIL="12pm Central Time"
457
+
458
+ Further customization will require that you write your own task.
459
+ DESC
460
+ task :disable, :roles => :web, :except => { :no_release => true } do
461
+ require 'erb'
462
+ on_rollback { run "rm #{shared_path}/system/maintenance.html" }
463
+
464
+ reason = ENV['REASON']
465
+ deadline = ENV['UNTIL']
466
+
467
+ template = File.read(File.join(File.dirname(__FILE__), "templates", "maintenance.rhtml"))
468
+ result = ERB.new(template).result(binding)
469
+
470
+ put result, "#{shared_path}/system/maintenance.html", :mode => 0644
471
+ end
472
+
473
+ desc <<-DESC
474
+ Makes the application web-accessible again. Removes the \
475
+ "maintenance.html" page generated by deploy:web:disable, which (if your \
476
+ web servers are configured correctly) will make your application \
477
+ web-accessible again.
478
+ DESC
479
+ task :enable, :roles => :web, :except => { :no_release => true } do
480
+ run "rm #{shared_path}/system/maintenance.html"
481
+ end
482
+ end
483
+ end