Module: Gap::Tasks

Defined in:
lib/gap/tasks.rb

Instance Method Summary collapse

Instance Method Details

#define_bulk_tasks(value) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gap/tasks.rb', line 9

def define_bulk_tasks value
  return unless value
  #gap dev start,restart,god
  %w(role set task).each {|key| value.delete(key)}
  %w(start stop reload restart).each do |com|
    task(com) do
      value.to_a.each do |app, commands|
        send(app)
        send(com) if commands["task"][com]
      end
    end
  end

  namespace :god do
    task(:config) do
      value.each do |app,commands|
        send(app)
        send(:config)
      end
    end
  end
end

#define_config_tasks(value) ⇒ Object



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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/gap/tasks.rb', line 32

def define_config_tasks value
  return unless value
  
  value.each do |attr,val|

    case attr
    when "role"
      val.each { |attr, val| role attr.to_sym, val } if val
    when "set"
      val.each { |attr, val| set attr, val } if val
    else

      val.each do |a, v|
        case a
        when "role"
          v.each { |attr, val| role attr.to_sym, val } if v
        when "set"
          v.each { |attr, val| set attr, val } if v
        when "task"
          if fetch :god

            task(attr) do
              namespace :god do
                task(:config) do
                  god_config_path = File.join( deploy_to, "config/god_#{application}_#{attr}.rb")
                  tmpl_path = File.expand_path 'tmpl.erb', File.dirname(__FILE__) 
                  god_config = Gap::GodErb.new(tmpl_path,application, attr, v.merge({"pid_file" => pid_file}))
                  upload( god_config.render, god_config_path, :via => :scp)
                  sudo "rvm-shell '#{rvm_god_string}' -c 'god load #{god_config_path}'"
                end
              end

              v.each do |name, command|
                if ["start","stop","restart"].include?(name)
                  task(name) do
                    sudo "rvm-shell '#{rvm_god_string}' -c 'god #{name} #{attr}_#{application}'"
                  end
                else
                  task(name) do
                    sudo_run command 
                  end
                end
              end
            end
          else
            task(attr) do
              v.each do |name, command|
                task(name) { sudo_run command }
              end
            end
          end
        else
        end
      end
    end
  end
end

#init_valObject



4
5
6
7
# File 'lib/gap/tasks.rb', line 4

def init_val
  set :rvm_ruby_string, nil
  set :god_config_path, nil
end