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.
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_s ⇒ Object
75 76 77 |
# File 'lib/uae/common.rb', line 75 def to_s() @pid_file end |
#unlink ⇒ Object
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 |
#unlink_at_exit ⇒ Object
70 71 72 73 |
# File 'lib/uae/common.rb', line 70 def unlink_at_exit() at_exit { unlink() } self end |
#unlink_on_signals(*sigs) ⇒ Object
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 |