Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding the closest Apache Software Foundation mirror programatically

Tags:

apache

mirror

For my deployment automation needs, I would like to dynamically and programatically determine the closest Apache Software Foundation mirror since the servers are distributed across geographically distinct locations and it would be ideal to dynamically determine the best mirror without having to hard-code that knowledge somewhere.

The only approach I could think of so far is to scrap the http://www.apache.org/dyn/closer.cgi page for the closest mirror suggested there, but it seems a bit cumbersome and fragile.

Is there a web API endpoint that provides this functionality in a stable and reliable way?

like image 284
Pedro Romano Avatar asked Feb 03 '14 18:02

Pedro Romano


People also ask

Who is Apache owned by?

Who owns the Apache code? ¶ All software developed within the Foundation belongs to the ASF, and therefore the members. The members own the code and the direction of it and the Foundation.

What is Apache org used for?

OPEN: The Apache Software Foundation provides support for 350+ Apache Projects and their Communities, furthering its mission of providing Open Source software for the public good.

Is Apache all open source?

Is Apache software open source? ¶ Yes. The Apache License meets both the Open Source Initiative's (OSI) Open Source Definition, and the Free Software Foundation's definition of "free software".


2 Answers

The mirror URLs in the page are marked up as <strong>, so you can scrape the page to get the top recommendation like this:

curl 'https://www.apache.org/dyn/closer.cgi' |
  grep -o '<strong>[^<]*</strong>' |
  sed 's/<[^>]*>//g' |
  head -1

Additionally, closer.cgi supports an ?as_json=1 query parameter to provide the same information as JSON. The result has a key of preferred for the closest mirror, as well as http for the alternatives.

like image 53
Joe Avatar answered Sep 17 '22 18:09

Joe


There is a more elegant way by using jq:

curl -s 'https://www.apache.org/dyn/closer.cgi?as_json=1' | jq --raw-output '.preferred'
like image 37
soulmachine Avatar answered Sep 20 '22 18:09

soulmachine