Class: EventHub::Components::Pidfile
- Inherits:
-
Object
- Object
- EventHub::Components::Pidfile
- Defined in:
- lib/eventhub/components/pid_file.rb
Instance Attribute Summary collapse
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
Instance Method Summary collapse
-
#delete ⇒ Object
Try to delete file, ignore all errors.
-
#initialize(file_name) ⇒ Pidfile
constructor
A new instance of Pidfile.
-
#read ⇒ Object
Read the PID from the file.
-
#write(pid = Process.pid) ⇒ Object
write the pid to the file specified in the initializer defaults to Process.pid.
Constructor Details
#initialize(file_name) ⇒ Pidfile
Returns a new instance of Pidfile.
3 4 5 |
# File 'lib/eventhub/components/pid_file.rb', line 3 def initialize(file_name) @file_name = file_name end |
Instance Attribute Details
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
2 3 4 |
# File 'lib/eventhub/components/pid_file.rb', line 2 def file_name @file_name end |
Instance Method Details
#delete ⇒ Object
Try to delete file, ignore all errors
15 16 17 18 19 |
# File 'lib/eventhub/components/pid_file.rb', line 15 def delete File.delete(file_name) rescue # ignore end |
#read ⇒ Object
Read the PID from the file
22 23 24 25 26 |
# File 'lib/eventhub/components/pid_file.rb', line 22 def read File.read(file_name) rescue Errno::ENOENT # ignore, will return nil end |
#write(pid = Process.pid) ⇒ Object
write the pid to the file specified in the initializer defaults to Process.pid
9 10 11 12 |
# File 'lib/eventhub/components/pid_file.rb', line 9 def write(pid = Process.pid) FileUtils.makedirs(File.dirname(file_name)) IO.write(file_name, pid.to_s) end |