5 WRITES_PID = [:start, :restart]
7 attr_accessor :name, :uid, :gid, :start, :stop, :restart
9 def initialize(options={})
17 # DON'T USE THIS INTERNALLY. Use the instance variable. -- Kev
18 # No really, trust me. Use the instance variable.
27 @pid_file = default_pid_file
44 def call_action(action)
45 command = send(action)
46 if command.kind_of?(String)
48 unless test(?d, God.pid_file_directory)
50 FileUtils.mkdir_p(God.pid_file_directory)
51 rescue Errno::EACCES => e
52 abort"Failed to create pid file directory: #{e.message}"
56 unless test(?w, God.pid_file_directory)
57 abort "The pid file directory (#{God.pid_file_directory}) is not writable by #{Etc.getlogin}"
61 # fork/exec to setuid/gid
64 ::Process::Sys.setgid(Etc.getgrnam(self.gid).gid) if self.gid
65 ::Process::Sys.setuid(Etc.getpwnam(self.uid).uid) if self.uid
68 STDIN.reopen "/dev/null"
69 STDOUT.reopen "/dev/null", "a"
76 if @tracking_pid or (@pid_file.nil? and WRITES_PID.include?(action))
77 File.open(default_pid_file, 'w') do |f|
82 @pid_file = default_pid_file
85 elsif command.kind_of?(Proc)
89 raise NotImplementedError
94 File.join(God.pid_file_directory, "#{self.name}.pid")