|
| 1 | +#!/bin/bash |
| 2 | +# This is intended to be called from puppet on both the master and the |
| 3 | +# primary machine. Its purpose is to restore repository configurations |
| 4 | +# when a backup machine is installed from scratch. |
| 5 | +# IMPORTANT NOTE: this will restore all the repositories from the primary |
| 6 | +# machine, but if any repositories were added by hand (that is, outside |
| 7 | +# of manage-replicas), then the source URL will be left pointing to the |
| 8 | +# primary machine rather than the real stratum 0 it is supposed to come |
| 9 | +# from. Those would need to be separately restored with add-repository -H |
| 10 | +# before calling this function. |
| 11 | + |
| 12 | +VARLIB=/var/lib/cvmfs-hastratum1 |
| 13 | +SHARE=/usr/share/cvmfs-hastratum1 |
| 14 | + |
| 15 | +DONEFILE=$VARLIB/restoration-date |
| 16 | +if [ -f $DONEFILE ]; then |
| 17 | + exit |
| 18 | +fi |
| 19 | + |
| 20 | +if cvmfsha-is-master; then |
| 21 | + exit |
| 22 | +fi |
| 23 | + |
| 24 | +. /etc/cvmfs/hastratum1.conf |
| 25 | + |
| 26 | +THISHOST="`uname -n`" |
| 27 | +case $THISHOST in |
| 28 | + $HOST1) OTHERHOST=$HOST2;; |
| 29 | + $HOST2) OTHERHOST=$HOST1;; |
| 30 | + *) echo "Not running on $HOST1 or $HOST2" >&2; exit 1;; |
| 31 | +esac |
| 32 | + |
| 33 | +sed "s/@otherhost@/$OTHERHOST/" $SHARE/restore-replicas.conf.in >$VARLIB/restore-replicas.conf |
| 34 | +if ! $SHARE/manage-replicas -f $VARLIB/restore-replicas.conf; then |
| 35 | + echo "Restoration of replicas failed" >&2 |
| 36 | + exit 1 |
| 37 | +fi |
| 38 | +rm $VARLIB/restore-replicas.conf |
| 39 | + |
| 40 | +# fix the incorrect source URLs |
| 41 | +( |
| 42 | +echo "addcmd true" |
| 43 | +echo "remcmd true" |
| 44 | +cat /etc/cvmfs/manage-replicas.conf |
| 45 | +) > $VARLIB/manage-replicas.conf |
| 46 | +if ! $SHARE/manage-replicas -f $VARLIB/manage-replicas.conf; then |
| 47 | + echo "Restoration of replica source URLs failed" >&2 |
| 48 | + exit 1 |
| 49 | +fi |
| 50 | +rm $VARLIB/manage-replicas.conf |
| 51 | + |
| 52 | +date >$DONEFILE |
0 commit comments