public
Rubygem
Description: Sprinkle is a software provisioning tool you can use to build remote servers with. eg. to install a Rails or Merb stack on a brand new slice directly after its been created
Homepage: http://sprinkle.rubyforge.org/
Clone URL: git://github.com/crafterm/sprinkle.git
sprinkle / lib / sprinkle / actors / vlad.rb
100644 66 lines (58 sloc) 1.96 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
module Sprinkle
  module Actors
    # = Vlad Delivery Method
    #
    # Vlad is one of the delivery method options available out of the
    # box with Sprinkle. If you have the vlad the deployer gem install, you
    # may use this delivery. The only configuration option available, and
    # which is mandatory to include is +script+. An example:
    #
    # deployment do
    # delivery :vlad do
    # script 'deploy'
    # end
    # end
    #
    # script is given a list of files which capistrano will include and load.
    # These recipes are mainly to set variables such as :user, :password, and to
    # set the app domain which will be sprinkled.
    class Vlad
      require 'vlad'
      attr_accessor :loaded_recipes #:nodoc:
 
      def initialize(&block) #:nodoc:
        self.instance_eval &block if block
      end
 
      # Defines a script file which will be included by vlad. Use these
      # script files to set vlad specific configurations. Multiple scripts
      # may be specified through multiple script calls, an example:
      #
      # deployment do
      # delivery :vlad do
      # script 'deploy'
      # script 'magic_beans'
      # end
      # end
      def script(name)
        @loaded_recipes ||= []
        self.load name
        @loaded_recipes << script
      end
 
      def process(name, commands, roles, suppress_and_return_failures = false) #:nodoc:
        commands = commands.join ' && ' if commands.is_a? Array
        t = remote_task(task_sym(name), :roles => roles) { run commands }
        
        begin
          t.invoke
          return true
        rescue ::Vlad::CommandFailedError => e
          return false if suppress_and_return_failures
          
          # Reraise error if we're not suppressing it
          raise
        end
      end
 
      private
 
        def task_sym(name)
          "install_#{name.to_task_name}".to_sym
        end
    end
  end
end