Package: apt-mirror-updater
Theapt-mirror-updaterpackage automates robustapt-getmirror selection forDebianandUbuntuby enabling discovery of available mirrors, ranking of
available mirrors, automatic switching between mirrors and robust package list
updating (seefeatures). It’s currently tested on Python 2.7, 3.5+ and PyPy
(although test coverage is still rather low, seestatus).FeaturesStatusInstallationUsageIssues with mirror updatesContactLicenseFeaturesDiscovery of available mirrorsDebianandUbuntumirrors are discovered automatically by querying theDebian mirror listor theUbuntu
mirror list(the applicable
mirror list is automatically selected based on the current platform).Ranking of available mirrorsDiscovered mirrors are ranked by bandwidth (to pick the fastest mirror) and
excluded if they’re being updated (seeissues with mirror updates).Automatic switching between mirrorsThe main mirror configured in/etc/apt/sources.listcan be changed with a
single command. The new (to be configured) mirror can be selected
automatically or configured explicitly by the user.Robust package list updatingSeveralapt-getsubcommands can fail if the current mirror is being updated
(seeissues with mirror updates) andapt-mirror-updatertries to work
around this by wrappingapt-getupdateto retry on failures and
automatically switch to a different mirror when it looks like the current
mirror is being updated (because I’ve seen such updates take more than 15
minutes and it’s not always acceptable to wait for so long, especially in
automated solutions).StatusOn the one hand theapt-mirror-updaterpackage was developed based on quite a
few years of experience in usingapt-getonDebianandUbuntusystems and
large scale automation of apt-get (working on 150+ remote systems). On the
other hand the Python package itself is relatively new: it was developed and
published in March 2016. As such:WarningUntilapt-mirror-updaterhas been rigorously tested I consider
it a proof of concept (beta software) so if it corrupts your
system you can’t complain that you weren’t warned! I’ve already
tested it on a variety of Ubuntu systems but haven’t found the
time to set up a Debian virtual machine for testing. Most of the
logic is exactly the same though. The worst that can happen
(assuming you trust my judgement ;-) is that/etc/apt/sources.listis corrupted however a backup copy is
made before any changes are applied, so I don’t see how this can
result in irreversible corruption.I’m working on an automated test suite but at the moment I’m still a bit fuzzy
on how to create representative tests for the error handling code paths (also,
writing a decent test suite requires a significant chunk of time :-).InstallationTheapt-mirror-updaterpackage is available onPyPIwhich means installation
should be as simple as:$pipinstallapt-mirror-updaterThere’s actually a multitude of ways to install Python packages (e.g. theper
user site-packages directory,virtual environmentsor just installing
system wide) and I have no intention of getting into that discussion here, so
if this intimidates you then read up on your options before returning to these
instructions ;-).UsageThere are two ways to use theapt-mirror-updaterpackage: As the command line
programapt-mirror-updaterand as a Python API. For details about the
Python API please refer to the API documentation available onRead the Docs.
The command line interface is described below.Usage:apt-mirror-updater [OPTIONS]The apt-mirror-updater program automates robust apt-get mirror selection for
Debian and Ubuntu by enabling discovery of available mirrors, ranking of
available mirrors, automatic switching between mirrors and robust package list
updating.Supported options:OptionDescription-r,--remote-host=SSH_ALIASOperate on a remote system instead of the local system. TheSSH_ALIASargument gives the SSH alias of the remote host. It is assumed that the
remote account has root privileges or password-less sudo access.-f,--find-current-mirrorDetermine the main mirror that is currently configured in
/etc/apt/sources.list and report its URL on standard output.-b,--find-best-mirrorDiscover available mirrors, rank them, select the best one and report its
URL on standard output.-l,--list-mirrorsList available (ranked) mirrors on the terminal in a human readable format.-c,--change-mirror=MIRROR_URLUpdate /etc/apt/sources.list to use the givenMIRROR_URL.-a,--auto-change-mirrorDiscover available mirrors, rank the mirrors by connection speed and update
status and update /etc/apt/sources.list to use the best available mirror.-u,--update,--update-package-listsUpdate the package lists using “apt-get update”, retrying on failure and
automatically switch to a different mirror when it looks like the current
mirror is being updated.-x,--exclude=PATTERNAdd a pattern to the mirror selection blacklist.PATTERNis expected to be
a shell pattern (containing wild cards like “?” and “*”) that is matched
against the full URL of each mirror.-m,--max=COUNTDon’t query more thanCOUNTmirrors for their connection status
(defaults to 50). If you give the number 0 no limit will be applied.Because Ubuntu mirror discovery can report more than 300 mirrors it’s
useful to limit the number of mirrors that are queried, otherwise the
ranking of mirrors will take a long time (because over 300 connections
need to be established).-v,--verboseIncrease logging verbosity (can be repeated).-q,--quietDecrease logging verbosity (can be repeated).-h,--helpShow this message and exit.Issues with mirror updatesOver the past five years my team (at work) and I have been managing a
cluster of 150+ Ubuntu servers, initially using manual system administration
but over time automatingapt-getfor a variety of use cases (provisioning,
security updates, deployments, etc.). As we increased our automation we started
running into various transient failure modes ofapt-get, primarily withapt-getupdatebut incidentally also with other subcommands.The most frequent failure that we run into isapt-getupdatecrapping out
with ‘hash sum mismatch’ errors (see alsoDebian bug #624122). When this
happens a file calledArchive-Update-in-Progress-*can sometimes be found
on the index page of the mirror that is being used (see alsoDebian bug
#110837). I’ve seen these situations last for more than 15 minutes.My working theory about these ‘hash sum mismatch’ errors is that they are
caused by the fact that mirror updates aren’t atomic, apparently causingapt-getupdateto download a package list whose datafiles aren’t consistent
with each other. If this assumption proves to be correct (and also assuming
that different mirrors are updated at different times :-) then the commandapt-mirror-updater--update-package-listsshould work around this annoying
failure mode (by automatically switching to a different mirror when ‘hash sum
mismatch’ errors are encountered).Publishingapt-mirror-updaterto the world is my attempt to contribute to
this situation instead of complaining in bug trackers (see above) where no
robust and automated solution is emerging (at the time of writing). Who knows,
maybe some day these issues will be resolved by moving logic similar to what
I’ve implemented here intoapt-getitself. Of course it would also help if
mirror updates were atomic…ContactThe latest version ofapt-mirror-updateris available onPyPIandGitHub.
The documentation is hosted onRead the Docsand includes achangelog. For
bug reports please create an issue onGitHub. If you have questions,
suggestions, etc. feel free to send me an e-mail atpeter@peterodding.com.LicenseThis software is licensed under theMIT license.© 2020 Peter Odding.