lib/god/process.rb in eric-god-0.7.7 vs lib/god/process.rb in eric-god-0.7.10

- old
+ new

@@ -1,19 +1,20 @@ module God class Process WRITES_PID = [:start, :restart] - attr_accessor :name, :uid, :gid, :log, :start, :stop, :restart, :unix_socket, :chroot, :env + attr_accessor :name, :uid, :gid, :log, :log_cmd, :start, :stop, :restart, :unix_socket, :chroot, :env def initialize self.log = '/dev/null' @pid_file = nil @tracking_pid = true @user_log = false @pid = nil @unix_socket = nil + @log_cmd = nil end def alive? if self.pid System::Process.new(self.pid).exists? @@ -26,14 +27,15 @@ pid = fork do uid_num = Etc.getpwnam(self.uid).uid if self.uid gid_num = Etc.getgrnam(self.gid).gid if self.gid ::Dir.chroot(self.chroot) if self.chroot + ::Process.groups = [gid_num] if self.gid ::Process::Sys.setgid(gid_num) if self.gid ::Process::Sys.setuid(uid_num) if self.uid - File.writable?(file) ? exit(0) : exit(1) + File.writable?(file_in_chroot(file)) ? exit(0) : exit(1) end wpid, status = ::Process.waitpid2(pid) status.exitstatus == 0 ? true : false end @@ -155,10 +157,19 @@ else @pid end end + # Send the given signal to this process. + # + # Returns nothing + def signal(sig) + sig = sig.to_i if sig.to_i != 0 + applog(self, :info, "#{self.name} sending signal '#{sig}' to pid #{self.pid}") + ::Process.kill(sig, self.pid) rescue nil + end + def start! call_action(:start) end def stop! @@ -265,15 +276,20 @@ uid_num = Etc.getpwnam(self.uid).uid if self.uid gid_num = Etc.getgrnam(self.gid).gid if self.gid ::Dir.chroot(self.chroot) if self.chroot ::Process.setsid + ::Process.groups = [gid_num] if self.gid ::Process::Sys.setgid(gid_num) if self.gid ::Process::Sys.setuid(uid_num) if self.uid Dir.chdir "/" $0 = command STDIN.reopen "/dev/null" - STDOUT.reopen file_in_chroot(self.log), "a" + if self.log_cmd + STDOUT.reopen IO.popen(self.log_cmd, "a") + else + STDOUT.reopen file_in_chroot(self.log), "a" + end STDERR.reopen STDOUT # close any other file descriptors 3.upto(256){|fd| IO::new(fd).close rescue nil}