Module: Daemon::PidFile

Defined in:
lib/serverside/daemon.rb

Overview

Stores and recalls the daemon pid.

Class Method Summary collapse

Class Method Details

.recall(daemon) ⇒ Object

Recalls the daemon pid. If the pid can not be recalled, an error is raised.



22
23
24
25
26
# File 'lib/serverside/daemon.rb', line 22

def self.recall(daemon)
  IO.read(daemon.pid_fn).to_i
rescue
  raise 'Pid not found. Is the daemon started?'
end

.remove(daemon) ⇒ Object



28
29
30
# File 'lib/serverside/daemon.rb', line 28

def self.remove(daemon)
  FileUtils.rm(daemon.pid_fn) if File.file?(daemon.pid_fn)
end

.store(daemon, pid) ⇒ Object

Stores the daemon pid.



16
17
18
# File 'lib/serverside/daemon.rb', line 16

def self.store(daemon, pid)
  File.open(daemon.pid_fn, 'w') {|f| f << pid}
end