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 =====================================================.
- #remove! ⇒ Object
- #running ⇒ Object
- #running? ⇒ Boolean
- #saved_pid ⇒ Object
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
36 37 38 39 40 |
# File 'lib/pigeon/pidfile.rb', line 36 def create!(pid = nil) open(@path, 'w') do |fh| fh.puts(pid || $$) end end |
#exist? ⇒ Boolean
48 49 50 |
# File 'lib/pigeon/pidfile.rb', line 48 def exist? File.exist?(@path) end |
#remove! ⇒ Object
42 43 44 45 46 |
# File 'lib/pigeon/pidfile.rb', line 42 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.saved_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 |
#saved_pid ⇒ Object
30 31 32 33 34 |
# File 'lib/pigeon/pidfile.rb', line 30 def saved_pid File.read(@path).to_i rescue Errno::ENOENT nil end |