kennethkalmer-daemon-kit 0.1.6 → 0.1.7.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/Configuration.txt +58 -0
  2. data/History.txt +16 -0
  3. data/Manifest.txt +29 -2
  4. data/PostInstall.txt +1 -1
  5. data/{README.textile → README.rdoc} +31 -19
  6. data/Rakefile +2 -4
  7. data/TODO.txt +6 -5
  8. data/app_generators/daemon_kit/daemon_kit_generator.rb +29 -0
  9. data/app_generators/daemon_kit/templates/Rakefile +3 -1
  10. data/app_generators/daemon_kit/templates/config/arguments.rb +12 -0
  11. data/app_generators/daemon_kit/templates/config/boot.rb +2 -2
  12. data/app_generators/daemon_kit/templates/script/console +3 -0
  13. data/app_generators/daemon_kit/templates/script/destroy +14 -0
  14. data/app_generators/daemon_kit/templates/script/generate +14 -0
  15. data/daemon_generators/deploy_capistrano/deploy_capistrano_generator.rb +35 -0
  16. data/daemon_generators/deploy_capistrano/templates/Capfile +10 -0
  17. data/daemon_generators/deploy_capistrano/templates/USAGE +10 -0
  18. data/daemon_generators/deploy_capistrano/templates/config/deploy/production.rb +6 -0
  19. data/daemon_generators/deploy_capistrano/templates/config/deploy/staging.rb +6 -0
  20. data/daemon_generators/deploy_capistrano/templates/config/deploy.rb +51 -0
  21. data/daemon_generators/deploy_capistrano/templates/config/environments/staging.rb +0 -0
  22. data/lib/daemon_kit/application.rb +135 -11
  23. data/lib/daemon_kit/arguments.rb +151 -0
  24. data/lib/daemon_kit/commands/console.rb +38 -0
  25. data/lib/daemon_kit/config.rb +1 -0
  26. data/lib/daemon_kit/console_daemon.rb +2 -0
  27. data/lib/daemon_kit/core_ext/string.rb +22 -0
  28. data/lib/daemon_kit/core_ext.rb +1 -0
  29. data/lib/daemon_kit/deployment/capistrano.rb +485 -0
  30. data/lib/daemon_kit/initializer.rb +87 -25
  31. data/lib/daemon_kit/pid_file.rb +61 -0
  32. data/lib/daemon_kit/tasks/environment.rake +5 -4
  33. data/lib/daemon_kit/tasks/framework.rake +15 -1
  34. data/lib/daemon_kit/tasks/god.rake +62 -0
  35. data/lib/daemon_kit/tasks/monit.rake +29 -0
  36. data/lib/daemon_kit.rb +11 -5
  37. data/rubygems_generators/install_rspec/templates/spec/spec_helper.rb +1 -1
  38. data/spec/argument_spec.rb +51 -0
  39. data/spec/config_spec.rb +77 -0
  40. data/spec/daemon_kit_spec.rb +2 -2
  41. data/spec/fixtures/env.yml +15 -0
  42. data/spec/fixtures/noenv.yml +4 -0
  43. data/spec/initializer_spec.rb +4 -3
  44. data/spec/spec_helper.rb +8 -11
  45. data/templates/god/god.erb +69 -0
  46. data/templates/monit/monit.erb +14 -0
  47. data/test/test_daemon-kit_generator.rb +15 -1
  48. data/test/test_deploy_capistrano_generator.rb +48 -0
  49. metadata +41 -21
  50. data/lib/daemon_kit/patches/force_kill_wait.rb +0 -120
