Created
October 26, 2011 17:55
-
-
Save mitchellh/1317151 to your computer and use it in GitHub Desktop.
Chef file lock to enforce only one chef run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Putting this at the top of your "base" recipe or some common recipe that | |
# is loaded very early on will force Chef to only run one process at a time. | |
# This is enforced using a file lock. The file lock is automatically released | |
# when the process exits, so there is no need to explicitly do so. | |
#---------------------------------------------------------------------- | |
# Obtain File Lock | |
#---------------------------------------------------------------------- | |
$_chef_lock_file = File.open(File.join(Chef::Config[:file_cache_path], "chef_lock"), "w+") | |
if $_chef_lock_file.flock(File::LOCK_EX | File::LOCK_NB) === false | |
Chef::Log.info("Another Chef process running. Not running.") | |
exit(true) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment