Monday, April 29, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 3559  / 3 Years ago, fri, august 27, 2021, 11:53:33

In some conditions like those :




  • Slow internet connections

  • Slow PPA or sources

  • Wifi internet access or 3g internet access



apt-get may stuck during update, install, upgrade or dist-upgrade.... endlessly (up to you to force it to close)



When I say stuck : it downloads the files, start the download, slow down and wait at some point and simply stop to download but still waiting the end of the file.



From what I understand it seems to occurs when there is a lot of latency variations (so when a server is saturated or with a wifi/3g internet access)



This effect affects also with official repositories. so it's not a source.list thing.



How can we tell to apt-get :




  1. to stop waiting endlessly

  2. retry to download when there is a timeout or a packet loss during the download



I am looking for a solution that does not involve brute force methods such as Ctrl+C or kill. I am looking for something more compatible with scripts (so no "human" intervention when the apt-get line has been launched).


More From » apt

 Answers
2

You can use the timeout command (installed by the package by the same name) to run a command and kill it if it takes more than N seconds. I'd be careful about when to use it though. Killing apt-get during a package installation could mess things up, so I suggest only running the download part with timeout. Something like this bash function:



upgrade() {
local retry=5 count=0

# retry at most $retry times, waiting 1 minute between each try
while true; do

# Tell apt-get to only download packages for upgrade, and send
# signal 15 (SIGTERM) if it takes more than 10 minutes
if timeout -15 600 apt-get --assume-yes --download-only upgrade; then
break
fi
if (( count++ == retry )); then
printf 'Upgrade failed
' >&2
return 1
fi
sleep 60
done

# At this point there should be no more packages to download, so
# install them.
apt-get --assume-yes upgrade
}


See How do I run a command, and have it abort (timeout) after N seconds? for more.


[#39803] Saturday, August 28, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
errettas

Total Points: 160
Total Questions: 118
Total Answers: 91

Location: Laos
Member since Fri, Sep 11, 2020
4 Years ago
;