A basic library for creating lockfiles for processes
This library works with Ruby 1.8 and 1.9 and is licensed under the MIT License.
Install the pidfile gem:
sudo gem install pidfile
The pidfile gem is easy to use and only requires the instantiation of the pidfile, like so:
pf = .
Of course there is other functionality, but if you are just wanting to keep a process from running more than once, this is all you need.
PidFile creates file to store the process ID (PID). By default, process ID (PID) files are created in /tmp upon instantiation and are given the same name as the calling script with a .pid extension. Process ID files are removed when the creating program exits.
Each argument, :pidfile and :piddir, can be changed upon instantiation of the class.
.(:piddir => '/var/lock', :pidfile => "awesome.pid")
Why isn't this a singleton?
My main concern is how it would behave when a process is forked multiple times. Each new process would get its own PID, but I wasn't sure how using a singleton would affect this; if the interrelationship of the processes would keep the object from correctly identifying the correct pidfile.
Anyway, I like the flexibility that not using a singleton offers, and I guess I'd rather ask you not to do something bad rather than restraining you.
Copyright© 2010 Samuel Mullen (samullen). See LICENSE for details