Class: UAE::PidFile
- Inherits:
-
Object
- Object
- UAE::PidFile
- Defined in:
- lib/uae/common.rb
Defined Under Namespace
Classes: ProcessRunningError
Instance Method Summary collapse
-
#initialize(pid_file, create_parents = true) ⇒ PidFile
constructor
A new instance of PidFile.
- #to_s ⇒ Object
-
#unlink ⇒ Object
Removes the created pidfile.
- #unlink_at_exit ⇒ Object
-
#unlink_on_signals(*sigs) ⇒ Object
Removes the created pidfile upon receipt of the supplied signals.
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_s ⇒ Object
83 84 85 |
# File 'lib/uae/common.rb', line 83 def to_s() @pid_file end |
#unlink ⇒ Object
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 |
#unlink_at_exit ⇒ Object
78 79 80 81 |
# File 'lib/uae/common.rb', line 78 def unlink_at_exit() at_exit { unlink() } self end |
#unlink_on_signals(*sigs) ⇒ Object
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 |