X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/f2ad6c961c68a0fd49e180906bc75cb577f23041..7c56f24c1f83e9d19c9df723bb86335598add902:/utils/cron_banip.sh?ds=sidebyside diff --git a/utils/cron_banip.sh b/utils/cron_banip.sh index 1f0aade6..2e0c8dfb 100755 --- a/utils/cron_banip.sh +++ b/utils/cron_banip.sh @@ -3,8 +3,14 @@ # Create or update the list of temporarily banned IPs. # -BLOCKEDFILE=/home/lonvia/nominatim/settings/ip_blocks -LOGFILE=/home/lonvia/nominatim/log/ip_blocks.log +BASEDIR="$( cd "$( dirname "$0" )" && cd .. && pwd )" +if [ "x$BASEDIR" == "x" ]; then + echo "Could not determine base dir." + exit -1 +fi + +BLOCKEDFILE=$BASEDIR/settings/ip_blocks +LOGFILE=$BASEDIR/log/ip_blocks.log LONG_PERIOD='1 hour' SHORT_PERIOD='10 min' @@ -17,6 +23,11 @@ SRCHSHORT_LIMIT='10 min' PSQLCMD='psql -qtA -d nominatim' +curload=`cat /proc/loadavg | sed 's:[. ].*::'` +if [ "$curload" -gt "15" ]; then + REVSHORT_LIMIT=$((REVSHORT_LIMIT/2)) +fi + # Blocking candidates $PSQLCMD > $BLOCKEDFILE.newblocks << ENDOFQUERY SELECT ipaddress FROM @@ -64,10 +75,12 @@ if [ "x$blocked" == "x" ]; then mv $BLOCKEDFILE.newblocks $BLOCKEDFILE else $PSQLCMD > $BLOCKEDFILE.newlifted << ENDOFQUERY + SELECT column1 FROM ( VALUES ('$blocked') EXCEPT (SELECT DISTINCT ipaddress FROM new_query_log WHERE starttime > now() - interval '$COOLOFF_PERIOD') + ) as q ORDER BY column1; ENDOFQUERY no_lifted=`cat $BLOCKEDFILE.newlifted | wc -w`