@@ -0,0 +1,38 @@
1
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
2
+
3
+ require 'optparse'
4
+
5
+ options = { :irb => irb }
6
+ OptionParser.new do |opt|
7
+ opt.banner = "Usage: console [environment] [options]"
8
+ opt.on("--irb=[#{irb}]", 'Invoke a different irb.') { |v| options[:irb] = v }
9
+ opt.on("--debugger", 'Enable ruby-debugging for the console.') { |v| options[:debugger] = v }
10
+ opt.parse!(ARGV)
11
+ end
12
+
13
+ libs = " -r irb/completion"
14
+ libs << %( -r "#{DAEMON_ROOT}/config/environment")
15
+ libs << " -r daemon_kit/console_daemon"
16
+
17
+ if options[:debugger]
18
+ begin
19
+ require 'ruby-debug'
20
+ libs << " -r ruby-debug"
21
+ puts "=> Debugger enabled"
22
+ rescue Exception
23
+ puts "You need to install ruby-debug to run the console in debugging mode. With gems, use 'gem install ruby-debug'"
24
+ exit
25
+ end
26
+ end
27
+
28
+ ENV['DAEMON_ENV'] = case ARGV.first
29
+ when "p"; "production"
30
+ when "d"; "development"
31
+ when "t"; "test"
32
+ else
33
+ ARGV.first || ENV['DAEMON_ENV'] || 'development'
34
+ end
35
+
36
+ puts "Loading #{ENV['DAEMON_ENV']} environment (daemon-kit #{DaemonKit::VERSION})"
37
+
38
+ exec "#{options[:irb]} #{libs} --simple-prompt"
@@ -20,6 +20,7 @@ module DaemonKit
20
20
 
21
21
  # Load the +config+.yml file from DAEMON_ROOT/config
22
22
  def load( config )
23
+ config = config.to_s
23
24
  config += '.yml' unless config =~ /\.yml$/
24
25
 
25
26
  path = File.join( DAEMON_ROOT, 'config', config )
