class Process::Daemon::ProcessFile

This module controls the storage and retrieval of process id files.

def self.cleanup(daemon)

Remove the pid file if the daemon is not running
def self.cleanup(daemon)
	clear(daemon) unless running(daemon)
end

def self.clear(daemon)

Removes the pid saved for a particular daemon
def self.clear(daemon)
	if File.exist? daemon.process_file_path
		FileUtils.rm(daemon.process_file_path)
	end
end

def self.recall(daemon)

Retrieves the pid for the given daemon
def self.recall(daemon)
	File.read(daemon.process_file_path).to_i rescue nil
end

def self.running(daemon)

Checks whether the daemon is running by checking the saved pid and checking the corresponding process
def self.running(daemon)
	pid = recall(daemon)
	return false if pid == nil
	gpid = Process.getpgid(pid) rescue nil
	return gpid != nil ? true : false
end

def self.status(daemon)

corresponding process can be found) or +:stopped+.
This function returns the status of the daemon. This can be one of +:running+, +:unknown+ (pid file exists but no
def self.status(daemon)
	if File.exist? daemon.process_file_path
		return ProcessFile.running(daemon) ? :running : :unknown
	else
		return :stopped
	end
end

def self.store(daemon, pid)

Saves the pid for the given daemon
def self.store(daemon, pid)
	File.write(daemon.process_file_path, pid)
end