From: Daniel Berger Date: 2008-06-07T00:10:20+09:00 Subject: Re: Ensuring only one instance of a script is running On May 28, 5:48 pm, "ara.t.howard" wrote: > On May 28, 2008, at 4:35 PM, Mike Kasick wrote: > > > Cute trick. > > > However, I wouldn't recommend it's use in any distributed code.   > > flocks > > are intended to serve a purpose other than what's achieved as a side > > effect here, and although it's generally safe, the behavior is unknown > > at best if the script file resides in a remote file system like NFS. > > > For example, in Linux versions prior to 2.6.12 flocks are local   > > only, so > > this would have the intended effect.  However, in Linux versions   > > 2.6.12 > > and newer, flocks are emulated by POSIX locks, which should result in > > only a single instance running across a set of machines attempting to > > run the same script located in an NFS share. > > you can use the same trick even on NFS > >    require 'posixlock' # gem installposixlock > >    DATA.posixlock( File::LOCK_EX | File::LOCK_NB ) > > and this will work for both NFS and local fs.  of course you'd need to   > degrade to flock ifposixlockis not installed.... > > my lockfile gem is also NFS safe and can be used for this purpose.   > actually it can make any program run one instance without modification > > rlock lockifle run_this_once.rb Good to know, thanks Ara. BTW, I don't see posixlock on the main codeforpeople file listing at http://rubyforge.org/frs/?group_id=1024 I was able to find 0.0.1 via the RAA, though. Is that the latest version? I ask because I want to build from source. Thanks, Dan