lib/god/watch.rb in god-0.3.0 vs lib/god/watch.rb in god-0.4.0

- old
+ new

@@ -15,11 +15,11 @@ def autostart?; @autostart; end extend Forwardable def_delegators :@process, :name, :uid, :gid, :start, :stop, :restart, :name=, :uid=, :gid=, :start=, :stop=, :restart=, - :pid_file, :pid_file= + :pid_file, :pid_file=, :log, :log=, :alive? # api attr_accessor :behaviors, :metrics # internal @@ -44,10 +44,20 @@ # mutex self.mutex = Mutex.new end + def valid? + @process.valid? + end + + ########################################################################### + # + # Behavior + # + ########################################################################### + def behavior(kind) # create the behavior begin b = Behavior.generate(kind, self) rescue NoSuchBehaviorError => e @@ -134,11 +144,11 @@ # Move from one state to another def move(to_state) msg = "#{self.name} move '#{self.state}' to '#{to_state}'" Syslog.debug(msg) - puts msg + LOG.log(self, :info, msg) # cleanup from current state from_state = self.state if from_state self.metrics[from_state].each { |m| m.disable } @@ -165,27 +175,32 @@ end def action(a, c = nil) case a when :start - Syslog.debug(self.start.to_s) - puts self.start.to_s + msg = "#{self.name} start: #{self.start.to_s}" + Syslog.debug(msg) + LOG.log(self, :info, msg) call_action(c, :start) sleep(self.start_grace + self.grace) when :restart if self.restart - Syslog.debug(self.restart.to_s) - puts self.restart + msg = "#{self.name} restart: #{self.restart.to_s}" + Syslog.debug(msg) + LOG.log(self, :info, msg) call_action(c, :restart) else action(:stop, c) action(:start, c) end sleep(self.restart_grace + self.grace) when :stop - Syslog.debug(self.stop.to_s) - puts self.stop.to_s + if self.stop + msg = "#{self.name} stop: #{self.stop.to_s}" + Syslog.debug(msg) + LOG.log(self, :info, msg) + end call_action(c, :stop) sleep(self.stop_grace + self.grace) end end @@ -207,9 +222,13 @@ to.instance_of?(Symbol) ? {true => to} : to end def register! God.registry.add(@process) + end + + def unregister! + God.registry.remove(@process) end end end \ No newline at end of file