Class: Quebert::Support::PidFile

Inherits:
Object
  • Object
show all
Defined in:
lib/quebert/support/pid_file.rb

Overview

Deal with all of our pid file stuff

Constant Summary collapse

ProcessRunning =
Class.new(RuntimeError)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ PidFile

Returns a new instance of PidFile.



11
12
13
# File 'lib/quebert/support/pid_file.rb', line 11

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/quebert/support/pid_file.rb', line 7

def path
  @path
end

Class Method Details

.read(file) ⇒ Object

Read pids and turn them into ints



20
21
22
23
24
25
26
# File 'lib/quebert/support/pid_file.rb', line 20

def self.read(file)
  if File.file?(file) && pid = File.read(file)
    pid.to_i
  else
    nil
  end
end

.running?(pid) ⇒ Boolean

Tells us if a current process is running

Returns:

  • (Boolean)


29
30
31
32
33
34
35
# File 'lib/quebert/support/pid_file.rb', line 29

def self.running?(pid)
  Process.getpgid(pid) != -1
rescue Errno::EPERM
  true
rescue Errno::ESRCH
  false
end

Instance Method Details

#write!Object



15
16
17
# File 'lib/quebert/support/pid_file.rb', line 15

def write!
  remove_stale and write
end