#!/bin/bash
# update mirrorlist server
#
# This file is part of MirrorManager2.
#
# This is a kind of 'master script' that kicks of many (but not all) others.
#
# It calls refresh_mirrorlist_cache which rebuilds the lookup pickle and kill
# any instances that would still be running before doing so.
#
# After all this is done, those three files need to be copied remotely to the
# app servers which actually run the mirrorlist wsgi app and the mirrorlist
# daemon.  After that, the mirrorlist daemon needs to get a SIGHUP so that it
# knows to reload its pickle and netblocks files.
#
# Author: Matt Domsch <mdomsch@fedoraproject.org>
#         Pierre-Yves Chibon <pingou@pingoured.fr>

LOCKFILE=/var/lock/mirrormanager/update-mirrorlist-server.lock
CACHEDIR=/var/lib/mirrormanager

[ -e ${LOCKFILE} ] && kill -0 $(cat ${LOCKFILE}) && exit 2
mkdir -p $(dirname ${LOCKFILE})
echo $$ > ${LOCKFILE}
trap "rm -f ${LOCKFILE}" QUIT TERM INT HUP EXIT

cd ${MM_DIR}
rm -rf ${CACHEDIR}/old
mkdir -p ${CACHEDIR}/old
cp -ar ${CACHEDIR}/*  ${CACHEDIR}/old/ 2>/dev/null

/usr/bin/mm2_refresh_mirrorlist_cache

exit 0
