Class: UAE::PidFile

Inherits:
Object
  • Object
show all
Defined in:
lib/uae/common.rb

Defined Under Namespace

Classes: ProcessRunningError

Instance Method Summary collapse

Constructor Details

#initialize(pid_file, create_parents = true) ⇒ PidFile

Returns a new instance of PidFile.



41
42
43
44
45
# File 'lib/uae/common.rb', line 41

def initialize(pid_file, create_parents=true)
  @pid_file = pid_file
  @dirty = true
  write(create_parents)
end

Instance Method Details

#to_sObject



75
76
77
# File 'lib/uae/common.rb', line 75

def to_s()
  @pid_file
end

Removes the created pidfile



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/uae/common.rb', line 48

def unlink()
  return unless @dirty

  # Swallowing exception here is fine. Removing the pid files is a courtesy.
  begin
    File.unlink(@pid_file)
    @dirty = false
  rescue
  end
  self
end


70
71
72
73
# File 'lib/uae/common.rb', line 70

def unlink_at_exit()
  at_exit { unlink() }
  self
end

Removes the created pidfile upon receipt of the supplied signals



61
62
63
64
65
66
67
68
# File 'lib/uae/common.rb', line 61

def unlink_on_signals(*sigs)
  return unless @dirty

  sigs.each do |s|
    Signal.trap(s) { unlink() }
  end
  self
end