Class: Daemonize::PidFile
- Inherits:
-
Object
- Object
- Daemonize::PidFile
- Defined in:
- lib/dctl/pidfile.rb
Overview
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:
-
if you are root, Pid-Files are stored to
/var/run
. -
else, Pid-File are stored in the current directory.
Instance Method Summary collapse
- #delete ⇒ Object
-
#initialize(path, name) ⇒ PidFile
constructor
A new instance of PidFile.
- #read ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize(path, name) ⇒ PidFile
Returns a new instance of PidFile.
28 29 30 31 32 33 |
# File 'lib/dctl/pidfile.rb', line 28 def initialize(path, name) # Test if this directory is valid. Dir.new path raise Errno::EACCES, path unless File.writable? path and File.readable? path @pathname = File.join(File.(path), name) + '.pid' end |
Instance Method Details
#delete ⇒ Object
46 47 48 49 |
# File 'lib/dctl/pidfile.rb', line 46 def delete File::delete @pathname self end |
#read ⇒ Object
35 36 37 |
# File 'lib/dctl/pidfile.rb', line 35 def read open(@pathname) { |f| Integer(f.read) } end |
#write ⇒ Object
39 40 41 42 43 44 |
# File 'lib/dctl/pidfile.rb', line 39 def write f = File.new(@pathname, File::CREAT | File::EXCL | File::WRONLY) f << $$ f.close self end |