Skip to content
This repository has been archived by the owner on Jan 18, 2019. It is now read-only.
/ simple_pid Public archive

A simple, but complete library for managing pidfiles.

License

Notifications You must be signed in to change notification settings

watsonian/simple_pid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simple_pid

This is a simple library for managing pid files. It was extracted from Kenneth Kalmer’s excellent daemon-kit project (github.com/kennethkalmer/daemon-kit). The daemon-kit framework is amazing for bootstrapping your daemons, but if you need something more lightweight (e.g., a single file daemon), then you’re out of luck (for now). In the mean time, there weren’t any obvious, simple pid file management libraries that you could trust. This one works well and has facilities to ensure the process the pid file is pointing to is still running, so you can handle stale pid files easily.

Usage

Some samples of the most common uses:

require 'rubygems'
require 'simple_pid'

pid = SimplePid.new("/path/to/your.pid")

if pid.exists?
  unless pid.running?
    pid.cleanup
    pid.write!
  end
else
  pid.write!
end

Most of the above is fairly self-explanatory. You can accomplish all of the above by calling:

SimplePid.drop("/path/to/your.pid")

If the path specified for the pid is unwritable for any reason, it falls back to using /tmp to store the

You can cleanup quickly with:

SimplePid.cleanup("/path/to/your.pid")

The above cleanup class method returns true if the process wasn’t running and the cleanup was actually run. It returns false if the process was still running and no cleanup occurred. If you need to force cleanup regardless of whether the process is running or not, you can do so with:

SimplePid.cleanup!("/path/to/your.pid")

You can check to see if the process is running and exit with an error message if it is like this:

pid.ensure_stopped!

The current contents of the pid file can always be accessed like this:

pid.pid

Copyright © 2010 Joel Watson. Portions copyright Kenneth Kalmer. See LICENSE for details.

About

A simple, but complete library for managing pidfiles.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages