mirror-update/reprepro : use common functions

This converts the reprepro mirror script to use the common functions
for timestamps and vos release.  This function ssh's to the AFS server
and runs vos release directly there, avoiding many issues with
kerberos timeouts.  This has been working successfully for the rsync
mirrors.  This will also send stats back so we can keep an eye on the
timing.

Change-Id: I1be29f2d9ecaad03b22c87819e5ae8d16c4f177e
This commit is contained in:
Ian Wienand 2020-10-19 13:59:37 +11:00
parent f8852b76fb
commit 6ee7a5a116
5 changed files with 36 additions and 41 deletions

View File

@ -17,10 +17,6 @@ source /usr/share/mirror-update/functions.sh
MIRROR_VOLUME=$1 MIRROR_VOLUME=$1
function echo_ts {
printf "%(%Y-%m-%d %H:%M:%S)T | %s\n" -1 "$@"
}
if [[ ${NO_TIMEOUT:-0} -eq 1 ]]; then if [[ ${NO_TIMEOUT:-0} -eq 1 ]]; then
echo_ts "Running interactively" echo_ts "Running interactively"
set -x set -x

View File

@ -5,6 +5,10 @@
AFS_SERVER=afs01.dfw.openstack.org AFS_SERVER=afs01.dfw.openstack.org
VOS_RELEASE="ssh -i /root/.ssh/id_vos_release vos_release@${AFS_SERVER} vos release " VOS_RELEASE="ssh -i /root/.ssh/id_vos_release vos_release@${AFS_SERVER} vos release "
function echo_ts {
printf "%(%Y-%m-%d %H:%M:%S)T | %s\n" -1 "$@"
}
# Send a timer stat to statsd # Send a timer stat to statsd
# send_timer metric [start_time] # send_timer metric [start_time]
# * uses timer metric afs.release.<$1> normalised for stats # * uses timer metric afs.release.<$1> normalised for stats

View File

@ -27,6 +27,28 @@
env: yes env: yes
value: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin value: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
- name: Create common function dir
file:
path: /usr/share/mirror-update
state: directory
owner: root
group: root
mode: '0755'
- name: Copy in common functions
copy:
src: 'functions.sh'
dest: '/usr/share/mirror-update'
owner: root
group: root
mode: '0644'
- name: Set cron flag to enable reporting stats
cron:
name: UNDER_CRON
env: yes
job: '1'
- name: Setup log publisher script - name: Setup log publisher script
include_tasks: log_publish.yaml include_tasks: log_publish.yaml

View File

@ -8,22 +8,6 @@
group: root group: root
mode: '0755' mode: '0755'
- name: Create common function dir
file:
path: /usr/share/mirror-update
state: directory
owner: root
group: root
mode: '0755'
- name: Copy in common functions
copy:
src: 'functions.sh'
dest: '/usr/share/mirror-update'
owner: root
group: root
mode: '0644'
- name: Set update script names - name: Set update script names
set_fact: set_fact:
rsync_update_scripts: rsync_update_scripts:
@ -55,12 +39,6 @@
mode: '0755' mode: '0755'
loop: '{{ rsync_update_scripts }}' loop: '{{ rsync_update_scripts }}'
- name: Set cron flag to enable reporting stats
cron:
name: UNDER_CRON
env: yes
job: '1'
- name: Install update cron jobs - name: Install update cron jobs
cron: cron:
name: '{{ item }} mirror sync' name: '{{ item }} mirror sync'

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/bash -e
# Copyright 2016 IBM Corp. # Copyright 2016 IBM Corp.
# #
@ -14,12 +14,12 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
set -e source /usr/share/mirror-update/functions.sh
# For initial clones, and debugging, set this for more verbose output # For initial clones, and debugging, set this for more verbose output
# that doesn't time out. # that doesn't time out.
if [[ ${NO_TIMEOUT:-0} -eq 1 ]]; then if [[ ${NO_TIMEOUT:-0} -eq 1 ]]; then
echo "Running interactively" echo_ts "Running interactively"
TIMEOUT="" TIMEOUT=""
set -x set -x
else else
@ -35,28 +35,23 @@ UNREF_FILE=/var/run/reprepro/${MIRROR_VOLUME}.${CONFIG_KEY}.unreferenced-files
K5START="k5start -t -f /etc/reprepro.keytab service/reprepro -- ${TIMEOUT} " K5START="k5start -t -f /etc/reprepro.keytab service/reprepro -- ${TIMEOUT} "
REPREPRO="$K5START reprepro --confdir $REPREPRO_CONFIG" REPREPRO="$K5START reprepro --confdir $REPREPRO_CONFIG"
date --iso-8601=ns echo_ts "Obtaining reprepro tokens and running reprepro update"
echo "Obtaining reprepro tokens and running reprepro update"
$REPREPRO update $REPREPRO update
if [ -f $UNREF_FILE ] ; then if [ -f $UNREF_FILE ] ; then
date --iso-8601=ns echo_ts "Cleaning up files made unreferenced on the last run"
echo "Cleaning up files made unreferenced on the last run"
$REPREPRO deleteifunreferenced < $UNREF_FILE $REPREPRO deleteifunreferenced < $UNREF_FILE
fi fi
date --iso-8601=ns echo_ts "Saving list of newly unreferenced files for next time"
echo "Saving list of newly unreferenced files for next time"
k5start -t -f /etc/reprepro.keytab service/reprepro -- bash -c "reprepro --confdir $REPREPRO_CONFIG dumpunreferenced > $UNREF_FILE" k5start -t -f /etc/reprepro.keytab service/reprepro -- bash -c "reprepro --confdir $REPREPRO_CONFIG dumpunreferenced > $UNREF_FILE"
date --iso-8601=ns echo_ts "Checking state of mirror"
echo "Checking state of mirror"
$REPREPRO checkpool fast $REPREPRO checkpool fast
$REPREPRO check $REPREPRO check
date --iso-8601=ns | $K5START tee $BASE/timestamp.txt date --iso-8601=ns | $K5START tee $BASE/timestamp.txt
echo "reprepro completed successfully, running vos release." echo_ts "reprepro completed successfully, running vos release."
k5start -t -f /etc/afsadmin.keytab service/afsadmin -- vos release -v $MIRROR_VOLUME vos_release $MIRROR_VOLUME
date --iso-8601=ns echo_ts "Done."
echo "Done."