This module controls the storage and retrieval of process id files.
Remove the pid file if the daemon is not running
# File lib/rexec/daemon/process_file.rb, line 54 def self.cleanup(daemon) clear(daemon) unless running(daemon) end
Removes the pid saved for a particular daemon
# File lib/rexec/daemon/process_file.rb, line 36 def self.clear(daemon) if File.exist? daemon.process_file_path FileUtils.rm(daemon.process_file_path) end end
Retrieves the pid for the given daemon
# File lib/rexec/daemon/process_file.rb, line 31 def self.recall(daemon) IO.read(daemon.process_file_path).to_i rescue nil end
Checks whether the daemon is running by checking the saved pid and checking the corresponding process
# File lib/rexec/daemon/process_file.rb, line 43 def self.running(daemon) pid = recall(daemon) return false if pid == nil gpid = Process.getpgid(pid) rescue nil return gpid != nil ? true : false end
This function returns the status of the daemon. This can be one of :running, :unknown (pid file exists but no corresponding process can be found) or :stopped.
# File lib/rexec/daemon/process_file.rb, line 60 def self.status(daemon) if File.exist? daemon.process_file_path return ProcessFile.running(daemon) ? :running : :unknown else return :stopped end end
Generated with the Darkfish Rdoc Generator 2.