class Process::Daemon::ProcessFile

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

Public Class Methods

cleanup(daemon) click to toggle source

Remove the pid file if the daemon is not running

# File lib/process/daemon/process_file.rb, line 56
def self.cleanup(daemon)
        clear(daemon) unless running(daemon)
end
clear(daemon) click to toggle source

Removes the pid saved for a particular daemon

# File lib/process/daemon/process_file.rb, line 38
def self.clear(daemon)
        if File.exist? daemon.process_file_path
                FileUtils.rm(daemon.process_file_path)
        end
end
recall(daemon) click to toggle source

Retrieves the pid for the given daemon

# File lib/process/daemon/process_file.rb, line 33
def self.recall(daemon)
        File.read(daemon.process_file_path).to_i rescue nil
end
running(daemon) click to toggle source

Checks whether the daemon is running by checking the saved pid and checking the corresponding process

# File lib/process/daemon/process_file.rb, line 45
def self.running(daemon)
        pid = recall(daemon)

        return false if pid == nil

        gpid = Process.getpgid(pid) rescue nil

        return gpid != nil ? true : false
end
status(daemon) click to toggle source

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/process/daemon/process_file.rb, line 62
def self.status(daemon)
        if File.exist? daemon.process_file_path
                return ProcessFile.running(daemon) ? :running : :unknown
        else
                return :stopped
        end
end
store(daemon, pid) click to toggle source

Saves the pid for the given daemon

# File lib/process/daemon/process_file.rb, line 28
def self.store(daemon, pid)
        File.write(daemon.process_file_path, pid)
end