1 $:.unshift File.dirname(__FILE__) # For use/testing when no gem is installed
8 require 'god/system/process'
10 require 'god/behavior'
11 require 'god/behaviors/clean_pid_file'
13 require 'god/condition'
14 require 'god/conditions/timeline'
15 require 'god/conditions/process_running'
16 require 'god/conditions/process_exits'
17 require 'god/conditions/tries'
18 require 'god/conditions/memory_usage'
19 require 'god/conditions/cpu_usage'
20 require 'god/conditions/always'
22 require 'god/reporter'
30 require 'god/event_handler'
31 require 'god/registry'
36 $:.unshift File.join(File.dirname(__FILE__), *%w[.. ext god])
44 God::EventHandler.load
50 attr_accessor :inited, :host, :port
56 attr_accessor :watches, :groups
67 # yield to the config file
68 yield self if block_given?
71 self.server = Server.new(self.host, self.port)
73 # init has been executed
77 # Where pid files created by god will go by default
78 def self.pid_file_directory
79 @pid_file_directory ||= '/var/run/god'
82 def self.pid_file_directory=(value)
83 @pid_file_directory = value
86 # Instantiate a new, empty Watch object and pass it to the mandatory
87 # block. The attributes of the watch will be set by the configuration
95 # ensure the new watch has a unique name
96 if self.watches[w.name] || self.groups[w.name]
97 abort "Watch name '#{w.name}' already used for a Watch or Group"
100 # add to list of watches
101 self.watches[w.name] = w
103 # add to group if specified
105 # ensure group name hasn't been used for a watch already
106 if self.watches[w.group]
107 abort "Group name '#{w.group}' already used for a Watch"
110 self.groups[w.group] ||= []
111 self.groups[w.group] << w
118 def self.control(name, command)
119 # get the list of watches
120 watches = Array(self.watches[name] || self.groups[name])
124 when "start", "monitor"
125 watches.each { |w| w.monitor }
127 watches.each { |w| w.move(:restart) }
129 watches.each { |w| w.unmonitor.action(:stop) }
131 watches.each { |w| w.unmonitor }
133 raise InvalidCommandError.new
140 # make sure there's something to do
141 if self.watches.nil? || self.watches.empty?
142 abort "You must specify at least one watch!"
145 # start event handler system
146 EventHandler.start if EventHandler.loaded?
148 # start the timer system
151 # start monitoring any watches set to autostart
152 self.watches.values.each { |w| w.monitor if w.autostart? }
154 # join the timer thread so we don't exit
163 Dir[glob].each do |f|