User Tools

Site Tools


Navigation Menu

Flight-Control

<
Previous mounth
04/12/2024
>
Next mounth
SMTWFTS
15
07
07
08
08
09
09
10
10
11
11
12
12
13
1614151617181920
1721222324252627
1828293001020304
1905060708091011









Hot Projects

SEEDStack

SEEDStack - Open 3D printable seed/sprouting systemDIY Food Hacking

UCSSPM

UCSSPM - Unified Clear-Sky Solar Prediction ModelOpen Solar Power

picoReflow

picoReflow - DIY PID Reflow Oven Controller based on RaspberryPiDIY Reflow Soldering

PiGI

PiGI - DIY Geiger Counter based on RaspberryPiRasPi Geiger Counter

DIY ARA-2000

Active Wideband Receiver Antenna for SDR - ARA-2000Wideband Antenna

DSpace

DSPace - Map everythingMap everything!

Mission-Tags

GeoIP Database Magic-Safety-Updater

In the past several months it sometimes just so happened, that the geoipupdate tool, available on many GNU/Linux systems to update MaxMind's GeoIP databases just failed. It exited fine but left a corrupt database, unreadable to the application depending on it. In this particular environment, GeoIP lookup is a mission-critical dependency, so it was time to come up with a little cron/logger/geoipupdate assisted bash magic, to update MaxMind's GeoIP Databases automatically and with two fallback safeties, in case the new DB is corrupt or the download failed somehow.

It performed very well for the last several weeks, never raised an alert and is published now, as it might be useful for someone else out there, confronted with the same problem. You could spend your time elsewhere, instead of re-inventing something that is already here and which doesn't rely on alerts, to get a human's attention but tries to fix it by itself in an automated process:

update-geoip.sh

Dependencies

  1. BASH
  2. logger
  3. geoip-bin/libgeoip1

With the update-$whatever naming convention, which can be found on most distributions today, naming it update-geoip.sh will be an easy to remember TAB-completion.

#!/bin/bash
#
##########################################################################
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##########################################################################

##########################################################################
#   GeoIP Database Magic-Safety Updater
##########################################################################
#
#   The purpose of this script is to keep GeoIP Databases automagically 
#   up-to-date and to verify each update. In order to prevent failing 
#   frontend apps, which depend on a working GeoIP lookup, the script
#   will roll back to a last known good version in case the new DBs 
#   fail to geolocate a predefined Test-IP/location combination. 
#
##########################################################################
#   Usage: update-geoip.sh (-v for verbose magic)
##########################################################################
#
#   V1.0   Initial Version                     20120510   chrono
#   V1.1   Bugfix - check if .archive exists   20120729   chrono
#   V1.2   Public Release under GPL3+          20121024   chrono
#

G_HOME="/usr/share/GeoIP"     # Home of your GeoIP DB
G_BIN="/usr/bin/geoiplookup"  # path to lookup tool
G_UPD="/usr/bin/geoipupdate"  # path to update tool
G_LOG="/usr/bin/logger"       # path to logger bin
G_IP="193.99.144.85"          # Test IP to geolocate
G_CHK="DE"                    # Expected geoloc for Test IP 
DEBUG=0                       # Set to 1 for debug (or use -v)

### functions ############################################################

function geo_check()
{
  local RES=$(${G_BIN} ${G_IP}|sed -n 2p|awk '{print substr($6,0,2)}')
  echo ${RES}
}

function log()
{
  if [ ${DEBUG} == 1 ]; then
    echo "$1"
  else
    ${G_LOG} "$1"
  fi
}

### prep rollback safety #################################################

if [ ! -d "${G_HOME}/.archive/" ]; then
  mkdir -p ${G_HOME}/.archive/
fi

cd ${G_HOME}
cp ${G_HOME}/GeoIPCity.dat ${G_HOME}/.archive/GeoIPCity.tmp

### try update ###########################################################

if [ "$1" == "-v" ]; then
  DEBUG=1
  ${G_UPD}
else
  ${G_UPD} > /dev/null 2>&1
fi

### check update #########################################################

CHECK=$(geo_check)

if [ "$CHECK" == "$G_CHK" ]; then

  ### check successfull - move last known working .dat to archive ########

  log "GeoIP DB is valid - Moving last version into archive"
  mv ${G_HOME}/.archive/GeoIPCity.tmp ${G_HOME}/.archive/GeoIPCity.dat

else

  ### check unsuccessfull - rolling back #################################

  log "GeoIP DB check FAILED - Rolling back last known working"
  mv ${G_HOME}/.archive/GeoIPCity.tmp ${G_HOME}/GeoIPCity.dat

  ### check rollback #####################################################

  CHECK=$(geo_check)

  if [ "$CHECK" == "$G_CHK" ]; then

    ### rollback successfull #############################################

    log "GeoIP DB Rollback is valid"

  else

    ### rollback data is corrupt too - move archived version ############# 

    log "GeoIP DB Rollback check FAILED - Moving back archive"
    mv ${G_HOME}/.archive/GeoIPCity.dat ${G_HOME}/GeoIPCity.dat

    ### check archive ####################################################

    CHECK=$(geo_check)

    if [ "$CHECK" == "$G_CHK" ]; then

      ### Archive recovery successfull ###################################

      log "Archive recovery OK - phew, that was a close call"

    else

      ### ALERT - we have no GeoIP capability on this machine ############

      log "Holy DevOp... I have failed you and had to kill myself!"

      # Do some alerting here if you really depend on working geoip-lookup

      exit 1

    fi
  fi
