Class: Pigeon::Pidfile
- Inherits:
-
Object
- Object
- Pigeon::Pidfile
- Defined in:
- lib/pigeon/pidfile.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Properties ===========================================================.
Instance Method Summary collapse
- #create!(pid = nil) ⇒ Object
- #exist? ⇒ Boolean
-
#initialize(path) ⇒ Pidfile
constructor
Instance Methods =====================================================.
- #pid ⇒ Object
- #remove! ⇒ Object
- #running ⇒ Object
- #running? ⇒ Boolean
Constructor Details
#initialize(path) ⇒ Pidfile
Instance Methods =====================================================
12 13 14 15 16 |
# File 'lib/pigeon/pidfile.rb', line 12 def initialize(path) @path = path @path += '.pid' unless (@path.match(/\./)) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Properties ===========================================================
6 7 8 |
# File 'lib/pigeon/pidfile.rb', line 6 def path @path end |
Instance Method Details
#create!(pid = nil) ⇒ Object
39 40 41 42 43 |
# File 'lib/pigeon/pidfile.rb', line 39 def create!(pid = nil) open(@path, 'w') do |fh| fh.puts(pid || $$) end end |
#exist? ⇒ Boolean
51 52 53 |
# File 'lib/pigeon/pidfile.rb', line 51 def exist? File.exist?(@path) end |
#pid ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/pigeon/pidfile.rb', line 30 def pid contents = File.read(@path) contents and contents.to_i rescue Errno::ENOENT nil end |
#remove! ⇒ Object
45 46 47 48 49 |
# File 'lib/pigeon/pidfile.rb', line 45 def remove! return unless (exist?) File.unlink(@path) end |
#running ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/pigeon/pidfile.rb', line 22 def running _pid = self.pid (_pid and Process.kill(0, _pid)) ? _pid : nil rescue Errno::ESRCH nil end |
#running? ⇒ Boolean
18 19 20 |
# File 'lib/pigeon/pidfile.rb', line 18 def running? !!self.running end |