Skip to content

Commit d7c5b24

Browse files
committed
Updated update-db to work on (my) OS-X box.
- Legacy-Id: 480
1 parent f051f64 commit d7c5b24

1 file changed

Lines changed: 28 additions & 14 deletions

File tree

test/update-db

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,45 @@
33
# push in a new copy of the database from a dump of the master database, and
44
# do the fixups needed to run the django apps.
55

6-
#set -x
7-
86
program=${0##*/}
97
progdir=${0%/*}
108

119
cd $progdir/..
1210
build=$PWD
13-
state=/var/local/$program
1411

1512
function log() { logger -i -t $program -s "$*"; }
1613
function die() { log "$*; terminating."; echo "$program: Error: $*" 1>&2; exit 1; }
1714

1815

19-
[ $DBDUMP ] || DBDUMP="$1"
20-
[ $DBDUMP ] || DBDUMP=/www/tools.ietf.org/events/raw/sqldump/sqldump.raw
21-
[ $DBFIX ] || DBFIX=$build/test/sql_fixup.sql
22-
[ $DBTIME ] || DBTIME=$state/update-db.time
23-
[ $DBDONE ] || DBDONE=$state/update-db.done
16+
for dir in /var/local /var/state /var/run /var/tmp; do
17+
[ -d $dir -a -w $dir ] && state=$dir/$program
18+
done
19+
[ "$state" ] || die "Couldn't find a directory to keep state in."
20+
[ -d "$state" ] || mkdir $state
21+
[ "$state" ] || die "Couldn't create state dir."
22+
23+
24+
for dir in $DBLOCK /var/local /var/state /var/run /var/tmp; do
25+
[ -d $dir -a -w $dir ] && lock=$dir/$program
26+
done
27+
[ "$lock" ] || die "Couldn't find a directory to keep lock in."
28+
[ -d "$lock" ] || mkdir $lock
29+
[ "$lock" ] || die "Couldn't create lock dir."
30+
31+
32+
[ "$DBDUMP" ] || DBDUMP="$1"
33+
[ "$DBDUMP" ] || DBDUMP=/www/tools.ietf.org/events/raw/sqldump/sqldump.raw
34+
[ "$DBFIX" ] || DBFIX=$build/test/sql_fixup.sql
35+
[ "$DBTIME" ] || DBTIME=$state/update-db.time
36+
[ "$DBDONE" ] || DBDONE=$state/update-db.done
37+
[ "$DBLOCK" ] || DBLOCK=$lock
38+
2439

25-
LOCKDIR=/var/lock/ietfdb
26-
PIDFILE=$LOCKDIR/pid
40+
PIDFILE=$DBLOCK/pid
2741

2842
while true; do
29-
if mkdir $LOCKDIR; then
30-
chmod a+rwx $LOCKDIR
43+
if mkdir $DBLOCK; then
44+
chmod a+rwx $DBLOCK
3145
#echo ""
3246
#date +"Time: %Y-%m-%d %H:%M"
3347
#echo "Database dump file is from $(date -r $DBDUMP +'%Y-%m-%d %H:%M')."
@@ -48,7 +62,7 @@ while true; do
4862
# else
4963
# echo "No new database dump available."
5064
fi
51-
rm -rf $LOCKDIR
65+
rm -rf $DBLOCK
5266
exit 0
5367
else
5468
pid=$(< $PIDFILE ) || die "Couldn't read pidfile '$PIDFILE'"
@@ -58,7 +72,7 @@ while true; do
5872
else
5973
log "Pidfile for process $pid exists, but process isn't running."
6074
log "Removing lock and old pid file $pidfile."
61-
rm -rf $LOCKDIR
75+
rm -rf $DBLOCK
6276
fi
6377
fi
6478
done

0 commit comments

Comments
 (0)