model/application.rb in ruby-station-0.0.4 vs model/application.rb in ruby-station-0.1.0

- old
+ new

@@ -1,10 +1,7 @@ -require 'ramaze/tool/bin' - class Application include DataMapper::Resource - include Ramaze::Tool::Bin::Helpers property :id, Serial property :pid, Integer property :port, Integer property :name, String @@ -18,34 +15,32 @@ script_path, "--port", self.port.to_s, "--data-dir", data_dir, ].join(" ") - self.pid = fork { - exec(cmd) + self.pid = Servant.watch(cmd){ + stopped } self.save end def stop - return unless self.pid - - Process.kill("INT", self.pid) - if is_running?(self.pid) - sleep 2 - Ramaze::Log.warn "Process #{self.pid} did not die, forcing it with -9" - Process.kill(9, self.pid) + if self.pid + Servant.kill(self.pid) + stopped end - - self.pid = nil - self.save end def full_name "#{self.name}-#{self.version}" end private + + def stopped + self.pid = nil + self.save + end def script_path File.join(Conf.gem_dir, "gems", full_name, "main.rb") end