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.



49
50
51
52
53
# File 'lib/uae/common.rb', line 49

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

Instance Method Details

#to_sObject



83
84
85
# File 'lib/uae/common.rb', line 83

def to_s()
  @pid_file
end

Removes the created pidfile



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/uae/common.rb', line 56

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


78
79
80
81
# File 'lib/uae/common.rb', line 78

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

Removes the created pidfile upon receipt of the supplied signals



69
70
71
72
73
74
75
76
# File 'lib/uae/common.rb', line 69

def unlink_on_signals(*sigs)
  return unless @dirty

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