@@ -0,0 +1,2 @@
1
+ # Load and configure our daemon process, without daemonizing
2
+ DaemonKit::Application.running!
@@ -0,0 +1,22 @@
1
+ require 'pathname'
2
+
3
+ class String
4
+
5
+ # Assuming the string is a file or path name, convert it into an
6
+ # absolute path.
7
+ def to_absolute_path
8
+ # Pathname is incompatible with Windows, but Windows doesn't have
9
+ # real symlinks so File.expand_path is safe.
10
+ if RUBY_PLATFORM =~ /(:?mswin|mingw)/
11
+ File.expand_path( self )
12
+
13
+ # Otherwise use Pathname#realpath which respects symlinks.
14
+ else
15
+ begin
16
+ File.expand_path( Pathname.new( self ).realpath.to_s )
17
+ rescue Errno::ENOENT
18
+ File.expand_path( Pathname.new( self ).cleanpath.to_s )
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + '/core_ext/string'
@@ -0,0 +1,485 @@
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") { run_locally(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 :shared_children, %w(log tmp)
46
+ _cset :current_dir, "current"
47
+
48
+ _cset(:releases_path) { File.join(deploy_to, version_dir) }
49
+ _cset(:shared_path) { File.join(deploy_to, shared_dir) }
50
+ _cset(:current_path) { File.join(deploy_to, current_dir) }
51
+ _cset(:release_path) { File.join(releases_path, release_name) }
52
+
53
+ _cset(:releases) { capture("ls -xt #{releases_path}").split.reverse }
54
+ _cset(:current_release) { File.join(releases_path, releases.last) }
55
+ _cset(:previous_release) { releases.length > 1 ? File.join(releases_path, releases[-2]) : nil }
56
+
57
+ _cset(:current_revision) { capture("cat #{current_path}/REVISION").chomp }
58
+ _cset(:latest_revision) { capture("cat #{current_release}/REVISION").chomp }
59
+ _cset(:previous_revision) { capture("cat #{previous_release}/REVISION").chomp }
60
+
61
+ _cset(:run_method) { fetch(:use_sudo, true) ? :sudo : :run }
62
+
63
+ # some tasks, like symlink, need to always point at the latest release, but
64
+ # they can also (occassionally) be called standalone. In the standalone case,
65
+ # the timestamped release_path will be inaccurate, since the directory won't
66
+ # actually exist. This variable lets tasks like symlink work either in the
67
+ # standalone case, or during deployment.
68
+ _cset(:latest_release) { exists?(:deploy_timestamped) ? release_path : current_release }
69
+
70
+ # =========================================================================
71
+ # These are helper methods that will be available to your recipes.
72
+ # =========================================================================
73
+
74
+ # Auxiliary helper method for the `deploy:check' task. Lets you set up your
75
+ # own dependencies.
76
+ def depend(location, type, *args)
77
+ deps = fetch(:dependencies, {})
78
+ deps[location] ||= {}
79
+ deps[location][type] ||= []
80
+ deps[location][type] << args
81
+ set :dependencies, deps
82
+ end
83
+
84
+ # Temporarily sets an environment variable, yields to a block, and restores
85
+ # the value when it is done.
86
+ def with_env(name, value)
87
+ saved, ENV[name] = ENV[name], value
88
+ yield
89
+ ensure
90
+ ENV[name] = saved
91
+ end
92
+
93
+ # logs the command then executes it locally.
94
+ # returns the command output as a string
95
+ def run_locally(cmd)
96
+ logger.trace "executing locally: #{cmd.inspect}" if logger
97
+ `#{cmd}`
98
+ end
99
+
100
+ # If a command is given, this will try to execute the given command, as
101
+ # described below. Otherwise, it will return a string for use in embedding in
102
+ # another command, for executing that command as described below.
103
+ #
104
+ # If :run_method is :sudo (or :use_sudo is true), this executes the given command
105
+ # via +sudo+. Otherwise is uses +run+. If :as is given as a key, it will be
106
+ # passed as the user to sudo as, if using sudo. If the :as key is not given,
107
+ # it will default to whatever the value of the :admin_runner variable is,
108
+ # which (by default) is unset.
109
+ #
110
+ # THUS, if you want to try to run something via sudo, and what to use the
111
+ # root user, you'd just to try_sudo('something'). If you wanted to try_sudo as
112
+ # someone else, you'd just do try_sudo('something', :as => "bob"). If you
113
+ # always wanted sudo to run as a particular user, you could do
114
+ # set(:admin_runner, "bob").
115
+ def try_sudo(*args)
116
+ options = args.last.is_a?(Hash) ? args.pop : {}
117
+ command = args.shift
118
+ raise ArgumentError, "too many arguments" if args.any?
119
+
120
+ as = options.fetch(:as, fetch(:admin_runner, nil))
121
+ via = fetch(:run_method, :sudo)
122
+ if command
123
+ invoke_command(command, :via => via, :as => as)
124
+ elsif via == :sudo
125
+ sudo(:as => as)
126
+ else
127
+ ""
128
+ end
129
+ end
130
+
131
+ # Same as sudo, but tries sudo with :as set to the value of the :runner
132
+ # variable (which defaults to "app").
133
+ def try_runner(*args)
134
+ options = args.last.is_a?(Hash) ? args.pop : {}
135
+ args << options.merge(:as => fetch(:runner, "app"))
136
+ try_sudo(*args)
137
+ end
138
+
139
+ # =========================================================================
140
+ # These are the tasks that are available to help with deploying web apps,
141
+ # and specifically, Rails applications. You can have cap give you a summary
142
+ # of them with `cap -T'.
143
+ # =========================================================================
144
+
145
+ namespace :deploy do
146
+ desc <<-DESC
147
+ Deploys your project. This calls both `update' and `restart'. Note that \
148
+ this will generally only work for applications that have already been deployed \
149
+ once. For a "cold" deploy, you'll want to take a look at the `deploy:cold' \
150
+ task, which handles the cold start specifically.
151
+ DESC
152
+ task :default do
153
+ update
154
+ restart
155
+ end
156
+
157
+ desc <<-DESC
158
+ Prepares one or more servers for deployment. Before you can use any \
159
+ of the Capistrano deployment tasks with your project, you will need to \
160
+ make sure all of your servers have been prepared with `cap deploy:setup'. When \
161
+ you add a new server to your cluster, you can easily run the setup task \
162
+ on just that server by specifying the HOSTS environment variable:
163
+
164
+ $ cap HOSTS=new.server.com deploy:setup
165
+
166
+ It is safe to run this task on servers that have already been set up; it \
167
+ will not destroy any deployed revisions or data.
168
+ DESC
169
+ task :setup, :except => { :no_release => true } do
170
+ dirs = [deploy_to, releases_path, shared_path]
171
+ dirs += shared_children.map { |d| File.join(shared_path, d) }
172
+ run "#{try_sudo} mkdir -p #{dirs.join(' ')} && #{try_sudo} chmod g+w #{dirs.join(' ')}"
173
+ end
174
+
175
+ desc <<-DESC
176
+ Copies your project and updates the symlink. It does this in a \
177
+ transaction, so that if either `update_code' or `symlink' fail, all \
178
+ changes made to the remote servers will be rolled back, leaving your \
179
+ system in the same state it was in before `update' was invoked. Usually, \
180
+ you will want to call `deploy' instead of `update', but `update' can be \
181
+ handy if you want to deploy, but not immediately restart your application.
182
+ DESC
183
+ task :update do
184
+ transaction do
185
+ update_code
186
+ symlink
187
+ end
188
+ end
189
+
190
+ desc <<-DESC
191
+ Copies your project to the remote servers. This is the first stage \
192
+ of any deployment; moving your updated code and assets to the deployment \
193
+ servers. You will rarely call this task directly, however; instead, you \
194
+ should call the `deploy' task (to do a complete deploy) or the `update' \
195
+ task (if you want to perform the `restart' task separately).
196
+
197
+ You will need to make sure you set the :scm variable to the source \
198
+ control software you are using (it defaults to :subversion), and the \
199
+ :deploy_via variable to the strategy you want to use to deploy (it \
200
+ defaults to :checkout).
201
+ DESC
202
+ task :update_code, :except => { :no_release => true } do
203
+ on_rollback { run "rm -rf #{release_path}; true" }
204
+ strategy.deploy!
205
+ finalize_update
206
+ end
207
+
208
+ desc <<-DESC
209
+ [internal] Touches up the released code. This is called by update_code \
210
+ after the basic deploy finishes. It assumes a Rails project was deployed, \
211
+ so if you are deploying something else, you may want to override this \
212
+ task with your own environment's requirements.
213
+
214
+ This task will make the release group-writable (if the :group_writable \
215
+ variable is set to true, which is the default). It will then set up \
216
+ symlinks to the shared directory for the :shared_children \
217
+ directories, and will lastly touch all assets in public/images, \
218
+ public/stylesheets, and public/javascripts so that the times are \
219
+ consistent (so that asset timestamping works). This touch process \
220
+ is only carried out if the :normalize_asset_timestamps variable is \
221
+ set to true, which is the default.
222
+ DESC
223
+ task :finalize_update, :except => { :no_release => true } do
224
+ run "chmod -R g+w #{latest_release}" if fetch(:group_writable, true)
225
+
226
+ # mkdir -p is making sure that the directories are there for some SCM's that don't
227
+ # save empty folders
228
+ dirs = fetch(:shared_children, [])
229
+ cmd = dirs.inject([]) do |c,d|
230
+ c.push "rm -rf #{latest_release}/#{d}"
231
+ c.push "ln -s #{shared_path}/#{d} #{latest_release}/#{d}"
232
+ c
233
+ end
234
+
235
+ run cmd.join( ' && ' )
236
+
237
+ if fetch(:normalize_asset_timestamps, false)
238
+ stamp = Time.now.utc.strftime("%Y%m%d%H%M.%S")
239
+ asset_paths = %w(images stylesheets javascripts).map { |p| "#{latest_release}/public/#{p}" }.join(" ")
240
+ run "find #{asset_paths} -exec touch -t #{stamp} {} ';'; true", :env => { "TZ" => "UTC" }
241
+ end
242
+
243
+ copy_configs
244
+ end
245
+
246
+ desc <<-DESC
247
+ Copies any shared configuration files from :deploy_to/config into \
248
+ the current release's config directory. Original files, if present, \
249
+ are renamed to the same name with .orig appended.
250
+
251
+ Specify a list of files by setting :config_files to an array in your \
252
+ deployment configuration.
253
+ DESC
254
+ task :copy_configs do
255
+ fetch(:config_files, []).each do |f|
256
+ run "[ -f #{release_path}/config/#{f} ]; mv #{release_path}/config/#{f} #{release_path}/config/#{f}.orig"
257
+ run "[ -f #{deploy_to}/config/#{f} ]; cp #{deploy_to}/config/#{f} #{release_path}/config/#{f}"
258
+ end
259
+ end
260
+
261
+ desc <<-DESC
262
+ Updates the symlink to the most recently deployed version. Capistrano works \
263
+ by putting each new release of your application in its own directory. When \
264
+ you deploy a new version, this task's job is to update the `current' symlink \
265
+ to point at the new version. You will rarely need to call this task \
266
+ directly; instead, use the `deploy' task (which performs a complete \
267
+ deploy, including `restart') or the 'update' task (which does everything \
268
+ except `restart').
269
+ DESC
270
+ task :symlink, :except => { :no_release => true } do
271
+ on_rollback do
272
+ if previous_release
273
+ run "rm -f #{current_path}; ln -s #{previous_release} #{current_path}; true"
274
+ else
275
+ logger.important "no previous release to rollback to, rollback of symlink skipped"
276
+ end
277
+ end
278
+
279
+ run "rm -f #{current_path} && ln -s #{latest_release} #{current_path}"
280
+ end
281
+
282
+ desc <<-DESC
283
+ Copy files to the currently deployed version. This is useful for updating \
284
+ files piecemeal, such as when you need to quickly deploy only a single \
285
+ file. Some files, such as updated templates, images, or stylesheets, \
286
+ might not require a full deploy, and especially in emergency situations \
287
+ it can be handy to just push the updates to production, quickly.
288
+
289
+ To use this task, specify the files and directories you want to copy as a \
290
+ comma-delimited list in the FILES environment variable. All directories \
291
+ will be processed recursively, with all files being pushed to the \
292
+ deployment servers.
293
+
294
+ $ cap deploy:upload FILES=templates,controller.rb
295
+
296
+ Dir globs are also supported:
297
+
298
+ $ cap deploy:upload FILES='config/apache/*.conf'
299
+ DESC
300
+ task :upload, :except => { :no_release => true } do
301
+ files = (ENV["FILES"] || "").split(",").map { |f| Dir[f.strip] }.flatten
302
+ abort "Please specify at least one file or directory to update (via the FILES environment variable)" if files.empty?
303
+
304
+ files.each { |file| top.upload(file, File.join(current_path, file)) }
305
+ end
306
+
307
+ desc <<-DESC
308
+ Restarts your application. This works by calling the bin/:application \
309
+ script under the current path with 'restart'
310
+
311
+ By default, this will be invoked via sudo as the `app' user. If \
312
+ you wish to run it as a different user, set the :runner variable to \
313
+ that user. If you are in an environment where you can't use sudo, set \
314
+ the :use_sudo variable to false:
315
+
316
+ set :use_sudo, false
317
+ DESC
318
+ task :restart, :except => { :no_release => true } do
319
+ try_runner "/usr/bin/env DAEMON_ENV=#{fetch(:daemon_env)} #{current_path}/bin/#{application} restart"
320
+ end
321
+
322
+ namespace :rollback do
323
+ desc <<-DESC
324
+ [internal] Points the current symlink at the previous revision.
325
+ This is called by the rollback sequence, and should rarely (if
326
+ ever) need to be called directly.
327
+ DESC
328
+ task :revision, :except => { :no_release => true } do
329
+ if previous_release
330
+ run "rm #{current_path}; ln -s #{previous_release} #{current_path}"
331
+ else
332
+ abort "could not rollback the code because there is no prior release"
333
+ end
334
+ end
335
+
336
+ desc <<-DESC
337
+ [internal] Removes the most recently deployed release.
338
+ This is called by the rollback sequence, and should rarely
339
+ (if ever) need to be called directly.
340
+ DESC
341
+ task :cleanup, :except => { :no_release => true } do
342
+ run "if [ `readlink #{current_path}` != #{current_release} ]; then rm -rf #{current_release}; fi"
343
+ end
344
+
345
+ desc <<-DESC
346
+ Rolls back to the previously deployed version. The `current' symlink will \
347
+ be updated to point at the previously deployed version, and then the \
348
+ current release will be removed from the servers. You'll generally want \
349
+ to call `rollback' instead, as it performs a `restart' as well.
350
+ DESC
351
+ task :code, :except => { :no_release => true } do
352
+ revision
353
+ cleanup
354
+ end
355
+
356
+ desc <<-DESC
357
+ Rolls back to a previous version and restarts. This is handy if you ever \
358
+ discover that you've deployed a lemon; `cap rollback' and you're right \
359
+ back where you were, on the previously deployed version.
360
+ DESC
361
+ task :default do
362
+ revision
363
+ restart
364
+ cleanup
365
+ end
366
+ end
367
+
368
+ desc <<-DESC
369
+ Clean up old releases. By default, the last 5 releases are kept on each \
370
+ server (though you can change this with the keep_releases variable). All \
371
+ other deployed revisions are removed from the servers. By default, this \
372
+ will use sudo to clean up the old releases, but if sudo is not available \
373
+ for your environment, set the :use_sudo variable to false instead.
374
+ DESC
375
+ task :cleanup, :except => { :no_release => true } do
376
+ count = fetch(:keep_releases, 5).to_i
377
+ if count >= releases.length
378
+ logger.important "no old releases to clean up"
379
+ else
380
+ logger.info "keeping #{count} of #{releases.length} deployed releases"
381
+
382
+ directories = (releases - releases.last(count)).map { |release|
383
+ File.join(releases_path, release) }.join(" ")
384
+
385
+ try_sudo "rm -rf #{directories}"
386
+ end
387
+ end
388
+
389
+ desc <<-DESC
390
+ Test deployment dependencies. Checks things like directory permissions, \
391
+ necessary utilities, and so forth, reporting on the things that appear to \
392
+ be incorrect or missing. This is good for making sure a deploy has a \
393
+ chance of working before you actually run `cap deploy'.
394
+
395
+ You can define your own dependencies, as well, using the `depend' method:
396
+
397
+ depend :remote, :gem, "tzinfo", ">=0.3.3"
398
+ depend :local, :command, "svn"
399
+ depend :remote, :directory, "/u/depot/files"
400
+ DESC
401
+ task :check, :except => { :no_release => true } do
402
+ dependencies = strategy.check!
403
+
404
+ other = fetch(:dependencies, {})
405
+ other.each do |location, types|
406
+ types.each do |type, calls|
407
+ if type == :gem
408
+ dependencies.send(location).command(fetch(:gem_command, "gem")).or("`gem' command could not be found. Try setting :gem_command")
409
+ end
410
+
411
+ calls.each do |args|
412
+ dependencies.send(location).send(type, *args)
413
+ end
414
+ end
415
+ end
416
+
417
+ if dependencies.pass?
418
+ puts "You appear to have all necessary dependencies installed"
419
+ else
420
+ puts "The following dependencies failed. Please check them and try again:"
421
+ dependencies.reject { |d| d.pass? }.each do |d|
422
+ puts "--> #{d.message}"
423
+ end
424
+ abort
425
+ end
426
+ end
427
+
428
+ desc <<-DESC
429
+ Deploys and starts a `cold' application. This is useful if you have not \
430
+ deployed your application before, or if your application is (for some \
431
+ other reason) not currently running. It will deploy the code, and then \
432
+ instead of invoking `deploy:restart', it will invoke `deploy:start' to \
433
+ fire up the application servers.
434
+ DESC
435
+ task :cold do
436
+ update
437
+ start
438
+ end
439
+
440
+ desc <<-DESC
441
+ Start the daemon processes. This will attempt to invoke a script \
442
+ in your application called `bin/:application', with the 'start' parameter.
443
+
444
+ By default, the script will be executed via sudo as the `app' user. If \
445
+ you wish to run it as a different user, set the :runner variable to \
446
+ that user. If you are in an environment where you can't use sudo, set \
447
+ the :use_sudo variable to false.
448
+ DESC
449
+ task :start do
450
+ try_runner "/usr/bin/env DAEMON_ENV=#{fetch(:daemon_env)} #{current_path}/bin/#{application} start"
451
+ end
452
+
453
+ desc <<-DESC
454
+ Stop the daemon processes. This will call 'bin/:application stop'.
455
+
456
+ By default, the script will be executed via sudo as the `app' user. If \
457
+ you wish to run it as a different user, set the :runner variable to \
458
+ that user. If you are in an environment where you can't use sudo, set \
459
+ the :use_sudo variable to false.
460
+ DESC
461
+ task :stop do
462
+ try_runner "/usr/bin/env DAEMON_ENV=#{fetch(:daemon_env)} #{current_path}/bin/#{application} stop"
463
+ end
464
+
465
+ namespace :pending do
466
+ desc <<-DESC
467
+ Displays the `diff' since your last deploy. This is useful if you want \
468
+ to examine what changes are about to be deployed. Note that this might \
469
+ not be supported on all SCM's.
470
+ DESC
471
+ task :diff, :except => { :no_release => true } do
472
+ system(source.local.diff(current_revision))
473
+ end
474
+
475
+ desc <<-DESC
476
+ Displays the commits since your last deploy. This is good for a summary \
477
+ of the changes that have occurred since the last deploy. Note that this \
478
+ might not be supported on all SCM's.
479
+ DESC
480
+ task :default, :except => { :no_release => true } do
481
+ from = source.next_revision(current_revision)
482
+ system(source.local.log(from))
483
+ end
484
+ end
485
+ end