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/memory_usage'
18 require 'god/conditions/cpu_usage'
19 require 'god/conditions/always'
21 require 'god/reporter'
29 require 'god/event_handler'
30 require 'god/registry'
35 $:.unshift File.join(File.dirname(__FILE__), *%w[.. ext god])
43 God::EventHandler.load
49 attr_accessor :inited, :host, :port
55 attr_accessor :watches, :groups
66 # yield to the config file
67 yield self if block_given?
70 self.server = Server.new(self.host, self.port)
72 # init has been executed
76 # Where pid files created by god will go by default
77 def self.pid_file_directory
78 @pid_file_directory ||= '/var/run/god'
81 def self.pid_file_directory=(value)
82 @pid_file_directory = value
85 # Instantiate a new, empty Watch object and pass it to the mandatory
86 # block. The attributes of the watch will be set by the configuration
94 # ensure the new watch has a unique name
95 if self.watches[w.name] || self.groups[w.name]
96 abort "Watch name '#{w.name}' already used for a Watch or Group"
99 # add to list of watches
100 self.watches[w.name] = w
102 # add to group if specified
104 # ensure group name hasn't been used for a watch already
105 if self.watches[w.group]
106 abort "Group name '#{w.group}' already used for a Watch"
109 self.groups[w.group] ||= []
110 self.groups[w.group] << w.name
117 def self.control(name, command)
118 # get the list of watches
119 watches = Array(self.watches[name] || self.groups[name])
123 when "start", "monitor"
124 watches.each { |w| w.monitor }
126 watches.each { |w| w.move(:restart) }
128 watches.each { |w| w.unmonitor.action(:stop) }
130 watches.each { |w| w.unmonitor }
132 raise InvalidCommandError.new
139 # make sure there's something to do
140 if self.watches.nil? || self.watches.empty?
141 abort "You must specify at least one watch!"
144 # start event handler system
145 EventHandler.start if EventHandler.loaded?
147 # start the timer system
150 # start monitoring any watches set to autostart
151 self.watches.values.each { |w| w.monitor if w.autostart? }
153 # join the timer thread so we don't exit
162 Dir[glob].each do |f|