From: Wouter Wijngaards Date: Mon, 5 Jan 2015 13:58:51 +0000 (+0000) Subject: - Updated contrib warmup.cmd/sh to support two modes - load X-Git-Tag: release-1.5.2rc1~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f053fa009cbe4923de4c8c86a2fe4a4fb804a7e0;p=thirdparty%2Funbound.git - Updated contrib warmup.cmd/sh to support two modes - load from pre-defined list of domains or (with filename as argument) load from user-specified list of domains, and updated contrib unbound_cache.sh/cmd to support loading/save/reload cache to/from default path or (with secondary argument) arbitrary path/filename, from Yuri Voinov. git-svn-id: file:///svn/unbound/trunk@3300 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/contrib/unbound_cache.cmd b/contrib/unbound_cache.cmd index 0f0069388..532162b16 100644 --- a/contrib/unbound_cache.cmd +++ b/contrib/unbound_cache.cmd @@ -2,7 +2,7 @@ rem -------------------------------------------------------------- rem -- DNS cache save/load script rem -- -rem -- Version 1.0 +rem -- Version 1.2 rem -- By Yuri Voinov (c) 2014 rem -------------------------------------------------------------- @@ -19,31 +19,42 @@ exit 1 :start -set arg=%1 +rem arg1 - command (optional) +rem arg2 - file name (optional) +set arg1=%1 +set arg2=%2 -if /I "%arg%" == "-h" goto help +if /I "%arg1%" == "-h" goto help -if "%arg%" == "" ( +if "%arg1%" == "" ( echo Loading cache from %program_path%\%fname% +dir /a %program_path%\%fname% type %program_path%\%fname%|%uc% load_cache goto end ) -if /I "%arg%" == "-s" ( +if defined %arg2% (goto Not_Defined) else (goto Defined) + +rem If file not specified; use default dump file +:Not_defined +if /I "%arg1%" == "-s" ( echo Saving cache to %program_path%\%fname% %uc% dump_cache>%program_path%\%fname% +dir /a %program_path%\%fname% echo ok goto end ) -if /I "%arg%" == "-l" ( +if /I "%arg1%" == "-l" ( echo Loading cache from %program_path%\%fname% +dir /a %program_path%\%fname% type %program_path%\%fname%|%uc% load_cache goto end ) -if /I "%arg%" == "-r" ( +if /I "%arg1%" == "-r" ( echo Saving cache to %program_path%\%fname% +dir /a %program_path%\%fname% %uc% dump_cache>%program_path%\%fname% echo ok echo Loading cache from %program_path%\%fname% @@ -51,15 +62,44 @@ type %program_path%\%fname%|%uc% load_cache goto end ) +rem If file name specified; use this filename +:Defined +if /I "%arg1%" == "-s" ( +echo Saving cache to %arg2% +%uc% dump_cache>%arg2% +dir /a %arg2% +echo ok +goto end +) + +if /I "%arg1%" == "-l" ( +echo Loading cache from %arg2% +dir /a %arg2% +type %arg2%|%uc% load_cache +goto end +) + +if /I "%arg1%" == "-r" ( +echo Saving cache to %arg2% +dir /a %arg2% +%uc% dump_cache>%arg2% +echo ok +echo Loading cache from %arg2% +type %arg2%|%uc% load_cache +goto end +) + :help -echo Usage: unbound_cache.cmd [-s] or [-l] or [-r] or [-h] +echo Usage: unbound_cache.cmd [-s] or [-l] or [-r] or [-h] [filename] echo. echo l - Load - default mode. Warming up Unbound DNS cache from saved file. cache-ttl must be high value. echo s - Save - save Unbound DNS cache contents to plain file with domain names. echo r - Reload - reloadind new cache entries and refresh existing cache echo h - this screen. +echo filename - file to save/load dumped cache. If not specified, %program_path%\%fname% will be used instead. echo Note: Run without any arguments will be in default mode. echo Also, unbound-control must be configured. exit 1 :end +exit 0 diff --git a/contrib/unbound_cache.sh b/contrib/unbound_cache.sh index c3dd9c3a2..b3e876ba9 100644 --- a/contrib/unbound_cache.sh +++ b/contrib/unbound_cache.sh @@ -1,13 +1,13 @@ #!/sbin/sh -# + # -------------------------------------------------------------- # -- DNS cache save/load script # -- -# -- Version 1.0 +# -- Version 1.2 # -- By Yuri Voinov (c) 2006, 2014 # -------------------------------------------------------------- # -# ident "@(#)unbound_cache.sh 1.1 14/04/26 YV" +# ident "@(#)unbound_cache.sh 1.2 14/10/30 YV" # ############# @@ -27,9 +27,10 @@ BASENAME=`which basename` CAT=`which cat` CUT=`which cut` ECHO=`which echo` +EXPR=`which expr` GETOPT=`which getopt` ID=`which id` -PRINTF=`which printf` +LS=`which ls` ############### # Subroutines # @@ -38,12 +39,13 @@ PRINTF=`which printf` usage_note () { # Script usage note - $ECHO "Usage: `$BASENAME $0` [-s] or [-l] or [-r] or [-h]" - $ECHO + $ECHO "Usage: `$BASENAME $0` [-s] or [-l] or [-r] or [-h] [filename]" + $ECHO . $ECHO "l - Load - default mode. Warming up Unbound DNS cache from saved file. cache-ttl must be high value." $ECHO "s - Save - save Unbound DNS cache contents to plain file with domain names." $ECHO "r - Reload - reloadind new cache entries and refresh existing cache" $ECHO "h - this screen." + $ECHO "filename - file to save/load dumped cache. If not specified, $CONF/$FNAME will be used instead." $ECHO "Note: Run without any arguments will be in default mode." $ECHO " Also, unbound-control must be configured." exit 0 @@ -68,7 +70,12 @@ check_uc () check_saved_file () { - if [ ! -f "$CONF/$FNAME" ]; then + filename=$1 + if [ ! -z "$filename" -a ! -f "$filename" ]; then + $ECHO . + $ECHO "ERROR: File $filename does not exists. Save it first." + exit 1 + elif [ ! -f "$CONF/$FNAME" ]; then $ECHO . $ECHO "ERROR: File $CONF/$FNAME does not exists. Save it first." exit 1 @@ -78,24 +85,42 @@ check_saved_file () save_cache () { # Save unbound cache - $PRINTF "Saving cache in $CONF/$FNAME..." - $UC dump_cache>$CONF/$FNAME + filename=$1 + if [ -z "$filename" ]; then + $ECHO "Saving cache in $CONF/$FNAME..." + $UC dump_cache>$CONF/$FNAME + $LS -lh $CONF/$FNAME + else + $ECHO "Saving cache in $filename..." + $UC dump_cache>$filename + $LS -lh $filename + fi $ECHO "ok" } load_cache () { - # Load saved cache contents and warmup DNS cache - $PRINTF "Loading cache from saved $CONF/$FNAME..." - check_saved_file - $CAT $CONF/$FNAME|$UC load_cache + # Load saved cache contents and warmup cache + filename=$1 + if [ -z "$filename" ]; then + $ECHO "Loading cache from saved $CONF/$FNAME..." + $LS -lh $CONF/$FNAME + check_saved_file $filename + $CAT $CONF/$FNAME|$UC load_cache + else + $ECHO "Loading cache from saved $filename..." + $LS -lh $filename + check_saved_file $filename + $CAT $filename|$UC load_cache + fi } reload_cache () { # Reloading and refresh existing cache and saved dump - save_cache - load_cache + filename=$1 + save_cache $filename + load_cache $filename } ############## @@ -109,27 +134,41 @@ root_check check_uc # Check command-line arguments -if [ "x$1" = "x" ]; then -# If arguments list empty, load cache by default +if [ "x$*" = "x" ]; then + # If arguments list empty,load cache by default load_cache else - arg_list=$1 + arg_list=$* # Parse command line set -- `$GETOPT sSlLrRhH: $arg_list` || { usage_note 1>&2 } - # Read arguments + # Read arguments for i in $arg_list do case $i in - -s | -S) save_cache;; - -l | -L) load_cache;; - -r | -R) reload_cache;; + -s | -S) save="1";; + -l | -L) save="0";; + -r | -R) save="2";; -h | -H | \?) usage_note;; + *) shift + file=$1 + break;; esac - break + shift done + + # Remove trailing -- + shift `$EXPR $OPTIND - 1` +fi + +if [ "$save" = "1" ]; then + save_cache $file +elif [ "$save" = "0" ]; then + load_cache $file +elif [ "$save" = "2" ]; then + reload_cache $file fi exit 0 \ No newline at end of file diff --git a/contrib/warmup.cmd b/contrib/warmup.cmd index d7df01827..b3895a86f 100644 --- a/contrib/warmup.cmd +++ b/contrib/warmup.cmd @@ -1,68 +1,153 @@ @echo off rem -------------------------------------------------------------- -rem -- Warm up DNS cache script by your own MRU domains +rem -- Warm up DNS cache script by your own MRU domains or from +rem -- file when it specified as script argument. rem -- -rem -- Version 1.0 +rem -- Version 1.1 rem -- By Yuri Voinov (c) 2014 rem -------------------------------------------------------------- +rem DNS host address +set address="127.0.0.1" + rem Check dig installed for /f "delims=" %%a in ('where dig') do @set dig=%%a if /I "%dig%"=="" echo Dig not found. If installed, add path to PATH environment variable. & exit 1 echo Dig found: %dig% -echo Warming up cache by MRU domains... -rem dig -f my_domains 1>nul 2>nul -rem echo Done. +set arg=%1% + +if defined %arg% (goto builtin) else (goto from_file) +:builtin +echo Warming up cache by MRU domains... for %%a in ( -mail.ru -my.mail.ru -mra.mail.ru +2gis.ru +admir.kz +adobe.com agent.mail.ru -news.mail.ru -icq.com -lenta.ru -gazeta.ru -peerbet.ru -www.opennet.ru -snob.ru +aimp.ru +akamai.com +akamai.net +almaty.tele2.kz +aol.com +apple.com +arin.com artlebedev.ru -mail.google.com -translate.google.com -drive.google.com -google.com -google.kz -drive.google.com +auto.mail.ru +beeline.kz +bing.com blogspot.com +comodo.com +dnscrypt.org +drive.google.com +drive.mail.ru +facebook.com farmanager.com +fb.com +firefox.com forum.farmanager.com +gazeta.ru +getsharex.com +gismeteo.ru +google.com +google.kz +google.ru +googlevideo.com +goto.kz +iana.org +icq.com +imap.mail.ru +instagram.com +intel.com +irr.kz +java.com +kaspersky.com +kaspersky.ru +kcell.kz +krisha.kz +lady.mail.ru +lenta.ru +libreoffice.org +linkedin.com +livejournal.com +mail.google.com +mail.ru +microsoft.com +mozilla.org +mra.mail.ru +munin-monitoring.org +my.mail.ru +news.bbcimg.co.uk +news.mail.ru +newsimg.bbc.net.uk +nvidia.com +odnoklassniki.ru +ok.ru +opencsw.org +opendns.com +opendns.org +opennet.ru +opera.com +oracle.com +peerbet.ru +piriform.com plugring.farmanager.com +privoxy.org +qip.ru +raidcall.com +rambler.ru +reddit.com +ru.wikipedia.org +shallalist.de +skype.com +snob.ru +squid-cache.org +squidclamav.darold.net +squidguard.org +ssl.comodo.com +ssl.verisign.com symantec.com symantecliveupdate.com -shalla.de -torstatus.blutmagie.de +tele2.kz +tengrinews.kz +thunderbird.com torproject.org -dnscrypt.org +torstatus.blutmagie.de +translate.google.com unbound.net -getsharex.com -skype.com +verisign.com +vk.com +vk.me +vk.ru +vkontakte.com +vkontakte.ru vlc.org -aimp.ru -mozilla.org -libreoffice.org -piriform.com -raidcall.com -nvidia.com -intel.com -microsoft.com +watsapp.net +weather.mail.ru windowsupdate.com -ru.wikipedia.org +www.baidu.com www.bbc.co.uk -tengrinews.kz -) do "%dig%" %%a 1>nul 2>nul +www.internic.net +www.opennet.ru +www.topgear.com +ya.ru +yahoo.com +yandex.com +yandex.ru +youtube.com +ytimg.com +) do "%dig%" %%a @%address% 1>nul 2>nul +goto end +:from_file +echo Warming up cache from %1% file... +%dig% -f %arg% @%address% 1>nul 2>nul + +:end echo Saving cache... -unbound_cache.cmd -s +if exist unbound_cache.cmd unbound_cache.cmd -s echo Done. + +exit 0 \ No newline at end of file diff --git a/contrib/warmup.sh b/contrib/warmup.sh index 820f019d7..b4d9135a6 100644 --- a/contrib/warmup.sh +++ b/contrib/warmup.sh @@ -1,65 +1,150 @@ #!/bin/sh # -------------------------------------------------------------- -# -- Warm up DNS cache script by your own MRU domains +# -- Warm up DNS cache script by your own MRU domains or from +# -- file when it specified as script argument. # -- -# -- Version 1.0 +# -- Version 1.1 # -- By Yuri Voinov (c) 2014 # -------------------------------------------------------------- +# Default DNS host address +address="127.0.0.1" + +cat=`which cat` dig=`which dig` +if [ -z "$1" ]; then echo "Warming up cache by MRU domains..." -$dig -f - >/dev/null 2>&1 </dev/null 2>&1 </dev/null 2>&1 +fi + echo "Done." echo "Saving cache..." -/usr/local/bin/unbound_cache.sh -s +script=`which unbound_cache.sh` +[ -f "$script" ] && $script -s echo "Done." exit 0 diff --git a/doc/Changelog b/doc/Changelog index 5a99c072d..0f42de28b 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -8,6 +8,12 @@ for installs where config is not in the prefix location. - Fix #634: fix fail to start on Linux LTS 3.14.X, ignores missing IP_MTU_DISCOVER OMIT option (fix from Remi Gacogne). + - Updated contrib warmup.cmd/sh to support two modes - load + from pre-defined list of domains or (with filename as argument) + load from user-specified list of domains, and updated contrib + unbound_cache.sh/cmd to support loading/save/reload cache to/from + default path or (with secondary argument) arbitrary path/filename, + from Yuri Voinov. 9 December 2014: Wouter - svn trunk has 1.5.2 in development.