fi

exit 0
#EOF

Download the script:
update-geoip.sh.txt

Discussion

Baccarat, 2024/01/24 07:58

Your blog has piqued a lot of real interest. I can see why since you have done such a good job of making it interesting. I appreciate your efforts very much. baccarat systems

25fox, 2024/02/13 00:05

Buy a driver's license Hello, welcome to the world's largest online driver's license organization. We sell authentic and registered driving licenses and we have several driving schools with which we collaborate.

https://origineelrijbewijskopen.com/

https://origineelrijbewijskopen.com/2023/11/10/rijbewijs-kopen-telegram/

https://origineelrijbewijskopen.com/2023/10/24/rijbewijs-kopen-nederland/ https://origineelrijbewijskopen.com/2023/11/01/rijbewijs-kopen-belgie/

https://origineelrijbewijskopen.com/2023/11/07/rijbewijs-a-kopen/

https://origineelrijbewijskopen.com/2023/11/07/rijbewijs-kopen-prijs/

https://origineelrijbewijskopen.com/2023/11/07/rijbewijs-te-koop-belgie/

https://origineelrijbewijskopen.com/2023/11/10/belgisch-rijbewijs-kopen/

https://origineelrijbewijskopen.com/2023/11/10/rijbewijs-kopen-duitsland/ https://origineelrijbewijskopen.com/2023/11/10/rijbewijs-examens-kopen/

https://origineelrijbewijskopen.com/2023/11/10/rijbewijs-kopen-hongarije/

What a nice post! I'm so happy to read this. What you wrote was very helpful to me. Thank you. Actually, I run a site similar to yours. If you have time, could you visit my site? Please leave your comments after reading what I wrote. If you do so, I will actively reflect your opinion. I think it will be a great help to run my site. Have a good day.

https://cf-cc-qualitylab.com/

https://cf-cc-qualitylab.com/product/american-dollars-for-sale/

https://cf-cc-qualitylab.com/product/buy-counterfeit-aud-online/

https://cf-cc-qualitylab.com/product/buy-fake-british-pounds-online/

https://cf-cc-qualitylab.com/product/buy-fake-euro-banknotes-online/

https://cf-cc-qualitylab.com/product/buy-new-zealand-dollars-online/ https://cf-cc-qualitylab.com/product/buy-undetected-canadian-dollars/

It is incredibly average to see the best inconspicuous components presented in a basic and seeing way Thank you. Actually, I run a site similar to yours. If you have time, could you visit my site? Please leave your comments after reading what I wrote. If you do so, I will actively reflect your opinion. I think it will be a great help to run my site. Have a good day.

https://cf-cc-qualitylab.com/product/paypal-flip/

https://cf-cc-qualitylab.com/product/western-union-flip/

https://cf-cc-qualitylab.com/product/cash-app-flip/ https://cf-cc-qualitylab.com/product/western-union-flip-sale/

https://cf-cc-qualitylab.com/product/legit-paypal-flip/

https://cf-cc-qualitylab.com/product/legit-cash-app-flip/ https://cf-cc-qualitylab.com/product/buy-cloned-cards/

https://cf-cc-qualitylab.com/product/buy-credit-card-dumps-online/

https://cf-cc-qualitylab.com/product/cloned-credit-cards-for-sale/ https://cf-cc-qualitylab.com/product/legit-paypal-money-transfer/

https://cf-cc-qualitylab.com/product/legit-paypal-money-transfer/

https://cf-cc-qualitylab.com/product/western-union-money-flip/

https://cf-cc-qualitylab.com/product/hacked-cash-app/

Such an especially significant article. To a great degree charming to examine this article.I should need to thank you for the undertakings you had made for creating this astonishing article. https://cf-cc-qualitylab.com/product/automated-money-developer-machines/

https://cf-cc-qualitylab.com/product/high-quality-automatic-solution/ https://cf-cc-qualitylab.com/product/ssd-chemical-solution-packaging-materials/

https://cf-cc-qualitylab.com/product/vector-paste-ssd-solution/ https://cf-cc-qualitylab.com/product/humine-activation-powder/

https://cf-cc-qualitylab.com/product/99-99-pure-gallium-metal-alloy-for-mercury-replacement/ https://cf-cc-qualitylab.com/product/automated-money-developer-machines/

I am another client of this site so here I saw different articles and posts posted by this site,I inquisitive more enthusiasm for some of them trust you will give more data on this points in your next articles.

