Class Daemonize::PidFile
In: lib/dctl/pidfile.rb
Parent: Object

What is a Pid-File?

A Pid-File is a file containing the process identification number (pid) that is stored in a well-defined location of the filesystem thus allowing other programs to find out the pid of a running script.

Dctl needs the pid of the scripts that are currently running in the background to send them so called signals. Dctl uses the TERM signal to tell the script to exit when you issue a stop command.

How does a Pid-File look like?

Pid-Files generated by Dctl have to following format:

  <basename>.pid

This file just contains one line with the pid as string (for example 6432).

Where are Pid-Files stored?

Dctl stores the Pid-files relative to two different locations:

  1. if you are root, Pid-Files are stored to /var/run.
  2. else, Pid-File are stored in the current directory.

Methods

delete   new   read   write  

Public Class methods

[Source]

    # File lib/dctl/pidfile.rb, line 28
28:     def initialize(path, name)
29:       # Test if this directory is valid.
30:       Dir.new path
31:       raise Errno::EACCES, path unless File.writable? path and File.readable? path
32:       @pathname = File.join(File.expand_path(path), name) + '.pid'
33:     end

Public Instance methods

[Source]

    # File lib/dctl/pidfile.rb, line 46
46:     def delete
47:       File::delete @pathname
48:       self
49:     end

[Source]

    # File lib/dctl/pidfile.rb, line 35
35:     def read
36:       open(@pathname) { |f| Integer(f.read) }
37:     end

[Source]

    # File lib/dctl/pidfile.rb, line 39
39:     def write
40:       f = File.new(@pathname, File::CREAT | File::EXCL | File::WRONLY)
41:       f << $$
42:       f.close
43:       self
44:     end

[Validate]