forked from adamlaska/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-db
More file actions
executable file
·64 lines (54 loc) · 1.71 KB
/
update-db
File metadata and controls
executable file
·64 lines (54 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/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
state=/var/local/$program
function log() { logger -i -t $program -s "$*"; }
function die() { log "$*; terminating."; echo "$program: Error: $*" 1>&2; exit 1; }
[ $DBDUMP ] || DBDUMP="$1"
[ $DBDUMP ] || DBDUMP=/www/tools.ietf.org/events/raw/sqldump/sqldump.raw
[ $DBFIX ] || DBFIX=$build/test/sql_fixup.sql
[ $DBTIME ] || DBTIME=$state/update-db.time
[ $DBDONE ] || DBDONE=$state/update-db.done
LOCKDIR=/var/lock/ietfdb
PIDFILE=$LOCKDIR/pid
while true; do
if mkdir $LOCKDIR; then
chmod a+rwx $LOCKDIR
#echo ""
#date +"Time: %Y-%m-%d %H:%M"
#echo "Database dump file is from $(date -r $DBDUMP +'%Y-%m-%d %H:%M')."
#echo "Last update done $(date -r $DBDONE +'%Y-%m-%d %H:%M')."
if [ $DBDUMP -nt $DBTIME ]; then
echo "$$" > $PIDFILE
chmod a+rw $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
touch -r $DBDUMP $DBTIME
touch $DBDONE
log "Done."
# else
# echo "No new database dump available."
fi
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