Class: Flamingo::Daemon::PidFile

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

Instance Method Summary collapse

Instance Method Details

#deleteObject



30
31
32
# File 'lib/flamingo/daemon/pid_file.rb', line 30

def delete
  File.delete(file) if file
end

#exists?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/flamingo/daemon/pid_file.rb', line 9

def exists?
  File.exist?(file) rescue false
end

#readObject



5
6
7
# File 'lib/flamingo/daemon/pid_file.rb', line 5

def read
  File.read(file).strip rescue nil
end

#running?Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/flamingo/daemon/pid_file.rb', line 13

def running?
  #PHD The code below borrowed from the daemons gem
  return false unless exists?
  # Check if process is in existence
  # The simplest way to do this is to send signal '0'
  # (which is a single system call) that doesn't actually
  # send a signal
  begin
    Process.kill(0, pid)
    return true
  rescue Errno::ESRCH
    return false
  rescue ::Exception   # for example on EPERM (process exists but does not belong to us)
    return true
  end
end

#write(pid) ⇒ Object



34
35
36
37
38
39
# File 'lib/flamingo/daemon/pid_file.rb', line 34

def write(pid)
  File.open(file,"w") {|f| f.write("#{pid}\n") }
  true
rescue 
  false
end