Module: MultiDaemons::PidStore

Defined in:
lib/multi_daemons/pid_store.rb

Class Method Summary collapse

Class Method Details

.cleanup(file_names) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/multi_daemons/pid_store.rb', line 19

def self.cleanup(file_names)
  file_names = [file_names].flatten
  file_names.each do |file_name|
    next unless File.exist?(file_name)

    FileUtils.rm(file_name)
  end
end

.get(file_name) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/multi_daemons/pid_store.rb', line 7

def self.get(file_name)
  [].tap do |pids|
    unless File.exist?(file_name)
      pids << nil
      next
    end
    File.read(file_name).each_line do |line|
      pids << line.to_i
    end
  end
end

.store(file_name, pid) ⇒ Object



3
4
5
# File 'lib/multi_daemons/pid_store.rb', line 3

def self.store(file_name, pid)
  File.open(file_name, 'a') { |f| f << "#{pid}\n" }
end