Class: Chef::RunLock
- Inherits:
-
Object
- Object
- Chef::RunLock
- Defined in:
- lib/chef/undev/monkey_patches/run_lock.rb
Instance Method Summary collapse
Instance Method Details
#acquire ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/chef/undev/monkey_patches/run_lock.rb', line 3 def acquire # ensure the runlock_file path exists create_path(File.dirname(runlock_file)) @runlock = File.open(runlock_file,'w+') unless runlock.flock(File::LOCK_EX|File::LOCK_NB) # Another chef client running... runpid = runlock.read.strip.chomp Chef::Log.warn("Chef client #{runpid} is running, will wait for it to finish and then run.") runlock.flock(File::LOCK_EX) end # We grabbed the run lock. Save the pid. runlock.truncate(0) runlock.rewind # truncate doesn't reset position to 0. runlock.write(Process.pid.to_s) end |