]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- Updated contrib warmup.cmd/sh to support two modes - load
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Mon, 5 Jan 2015 13:58:51 +0000 (13:58 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Mon, 5 Jan 2015 13:58:51 +0000 (13:58 +0000)
  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

contrib/unbound_cache.cmd
contrib/unbound_cache.sh
contrib/warmup.cmd
contrib/warmup.sh
doc/Changelog

index 0f0069388dfb2477ab8770b4987d38d8bf327f2a..532162b16191003c93a2cf9dad85ba23a3c198cc 100644 (file)
@@ -2,7 +2,7 @@
 rem --------------------------------------------------------------\r
 rem -- DNS cache save/load script\r
 rem --\r
-rem -- Version 1.0\r
+rem -- Version 1.2\r
 rem -- By Yuri Voinov (c) 2014\r
 rem --------------------------------------------------------------\r
 \r
@@ -19,31 +19,42 @@ exit 1
 \r
 :start\r
 \r
-set arg=%1\r
+rem arg1 - command (optional)\r
+rem arg2 - file name (optional)\r
+set arg1=%1\r
+set arg2=%2\r
 \r
-if /I "%arg%" == "-h" goto help\r
+if /I "%arg1%" == "-h" goto help\r
 \r
-if "%arg%" == "" (\r
+if "%arg1%" == "" (\r
 echo Loading cache from %program_path%\%fname%\r
+dir /a %program_path%\%fname%\r
 type %program_path%\%fname%|%uc% load_cache\r
 goto end\r
 )\r
 \r
-if /I "%arg%" == "-s" (\r
+if defined %arg2% (goto Not_Defined) else (goto Defined)\r
+\r
+rem If file not specified; use default dump file\r
+:Not_defined\r
+if /I "%arg1%" == "-s" (\r
 echo Saving cache to %program_path%\%fname%\r
 %uc% dump_cache>%program_path%\%fname%\r
+dir /a %program_path%\%fname%\r
 echo ok\r
 goto end\r
 )\r
 \r
-if /I "%arg%" == "-l" (\r
+if /I "%arg1%" == "-l" (\r
 echo Loading cache from %program_path%\%fname%\r
+dir /a %program_path%\%fname%\r
 type %program_path%\%fname%|%uc% load_cache\r
 goto end\r
 )\r
 \r
-if /I "%arg%" == "-r" (\r
+if /I "%arg1%" == "-r" (\r
 echo Saving cache to %program_path%\%fname%\r
+dir /a %program_path%\%fname%\r
 %uc% dump_cache>%program_path%\%fname%\r
 echo ok\r
 echo Loading cache from %program_path%\%fname%\r
@@ -51,15 +62,44 @@ type %program_path%\%fname%|%uc% load_cache
 goto end\r
 )\r
 \r
+rem If file name specified; use this filename\r
+:Defined\r
+if /I "%arg1%" == "-s" (\r
+echo Saving cache to %arg2%\r
+%uc% dump_cache>%arg2%\r
+dir /a %arg2%\r
+echo ok\r
+goto end\r
+)\r
+\r
+if /I "%arg1%" == "-l" (\r
+echo Loading cache from %arg2%\r
+dir /a %arg2%\r
+type %arg2%|%uc% load_cache\r
+goto end\r
+)\r
+\r
+if /I "%arg1%" == "-r" (\r
+echo Saving cache to %arg2%\r
+dir /a %arg2%\r
+%uc% dump_cache>%arg2%\r
+echo ok\r
+echo Loading cache from %arg2%\r
+type %arg2%|%uc% load_cache\r
+goto end\r
+)\r
+\r
 :help\r
-echo Usage: unbound_cache.cmd [-s] or [-l] or [-r] or [-h]\r
+echo Usage: unbound_cache.cmd [-s] or [-l] or [-r] or [-h] [filename]\r
 echo.\r
 echo l - Load - default mode. Warming up Unbound DNS cache from saved file. cache-ttl must be high value.\r
 echo s - Save - save Unbound DNS cache contents to plain file with domain names.\r
 echo r - Reload - reloadind new cache entries and refresh existing cache\r
 echo h - this screen.\r
+echo filename - file to save/load dumped cache. If not specified, %program_path%\%fname% will be used instead.\r
 echo Note: Run without any arguments will be in default mode.\r
 echo       Also, unbound-control must be configured.\r
 exit 1\r
 \r
 :end\r
+exit 0\r
index c3dd9c3a2df939ec3ca8f111fe95681212f85084..b3e876ba901227ea954b462d3e0c331c9ab53760 100644 (file)
@@ -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
index d7df018273823a897cdce9b6e9aaf32010da59e3..b3895a86fe2e395c4f02cf65d863031a9fa811a2 100644 (file)
 @echo off\r
 \r
 rem --------------------------------------------------------------\r
-rem -- Warm up DNS cache script by your own MRU domains\r
+rem -- Warm up DNS cache script by your own MRU domains or from\r
+rem -- file when it specified as script argument.\r
 rem --\r
-rem -- Version 1.0\r
+rem -- Version 1.1\r
 rem -- By Yuri Voinov (c) 2014\r
 rem --------------------------------------------------------------\r
 \r
+rem DNS host address\r
+set address="127.0.0.1"\r
+\r
 rem Check dig installed\r
 for /f "delims=" %%a in ('where dig') do @set dig=%%a\r
 if /I "%dig%"=="" echo Dig not found. If installed, add path to PATH environment variable. & exit 1\r
 echo Dig found: %dig%\r
 \r
-echo Warming up cache by MRU domains...\r
-rem dig -f my_domains 1>nul 2>nul\r
-rem echo Done.\r
+set arg=%1%\r
+\r
+if defined %arg% (goto builtin) else (goto from_file)\r
 \r
+:builtin\r
+echo Warming up cache by MRU domains...\r
 for %%a in (\r
-mail.ru\r
-my.mail.ru\r
-mra.mail.ru\r
+2gis.ru\r
+admir.kz\r
+adobe.com\r
 agent.mail.ru\r
-news.mail.ru\r
-icq.com\r
-lenta.ru\r
-gazeta.ru\r
-peerbet.ru\r
-www.opennet.ru\r
-snob.ru\r
+aimp.ru\r
+akamai.com\r
+akamai.net\r
+almaty.tele2.kz\r
+aol.com\r
+apple.com\r
+arin.com\r
 artlebedev.ru\r
-mail.google.com\r
-translate.google.com\r
-drive.google.com\r
-google.com\r
-google.kz\r
-drive.google.com\r
+auto.mail.ru\r
+beeline.kz\r
+bing.com\r
 blogspot.com\r
+comodo.com\r
+dnscrypt.org\r
+drive.google.com\r
+drive.mail.ru\r
+facebook.com\r
 farmanager.com\r
+fb.com\r
+firefox.com\r
 forum.farmanager.com\r
+gazeta.ru\r
+getsharex.com\r
+gismeteo.ru\r
+google.com\r
+google.kz\r
+google.ru\r
+googlevideo.com\r
+goto.kz\r
+iana.org\r
+icq.com\r
+imap.mail.ru\r
+instagram.com\r
+intel.com\r
+irr.kz\r
+java.com\r
+kaspersky.com\r
+kaspersky.ru\r
+kcell.kz\r
+krisha.kz\r
+lady.mail.ru\r
+lenta.ru\r
+libreoffice.org\r
+linkedin.com\r
+livejournal.com\r
+mail.google.com\r
+mail.ru\r
+microsoft.com\r
+mozilla.org\r
+mra.mail.ru\r
+munin-monitoring.org\r
+my.mail.ru\r
+news.bbcimg.co.uk\r
+news.mail.ru\r
+newsimg.bbc.net.uk\r
+nvidia.com\r
+odnoklassniki.ru\r
+ok.ru\r
+opencsw.org\r
+opendns.com\r
+opendns.org\r
+opennet.ru\r
+opera.com\r
+oracle.com\r
+peerbet.ru\r
+piriform.com\r
 plugring.farmanager.com\r
+privoxy.org\r
+qip.ru\r
+raidcall.com\r
+rambler.ru\r
+reddit.com\r
+ru.wikipedia.org\r
+shallalist.de\r
+skype.com\r
+snob.ru\r
+squid-cache.org\r
+squidclamav.darold.net\r
+squidguard.org\r
+ssl.comodo.com\r
+ssl.verisign.com\r
 symantec.com\r
 symantecliveupdate.com\r
-shalla.de\r
-torstatus.blutmagie.de\r
+tele2.kz\r
+tengrinews.kz\r
+thunderbird.com\r
 torproject.org\r
-dnscrypt.org\r
+torstatus.blutmagie.de\r
+translate.google.com\r
 unbound.net\r
-getsharex.com\r
-skype.com\r
+verisign.com\r
+vk.com\r
+vk.me\r
+vk.ru\r
+vkontakte.com\r
+vkontakte.ru\r
 vlc.org\r
-aimp.ru\r
-mozilla.org\r
-libreoffice.org\r
-piriform.com\r
-raidcall.com\r
-nvidia.com\r
-intel.com\r
-microsoft.com\r
+watsapp.net\r
+weather.mail.ru\r
 windowsupdate.com\r
-ru.wikipedia.org\r
+www.baidu.com\r
 www.bbc.co.uk\r
-tengrinews.kz\r
-) do "%dig%" %%a 1>nul 2>nul\r
+www.internic.net\r
+www.opennet.ru\r
+www.topgear.com\r
+ya.ru\r
+yahoo.com\r
+yandex.com\r
+yandex.ru\r
+youtube.com\r
+ytimg.com\r
+) do "%dig%" %%a @%address% 1>nul 2>nul\r
+goto end\r
 \r
+:from_file\r
+echo Warming up cache from %1% file...\r
+%dig% -f %arg% @%address% 1>nul 2>nul \r
+\r
+:end\r
 echo Saving cache...\r
-unbound_cache.cmd -s\r
+if exist unbound_cache.cmd unbound_cache.cmd -s\r
 echo Done.\r
+\r
+exit 0
\ No newline at end of file
index 820f019d71225776cf933ef6457e002d14d3f988..b4d9135a68dd74c0f39ed52c6569d55a19f5a33b 100644 (file)
 #!/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 <<EOT
-mail.ru
-my.mail.ru
-mra.mail.ru
+$dig -f - @$address >/dev/null 2>&1 <<EOT
+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
+clamav.net
+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
+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
+www.internic.net
+www.opennet.ru
+www.topgear.com
+ya.ru
+yahoo.com
+yandex.com
+yandex.ru
+youtube.com
+ytimg.com
 EOT
+else
+ echo "Warming up cache from $1 file..."
+ $cat $1 | $dig -f - @$address >/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
index 5a99c072debbb7ec7ef91511c3a1d703cfc3844d..0f42de28b56455df2f79bf0b5e519f3b99e36f91 100644 (file)
@@ -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.