From 8deca3446e08feefc8cc209e7d1bad88bd5c83a7 Mon Sep 17 00:00:00 2001 From: Henrik Levkowetz Date: Tue, 12 Jun 2007 18:05:46 +0000 Subject: [PATCH] A script to update the update database from a dump file - Legacy-Id: 339 --- test/update-db | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 test/update-db diff --git a/test/update-db b/test/update-db new file mode 100755 index 000000000..4f2ebbfd3 --- /dev/null +++ b/test/update-db @@ -0,0 +1,47 @@ +#!/bin/bash + +# push in a new copy of the database from a dump of the master database, and +# do the fixups needed to run the django apps. + +#set -x + +program=${0##*/} +progdir=${0%/*} + +cd $progdir/.. +build=$PWD + +function log() { logger -i -t $program -s "$*"; } +function die() { log "$*; terminating."; echo "$program: Error: $*" 1>&2; exit 1; } + + +[ $DBDUMP ] || DBDUMP=/www/tools.ietf.org/events/raw/sqldump/sqldump.raw +[ $DBFIX ] || DBFIX=$build/test/sql_fixup.sql + +LOCKDIR=/var/lock/ietfdb +PIDFILE=$LOCKDIR/pid + +while true; do + if mkdir $LOCKDIR; then + echo "$$" > $PIDFILE + log "Updating local database from $DBDUMP ..." + python ietf/manage.py dbshell < $DBDUMP + log "Updating local database from $DBFIX ..." + python ietf/manage.py dbshell < $DBFIX + log "Running Django syncdb ..." + python ietf/manage.py syncdb + log "Done." + rm -rf $LOCKDIR + exit 0 + else + pid=$(< $PIDFILE ) || die "Couldn't read pidfile '$PIDFILE'" + if kill -0 $pid; then + log "Pidfile for process $pid exists, and process is running. Sleeping." + sleep 10 + else + log "Pidfile for process $pid exists, but process isn't running." + log "Removing lock and old pid file $pidfile." + rm -rf $LOCKDIR + fi + fi +done \ No newline at end of file