capistrano 2.1.0 → 3.0.0

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