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



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

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
94
# File 'lib/san_juan.rb', line 8

def role(role, watches)
  via = fetch(:run_method, :sudo)
  @@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
        invoke_command "god -c #{san_juan.configuration_path(current_path, role)}", :via => via
      end

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

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

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

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

      desc "Describe the status of the running tasks"
      task :status, :roles => role do
        invoke_command 'god status', :via => via
      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
              invoke_command "god #{command} #{watch}", :via => via
            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