Updated update-db to work on (my) OS-X box.
- Legacy-Id: 480
This commit is contained in:
parent
f051f64977
commit
d7c5b248e9
|
@ -3,31 +3,45 @@
|
||||||
# push in a new copy of the database from a dump of the master database, and
|
# 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.
|
# do the fixups needed to run the django apps.
|
||||||
|
|
||||||
#set -x
|
|
||||||
|
|
||||||
program=${0##*/}
|
program=${0##*/}
|
||||||
progdir=${0%/*}
|
progdir=${0%/*}
|
||||||
|
|
||||||
cd $progdir/..
|
cd $progdir/..
|
||||||
build=$PWD
|
build=$PWD
|
||||||
state=/var/local/$program
|
|
||||||
|
|
||||||
function log() { logger -i -t $program -s "$*"; }
|
function log() { logger -i -t $program -s "$*"; }
|
||||||
function die() { log "$*; terminating."; echo "$program: Error: $*" 1>&2; exit 1; }
|
function die() { log "$*; terminating."; echo "$program: Error: $*" 1>&2; exit 1; }
|
||||||
|
|
||||||
|
|
||||||
[ $DBDUMP ] || DBDUMP="$1"
|
for dir in /var/local /var/state /var/run /var/tmp; do
|
||||||
[ $DBDUMP ] || DBDUMP=/www/tools.ietf.org/events/raw/sqldump/sqldump.raw
|
[ -d $dir -a -w $dir ] && state=$dir/$program
|
||||||
[ $DBFIX ] || DBFIX=$build/test/sql_fixup.sql
|
done
|
||||||
[ $DBTIME ] || DBTIME=$state/update-db.time
|
[ "$state" ] || die "Couldn't find a directory to keep state in."
|
||||||
[ $DBDONE ] || DBDONE=$state/update-db.done
|
[ -d "$state" ] || mkdir $state
|
||||||
|
[ "$state" ] || die "Couldn't create state dir."
|
||||||
|
|
||||||
LOCKDIR=/var/lock/ietfdb
|
|
||||||
PIDFILE=$LOCKDIR/pid
|
for dir in $DBLOCK /var/local /var/state /var/run /var/tmp; do
|
||||||
|
[ -d $dir -a -w $dir ] && lock=$dir/$program
|
||||||
|
done
|
||||||
|
[ "$lock" ] || die "Couldn't find a directory to keep lock in."
|
||||||
|
[ -d "$lock" ] || mkdir $lock
|
||||||
|
[ "$lock" ] || die "Couldn't create lock dir."
|
||||||
|
|
||||||
|
|
||||||
|
[ "$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
|
||||||
|
[ "$DBLOCK" ] || DBLOCK=$lock
|
||||||
|
|
||||||
|
|
||||||
|
PIDFILE=$DBLOCK/pid
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
if mkdir $LOCKDIR; then
|
if mkdir $DBLOCK; then
|
||||||
chmod a+rwx $LOCKDIR
|
chmod a+rwx $DBLOCK
|
||||||
#echo ""
|
#echo ""
|
||||||
#date +"Time: %Y-%m-%d %H:%M"
|
#date +"Time: %Y-%m-%d %H:%M"
|
||||||
#echo "Database dump file is from $(date -r $DBDUMP +'%Y-%m-%d %H:%M')."
|
#echo "Database dump file is from $(date -r $DBDUMP +'%Y-%m-%d %H:%M')."
|
||||||
|
@ -48,7 +62,7 @@ while true; do
|
||||||
# else
|
# else
|
||||||
# echo "No new database dump available."
|
# echo "No new database dump available."
|
||||||
fi
|
fi
|
||||||
rm -rf $LOCKDIR
|
rm -rf $DBLOCK
|
||||||
exit 0
|
exit 0
|
||||||
else
|
else
|
||||||
pid=$(< $PIDFILE ) || die "Couldn't read pidfile '$PIDFILE'"
|
pid=$(< $PIDFILE ) || die "Couldn't read pidfile '$PIDFILE'"
|
||||||
|
@ -58,7 +72,7 @@ while true; do
|
||||||
else
|
else
|
||||||
log "Pidfile for process $pid exists, but process isn't running."
|
log "Pidfile for process $pid exists, but process isn't running."
|
||||||
log "Removing lock and old pid file $pidfile."
|
log "Removing lock and old pid file $pidfile."
|
||||||
rm -rf $LOCKDIR
|
rm -rf $DBLOCK
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
Loading…
Reference in a new issue