public
Description: Capistrano Recipies for God
Homepage: http://github.com/jnewland/san_juan
Clone URL: git://github.com/jnewland/san_juan.git
san_juan / lib / san_juan.rb
100644 95 lines (76 sloc) 2.61 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
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
95
module SanJuan
  @@roles = []
 
  def roles
    @@roles
  end
 
  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, :roles => san_juan.roles do
            san_juan.roles.each { |role| send(role, :status) }
          end
 
          desc "Start god"
          task :start do
            san_juan.roles.each { |role| send(role, :start) }
          end
 
          desc "Reloading God Config"
          task :reload do
            san_juan.roles.each { |role| send(role, :reload) }
          end
 
          desc "Start god interactively"
          task :start_interactive do
            san_juan.roles.each { |role| send(role, :start_interactive) }
          end
 
          desc "Quit god, but not the processes it's monitoring"
          task :quit do
            san_juan.roles.each { |role| send(role, :quit) }
          end
 
          desc "Terminate god and all monitored processes"
          task :terminate do
            san_juan.roles.each { |role| send(role, :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
 
        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
 
  def configuration_path(current_path, role)
    fetch(:god_config_path, nil) || "#{current_path}/config/god/#{role}.god"
  end
 
end
Capistrano.plugin :san_juan, SanJuan