Skip to content

Instantly share code, notes, and snippets.

@mikesmullin
Created May 28, 2013 04:07
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikesmullin/5660466 to your computer and use it in GitHub Desktop.
Save mikesmullin/5660466 to your computer and use it in GitHub Desktop.
I found a situation when chef had generated Chef::Exceptions::CommandTimeout exception in git clone command if time of git clone is more than 600 seconds (10 minutes). Here's how to set the timeout value for such situations in chef recipe.
# monkey-patch Chef Git Provider
# to raise the default ShellOut timeout setting
# because this repo can take over 10min
# to clone from github.com
class ::Chef::Provider::Git
def clone # based on opscode/chef commit b86c5b06
converge_by("clone from #{@new_resource.repository} into #{@new_resource.destination}") do
remote = @new_resource.remote
args = []
args << "-o #{remote}" unless remote == 'origin'
args << "--depth #{@new_resource.depth}" if @new_resource.depth
timeout = 10000 # i believe these are seconds
Chef::Log.info "#{@new_resource} cloning repo #{@new_resource.repository} to #{@new_resource.destination} with timeout #{timeout}"
clone_cmd = "git clone #{args.join(' ')} #{@new_resource.repository} #{Shellwords.escape @new_resource.destination}"
shell_out!(clone_cmd, run_options(:log_level => :info, :timeout => timeout))
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment