8

When there is a problem with access to yum repos (for example if a needed proxy isn't configured), running a command like 'yum update' will wait for a very long time trying lots of different mirrors. Sometimes that is good, but sometimes I would rather check quickly whether access to yum repos is OK.

Is there a way to get yum to quickly check its connectivity and give me a status code indicating whether access to remote repos is OK?

kdt
  • 1,400
  • 3
  • 22
  • 34

4 Answers4

3

Here's one way to do it, the crux of it is the *Repo-baseurl:" which is reported by the yum repolist command:

# curl -s --dump-header - `yum repolist rhcd -v | grep Repo-baseurl | awk  '{print $2}'` -o  /dev/null

HTTP/1.1 200 OK
Date: Fri, 17 May 2013 09:58:30 GMT
Server: Apache/2.2.3 (CentOS)
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html;charset=ISO-8859-1

Breakdown of that:

 yum repolist rhcd -v
Loading "fastestmirror" plugin
Config time: 0.104
Yum Version: 3.2.22
Loading mirror speeds from cached hostfile
Repo-id     : rhcd
Repo-name   : rhcd
Repo-status : enabled:
Repo-updated: Mon Nov  1 14:37:19 2010
Repo-pkgs   : 2,599
Repo-size   : 3.7 G
Repo-baseurl: http://lochost:81/core_build/il31/centos/5Server/i386/CentOS/

Extract the baseurl with grep and pipe to awk for the url.

use curl's dump header option to see the http status:

HTTP/1.1 200 OK
Date: Fri, 17 May 2013 09:58:30 GMT
Server: Apache/2.2.3 (CentOS)
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html;charset=ISO-8859-1

Of course yum is a really nicely put together python program so I guess you could also put it together as a python utility importing the relevant bits of yum.

Without a reponame yum repolist will list all of the yum repositories. You can then process them in a loop.

gm3dmo
  • 10,057
  • 1
  • 42
  • 36
1

I had the same need (check if proxy is configured correctly), and while the above solutions gave hints, none was a complete solution, as checking with curl does not use the http proxy configured in yum.

Firstly, yum proxy can be configured:

  • per-repo by adding proxy=http://<proxy_ip>:<proxy_port> in each /etc/yum.repos.d/*.repo

  • globally, by adding proxy=http://<ip>:<port> and http_caching=none in yum.conf (no caching to avoid getting stale repmod.xml causing checksum mismatches)

1. First, get a list of repositories and URLs:

#Produces a csv with 'repo_id#repo_url' rows
yum repolist enabled -v|egrep 'Repo-id|Repo-baseurl' | paste -sd ' \n' | awk '{printf ("%s#%s\n",$3,$6)}' > repolist.csv

2. Clear yum cache to avoid cached answers

yum clean all

Then for each repository in repolist.csv, do the following:

3a. query repo contents with yum (about 15 seconds for base)

#count packages, outputs: 9352
yum --quiet --disablerepo=* --enablerepo=base list available|wc -l

3b. alternatively query a specific package with repoquery (about 7 seconds for base)

# outputs: 1
repoquery --repoid=base --qf "%-20{repoid} %{name}"  openssh-clients|wc -l
sivann
  • 563
  • 5
  • 16
1

For me, the following command worked:

yum repolist -v | grep Repo-baseurl | awk  '{print $3}'

instead of this one:

yum repolist rhcd -v | grep Repo-baseurl | awk  '{print $2}'

And for multiple yum-repos, you could do the following:

for repourl in $(yum repolist -v | grep Repo-baseurl | awk  '{print $3}') ; do echo $repourl; curl -s --dump-header - $repourl -o  /dev/null; done

Will result in:

http://repo-url-1/
HTTP/1.1 200 OK
Date: Sat, 31 Aug 2019 08:32:35 GMT
Server: Apache/2.2.15 (CentOS)
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html;charset=UTF-8

http://repo-url-2/
HTTP/1.1 200 OK
Date: Sat, 31 Aug 2019 08:32:36 GMT
Server: Apache/2.2.15 (CentOS)
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html;charset=UTF-8
sMajeed
  • 111
  • 3
0

I don't think there is a general command to check yum connectivity. What you can do is this: create a test repo in /etc/yum.repos.d/test.repo that just checks against a single location instead of the whole mirrors list so things are more speedy.

[test]
name= test
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
enabled = 0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

and then give a yum command in the form

yum --disablerepo=* --enablerepo=test list available

if you get a connection error chances are that your internet connectivity is at fault. Of course centos.org could also be down in the above example but the chances of that are slimmer.

thanosk
  • 940
  • 7
  • 16