Skip to content

Fix PidFile.pid to use the default pidfile path. #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/pidfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,30 @@ def locktime
# Class Methods
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=#

# Return the default pidfile path
def self.default_pidfile
File.join(DEFAULT_OPTIONS[:piddir], DEFAULT_OPTIONS[:pidfile])
end

# Returns the PID, if any, of the instantiating process
def self.pid(path=nil)
path ||= default_pidfile
if pidfile_exists?(path)
open(path, 'r').read.to_i
end
end

# class method for determining the existence of pidfile
def self.pidfile_exists?(path=nil)
path ||= File.join(DEFAULT_OPTIONS[:piddir], DEFAULT_OPTIONS[:pidfile])
path ||= default_pidfile

File.exists?(path)
end

# boolean stating whether the calling program is already running
def self.running?(path=nil)
calling_pid = nil
path ||= File.join(DEFAULT_OPTIONS[:piddir], DEFAULT_OPTIONS[:pidfile])
path ||= default_pidfile

if pidfile_exists?(path)
calling_pid = pid(path)
Expand Down