diff --git a/src/bin/apply_osc_to_db.sh b/src/bin/apply_osc_to_db.sh index a9743ee66..ed8a306a1 100755 --- a/src/bin/apply_osc_to_db.sh +++ b/src/bin/apply_osc_to_db.sh @@ -31,6 +31,11 @@ if [[ ! ${EXEC_DIR:0:1} == "/" ]]; then DB_DIR=`$EXEC_DIR/dispatcher --show-dir` +if [[ ! -d $DB_DIR ]] ; then + echo "Can't find DB_DIR. Returned value: $DB_DIR" + exit 1; +fi + REPLICATE_DIR="$1" if [[ ! ${REPLICATE_DIR:0:1} == "/" ]]; then { diff --git a/src/bin/fetch_osc.sh b/src/bin/fetch_osc.sh index 24d6495c5..ef5a4b078 100755 --- a/src/bin/fetch_osc.sh +++ b/src/bin/fetch_osc.sh @@ -38,6 +38,26 @@ if [[ ! -d $LOCAL_DIR ]]; }; fi +if [[ $REPLICATE_ID == "auto" ]] ; then + REPLICATE_ID=`find $LOCAL_DIR -type f -name '*state.txt' -not -size 0 | sort | tail -n 1 | sed -e "s#^$LOCAL_DIR##" -e 's#[./]##g' -e 's#statetxt##' -e 's/^0\+//g'` + + EXEC_DIR="`dirname $0`/" + DB_DIR=`$EXEC_DIR/dispatcher --show-dir` + + if [[ ! -d $DB_DIR ]] ; then + echo "Can't find DB_DIR. Returned value: $DB_DIR" + exit 1; + fi + + if [[ "x$REPLICATE_ID" == "x" ]] ; then + REPLICATE_ID=`cat $DB_DIR/replicate_id` + fi + if [[ "x$REPLICATE_ID" == "x" ]] ; then + echo "Could not determine REPLICATE_ID. Exiting" + exit 1 + fi +fi + # $1 - remote source # $2 - local destination fetch_file() diff --git a/src/bin/rules_loop.sh b/src/bin/rules_loop.sh index c506b7bcf..fccc947ea 100755 --- a/src/bin/rules_loop.sh +++ b/src/bin/rules_loop.sh @@ -19,11 +19,12 @@ if [[ -z $1 ]]; then { - echo Usage: $0 database_dir + echo "Usage: $0 database_dir [desired_cpu_load]" exit 0 }; fi +CPU_LOAD=${2:-100} DB_DIR=$1 EXEC_DIR="`dirname $0`/" @@ -37,8 +38,14 @@ pushd "$EXEC_DIR" while [[ true ]]; do { + START=$(date +%s) echo "`date '+%F %T'`: update started" >>$DB_DIR/rules_loop.log ./osm3s_query --progress --rules <$DB_DIR/rules/areas.osm3s echo "`date '+%F %T'`: update finished" >>$DB_DIR/rules_loop.log - sleep 3 + WORK_TIME=$(( $(date +%s) - START )) + SLEEP_TIME=$(( WORK_TIME * 100 / CPU_LOAD - WORK_TIME)) + # let SLEEP_TIME be at least 3 seconds + SLEEP_TIME=$(( SLEEP_TIME < 3 ? 3 : SLEEP_TIME)) + echo "It took $WORK_TIME to run the loop. Desired load is: ${CPU_LOAD}%. Sleeping: $SLEEP_TIME" + sleep $SLEEP_TIME }; done