Created
May 28, 2013 04:07
-
-
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.
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
# 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 |
Thanks very much for this. I took this sample code and overrode spawn_command_thread() in https://github.com/opscode/chef/blob/master/lib/chef/provider/service/windows.rb to increase the timeout to Windows service star, stop, restart, etc. events.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
see also:
http://stackoverflow.com/questions/14557118/how-to-set-a-timeout-in-deploy-revision-provider
http://community.opscode.com/chat/chef/2012-03-12 search "timeout"
https://github.com/opscode/mixlib-shellout/blob/master/lib/mixlib/shellout.rb#L278
https://github.com/opscode/mixlib-shellout/blob/master/lib/mixlib/shellout/unix.rb#L63
https://github.com/opscode/chef/blob/master/lib/chef/provider/git.rb#L152