Sha256: 9b5c7e780aeea442a9cd75cc8445aeeb5bb00cdfdbb8270c4418197766332aea

Contents?: true

Size: 936 Bytes

Versions: 32

Compression:

Stored size: 936 Bytes

Contents

class Pigeon::Pidfile
  # == Constants ============================================================

  # == Properties ===========================================================
  
  attr_reader :path 
  
  # == Class Methods ========================================================
  
  # == Instance Methods =====================================================
  
  def initialize(path)
    @path = path
    
    @path += '.pid' unless (@path.match(/\./))
  end
  
  def running?
    !!self.running
  end
  
  def running
    pid = self.saved_pid

    (pid and Process.kill(0, pid)) ? pid : nil
  rescue Errno::ESRCH
    nil
  end
  
  def saved_pid
    File.read(@path).to_i
  rescue Errno::ENOENT
    nil
  end
  
  def create!(pid = nil)
    open(@path, 'w') do |fh|
      fh.puts(pid || $$)
    end
  end
  
  def remove!
    return unless (exist?)

    File.unlink(@path)
  end
  
  def exist?
    File.exist?(@path)
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
pigeon-1.0.2 lib/pigeon/pidfile.rb
pigeon-1.0.1 lib/pigeon/pidfile.rb
pigeon-1.0.0 lib/pigeon/pidfile.rb
pigeon-0.9.3 lib/pigeon/pidfile.rb
pigeon-0.9.2.1 lib/pigeon/pidfile.rb
pigeon-0.9.2 lib/pigeon/pidfile.rb
pigeon-0.9.1 lib/pigeon/pidfile.rb
pigeon-0.9.0 lib/pigeon/pidfile.rb
pigeon-0.8.0 lib/pigeon/pidfile.rb
pigeon-0.7.1 lib/pigeon/pidfile.rb
pigeon-0.7.0 lib/pigeon/pidfile.rb
pigeon-0.6.5 lib/pigeon/pidfile.rb
pigeon-0.6.4 lib/pigeon/pidfile.rb
pigeon-0.6.3 lib/pigeon/pidfile.rb
pigeon-0.6.2 lib/pigeon/pidfile.rb
pigeon-0.6.1 lib/pigeon/pidfile.rb
pigeon-0.6.0 lib/pigeon/pidfile.rb
pigeon-0.5.2 lib/pigeon/pidfile.rb
pigeon-0.5.1 lib/pigeon/pidfile.rb
pigeon-0.5.0 lib/pigeon/pidfile.rb