Class: NginxStage::PidFile

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

Overview

A class to handle a PID file

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pid_path) ⇒ PidFile

Returns a new instance of PidFile.

Raises:



15
16
17
18
19
20
# File 'lib/nginx_stage/pid_file.rb', line 15

def initialize(pid_path)
  @pid_path = pid_path
  raise MissingPidFile, "missing PID file: #{pid_path}" unless File.exist?(pid_path)
  raise InvalidPidFile, "invalid PID file: #{pid_path}" unless File.file?(pid_path)
  @pid = File.read(pid_path).to_i
end

Instance Attribute Details

#pidInteger (readonly)

Process id that describes this object



10
11
12
# File 'lib/nginx_stage/pid_file.rb', line 10

def pid
  @pid
end

#pid_pathString (readonly)

Path of the PID file



6
7
8
# File 'lib/nginx_stage/pid_file.rb', line 6

def pid_path
  @pid_path
end

Instance Method Details

#running_process?Boolean

Whether the corresponding pid is a running process



24
25
26
27
28
29
# File 'lib/nginx_stage/pid_file.rb', line 24

def running_process?
  Process.getpgid @pid
  true
rescue Errno::ESRCH
  false
end

#to_sString

Convert object to string



33
34
35
# File 'lib/nginx_stage/pid_file.rb', line 33

def to_s
  pid_path.to_s
end