in chefctl/src/chefctl.rb [792:823]
def acquire_lock
if Chefctl::Config.immediate
Chefctl.lib.stop_or_wait_for_chef(@paths[:chef_cur])
end
Chefctl.logger.debug("Trying lock #{@lock[:file]}")
acquired = wait_for_lock(-1)
unless acquired
held = 'another process'
unless Chefctl.lib.is_a?(Chefctl::Lib::Windows)
File.open(@lock[:file], 'r') do |f|
held = f.read.strip
end
end
Chefctl.logger.info("#{@lock[:file]} is locked by #{held}, " +
"waiting up to #{@lock[:time]} seconds.")
unless wait_for_lock(@lock[:time])
quit "Unable to lock #{@lock[:file]}"
end
end
Chefctl.logger.debug("Lock acquired: #{@lock[:file]}")
@lock[:fd].truncate(0)
@lock[:fd].write(Process.pid.to_s)
@lock[:fd].flush
@lock[:held] = true
end