Skip to content

Commit 8deca34

Browse files
committed
A script to update the update database from a dump file
- Legacy-Id: 339
1 parent 6fe5717 commit 8deca34

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

test/update-db

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
3+
# push in a new copy of the database from a dump of the master database, and
4+
# do the fixups needed to run the django apps.
5+
6+
#set -x
7+
8+
program=${0##*/}
9+
progdir=${0%/*}
10+
11+
cd $progdir/..
12+
build=$PWD
13+
14+
function log() { logger -i -t $program -s "$*"; }
15+
function die() { log "$*; terminating."; echo "$program: Error: $*" 1>&2; exit 1; }
16+
17+
18+
[ $DBDUMP ] || DBDUMP=/www/tools.ietf.org/events/raw/sqldump/sqldump.raw
19+
[ $DBFIX ] || DBFIX=$build/test/sql_fixup.sql
20+
21+
LOCKDIR=/var/lock/ietfdb
22+
PIDFILE=$LOCKDIR/pid
23+
24+
while true; do
25+
if mkdir $LOCKDIR; then
26+
echo "$$" > $PIDFILE
27+
log "Updating local database from $DBDUMP ..."
28+
python ietf/manage.py dbshell < $DBDUMP
29+
log "Updating local database from $DBFIX ..."
30+
python ietf/manage.py dbshell < $DBFIX
31+
log "Running Django syncdb ..."
32+
python ietf/manage.py syncdb
33+
log "Done."
34+
rm -rf $LOCKDIR
35+
exit 0
36+
else
37+
pid=$(< $PIDFILE ) || die "Couldn't read pidfile '$PIDFILE'"
38+
if kill -0 $pid; then
39+
log "Pidfile for process $pid exists, and process is running. Sleeping."
40+
sleep 10
41+
else
42+
log "Pidfile for process $pid exists, but process isn't running."
43+
log "Removing lock and old pid file $pidfile."
44+
rm -rf $LOCKDIR
45+
fi
46+
fi
47+
done

0 commit comments

Comments
 (0)