Module: SanJuan

Defined in:
lib/san_juan.rb

Constant Summary collapse

@@roles =
[]

Instance Method Summary collapse

Instance Method Details

#configuration_path(current_path, role) ⇒ Object



95
96
97
# File 'lib/san_juan.rb', line 95

def configuration_path(current_path, role)
  fetch(:god_config_path, nil) || "#{current_path}/config/god/#{role}.god"
end

#role(role, watches) ⇒ Object



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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/san_juan.rb', line 8

def role(role, watches)
  @@roles << role

  namespace :god do

    unless @meta_tasks_defined
      namespace :all do
        desc "Describe the status of the running tasks on each server"
        task :status do
          san_juan.roles.each { |role| send(role).send(:status) }
        end

        desc "Start god"
        task :start do
          san_juan.roles.each { |role| send(role).send(:start) }
        end

        desc "Reloading God Config"
        task :reload do
          san_juan.roles.each { |role| send(role).send(:reload) }
        end

        desc "Start god interactively"
        task :start_interactive do
          san_juan.roles.each { |role| send(role).send(:start_interactive) }
        end

        desc "Quit god, but not the processes it's monitoring"
        task :quit do
          san_juan.roles.each { |role| send(role).send(:quit) }
        end

        desc "Terminate god and all monitored processes"
        task :terminate do
          san_juan.roles.each { |role| send(role).send(:terminate) }
        end
      end
    end
    @meta_tasks_defined = true

    namespace role do
      desc "Start god"
      task :start, :roles => role do
        sudo "god -c #{san_juan.configuration_path(current_path, role)}"
      end

      desc "Start god interactively"
      task :start_interactive, :roles => role do
        sudo "god -c #{san_juan.configuration_path(current_path, role)} -D"
      end

      desc "Reload the god config file"
      task :reload, :roles => role do
        sudo "god load #{san_juan.configuration_path(current_path, role)}"
      end

      desc "Quit god, but not the processes it's monitoring"
      task :quit, :roles => role do
        sudo 'god quit'
      end

      desc "Terminate god and all monitored processes"
      task :terminate, :roles => role do
        sudo 'god terminate'
      end

      desc "Describe the status of the running tasks"
      task :status, :roles => role do
        sudo 'god status'
      end

      watches.each do |watch|
        namespace watch do
          %w(start restart stop unmonitor remove log).each do |command|
            desc "#{command.capitalize} #{watch}"
            task command, :roles => role do
              sudo "god #{command} #{watch}"
            end
          end
        end
      end

    end # end role namespace

  end #end god namespace
end

#rolesObject



4
5
6
# File 'lib/san_juan.rb', line 4

def roles
  @@roles
end