https://cf-cc-qualitylab.com/2024/02/01/western-union-uberweisen-umdrehen/ https://cf-cc-qualitylab.com/2024/02/01/kaufen-sie-western-union-umdrehen/

https://cf-cc-qualitylab.com/product/automated-money-developer-machines/

https://cf-cc-qualitylab.com/2024/02/01/koop-western-union-omzet/

https://cf-cc-qualitylab.com/2024/01/31/acquistare-lanciare-western-union/

https://cf-cc-qualitylab.com/2024/01/31/contanti-ribaltabili-della-western-union/

https://cf-cc-qualitylab.com/2024/01/30/volteo-de-dinero-de-western-union/

https://cf-cc-qualitylab.com/2024/01/30/comprar-voltear-de-western-union/

https://cf-cc-qualitylab.com/2024/01/28/transfert-dargent-western-union/

https://cf-cc-qualitylab.com/2024/01/28/retournement-de-western-union/

https://cf-cc-qualitylab.com/2024/01/27/online-kredietkaart-dumps-kopen/

https://cf-cc-qualitylab.com/2024/01/27/gekloonde-kredietkaarten-te-koop/

https://cf-cc-qualitylab.com/2024/01/27/gekloonde-kaarten-kopen/ https://cf-cc-qualitylab.com/2024/01/27/kaufen-sie-kreditkarten-dumps-online/

https://cf-cc-qualitylab.com/2024/01/27/geklonte-karten-dumps-zum-verkauf/

All things considered I read it yesterday yet I had a few musings about it and today I needed to peruse it again in light of the fact that it is extremely elegantly composed.

https://cf-cc-qualitylab.com/2024/01/27/kaufen-sie-geklonte-karten/

https://cf-cc-qualitylab.com/2024/01/27/acquistare-scarico-di-carte-di-credito-in-linea/ https://cf-cc-qualitylab.com/2024/01/27/carte-di-credito-clonate-in-vendita/ https://cf-cc-qualitylab.com/2024/01/27/carte-clonate-in-vendita/ https://cf-cc-qualitylab.com/2024/01/26/comprar-volcados-de-tarjetas-de-credito/

https://cf-cc-qualitylab.com/2024/01/26/tarjetas-de-credito-clonadas-a-la-venta/ https://cf-cc-qualitylab.com/2024/01/25/comprar-tarjetas-clonadas/ https://cf-cc-qualitylab.com/2024/01/25/acheter-des-dumps-de-cartes-de-credit-en-ligne/

https://cf-cc-qualitylab.com/2024/01/25/cartes-de-credit-clonees-a-vendre/

https://cf-cc-qualitylab.com/2024/01/25/cartes-clonees-a-vendre/ https://cf-cc-qualitylab.com/2024/01/23/requisitengeld-zum-verkauf/ https://cf-cc-qualitylab.com/2024/01/23/falschgeld-kaufen/

https://cf-cc-qualitylab.com/2024/01/23/gefalschter-euro-zum-verkauf/

https://cf-cc-qualitylab.com/2024/01/21/koop-valse-polymeerbiljetten/ https://cf-cc-qualitylab.com/2024/01/21/koop-valse-bankbiljetten/

 Actually, I run a site similar to yours. If you have time, could you visit my site? Please leave your comments after reading what I wrote. If you do so, I will actively reflect your opinion. I think it will be a great help to run my site. Have a good day.

https://cf-cc-qualitylab.com/2024/01/21/koop-valse-euro-bankbiljetten/

https://cf-cc-qualitylab.com/2024/01/21/comprar-dinero-falso-en-linea/

https://cf-cc-qualitylab.com/2024/01/21/comprar-dinero-falso/

https://cf-cc-qualitylab.com/2024/01/21/billetes-de-euro-a-la-venta/

https://cf-cc-qualitylab.com/2024/01/17/soldi-realistici-in-vendita/

https://cf-cc-qualitylab.com/2024/01/17/acquistare-denaro-falso/ https://cf-cc-qualitylab.com/2024/01/17/banconote-in-euro-in-vendita/ https://cf-cc-qualitylab.com/2024/01/17/argent-accessoire-a-vendre/ https://cf-cc-qualitylab.com/2024/01/17/acheter-des-billets-indetectables/ https://cf-cc-qualitylab.com/2024/01/17/faux-euros-a-vendre-en-ligne/

https://cf-cc-qualitylab.com/2024/01/09/buy-euros-online-cyprus/

https://cf-cc-qualitylab.com/2024/01/09/fake-polymer-notes-for-sale/

https://cf-cc-qualitylab.com/2024/01/09/counterfeit-money-for-sale/

https://cf-cc-qualitylab.com/2024/01/09/buy-fake-dollar-bills/

https://cf-cc-qualitylab.com/2024/01/09/buy-prop-money-canada/

https://cf-cc-qualitylab.com/2024/01/09/buy-fake-polymer-notes/

Enter your comment. Wiki syntax is allowed:
C L W I U