Class: Daemons::Pid

### Home Classes Methods

### In Files

- lib/daemons/pid.rb

### Parent

Object

### Methods

- ::dir
- ::new
- ::running?
- #cleanup
- #exist?
- #pid
- #pid=
- #running?
- #zap

### Class/Module Index

Quicksearch

- Daemons
- Daemons::Application
- Daemons::ApplicationGroup
- Daemons::CmdException
- Daemons::Controller
- Daemons::Error
- Daemons::Exception
- Daemons::Monitor
- Daemons::Optparse
- Daemons::Pid
- Daemons::PidFile
- Daemons::PidMem
- Daemons::RuntimeException
- Daemons::SystemError
- Daemons::TimeoutError
- CurrentProcess
- Daemonize
- Object

No matching classes.

# Daemons::Pid

### Public Class Methods

dir(dir_mode, dir, script) click to toggle source

Returns the directory that should be used to write the pid file to depending on the given mode.

Some modes may require an additionaly hint, others may determine the directory automatically.

If no valid directory is found, returns nil.

    # File lib/daemons/pid.rb, line 32
    def self.dir(dir_mode, dir, script)
      # nil script parameter is allowed as long as dir_mode is not :script
      return nil if dir_mode == :script && script.nil?

      case dir_mode
        when :normal
          return File.expand_path(dir)
        when :script
          return File.expand_path(File.join(File.dirname(script), dir))
        when :system
          return '/var/run'
        else
          fail Error.new("pid file mode '#{dir_mode}' not implemented")
      end
    end

new() click to toggle source

Initialization method

    # File lib/daemons/pid.rb, line 49
    def initialize
    end

running?(pid) click to toggle source

    # File lib/daemons/pid.rb, line 5
    def self.running?(pid)
      return false unless pid

      # Check if process is in existence
      # The simplest way to do this is to send signal '0'
      # (which is a single system call) that doesn't actually
      # send a signal
      begin
        Process.kill(0, pid)
        return true
      rescue TimeoutError
        raise
      rescue Errno::ESRCH
        return false
      rescue ::Exception   # for example on EPERM (process exists but does not belong to us)
        return true
      end
    end

### Public Instance Methods

cleanup() click to toggle source

Cleanup method

    # File lib/daemons/pid.rb, line 66
    def cleanup
    end

exist?() click to toggle source

Exist? method

    # File lib/daemons/pid.rb, line 74
    def exist?
      true
    end

pid() click to toggle source

Get method

    # File lib/daemons/pid.rb, line 53
    def pid
    end

pid=(p) click to toggle source

Set method

    # File lib/daemons/pid.rb, line 57
    def pid=(p)
    end

running?() click to toggle source

Check whether the process is running

    # File lib/daemons/pid.rb, line 61
    def running?
      Pid.running?(pid)
    end

zap() click to toggle source

Zap method

    # File lib/daemons/pid.rb, line 70
    def zap
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.