- 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
This commit is contained in:
Wouter Wijngaards 2015-01-05 13:58:51 +00:00
parent 7319df2e32
commit f053fa009c
5 changed files with 371 additions and 116 deletions

View File

@ -2,7 +2,7 @@
rem -------------------------------------------------------------- rem --------------------------------------------------------------
rem -- DNS cache save/load script rem -- DNS cache save/load script
rem -- rem --
rem -- Version 1.0 rem -- Version 1.2
rem -- By Yuri Voinov (c) 2014 rem -- By Yuri Voinov (c) 2014
rem -------------------------------------------------------------- rem --------------------------------------------------------------
@ -19,47 +19,87 @@ exit 1
:start :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% echo Loading cache from %program_path%\%fname%
dir /a %program_path%\%fname%
type %program_path%\%fname%|%uc% load_cache type %program_path%\%fname%|%uc% load_cache
goto end 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% echo Saving cache to %program_path%\%fname%
%uc% dump_cache>%program_path%\%fname% %uc% dump_cache>%program_path%\%fname%
dir /a %program_path%\%fname%
echo ok echo ok
goto end 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 "%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% echo Loading cache from %program_path%\%fname%
type %program_path%\%fname%|%uc% load_cache type %program_path%\%fname%|%uc% load_cache
goto end goto end
) )
if /I "%arg%" == "-r" ( rem If file name specified; use this filename
echo Saving cache to %program_path%\%fname% :Defined
%uc% dump_cache>%program_path%\%fname% if /I "%arg1%" == "-s" (
echo Saving cache to %arg2%
%uc% dump_cache>%arg2%
dir /a %arg2%
echo ok echo ok
echo Loading cache from %program_path%\%fname% goto end
type %program_path%\%fname%|%uc% load_cache )
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 goto end
) )
:help :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.
echo l - Load - default mode. Warming up Unbound DNS cache from saved file. cache-ttl must be high value. 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 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 r - Reload - reloadind new cache entries and refresh existing cache
echo h - this screen. 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 Note: Run without any arguments will be in default mode.
echo Also, unbound-control must be configured. echo Also, unbound-control must be configured.
exit 1 exit 1
:end :end
exit 0

View File

@ -1,13 +1,13 @@
#!/sbin/sh #!/sbin/sh
#
# -------------------------------------------------------------- # --------------------------------------------------------------
# -- DNS cache save/load script # -- DNS cache save/load script
# -- # --
# -- Version 1.0 # -- Version 1.2
# -- By Yuri Voinov (c) 2006, 2014 # -- 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` CAT=`which cat`
CUT=`which cut` CUT=`which cut`
ECHO=`which echo` ECHO=`which echo`
EXPR=`which expr`
GETOPT=`which getopt` GETOPT=`which getopt`
ID=`which id` ID=`which id`
PRINTF=`which printf` LS=`which ls`
############### ###############
# Subroutines # # Subroutines #
@ -38,12 +39,13 @@ PRINTF=`which printf`
usage_note () usage_note ()
{ {
# Script usage note # Script usage note
$ECHO "Usage: `$BASENAME $0` [-s] or [-l] or [-r] or [-h]" $ECHO "Usage: `$BASENAME $0` [-s] or [-l] or [-r] or [-h] [filename]"
$ECHO $ECHO .
$ECHO "l - Load - default mode. Warming up Unbound DNS cache from saved file. cache-ttl must be high value." $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 "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 "r - Reload - reloadind new cache entries and refresh existing cache"
$ECHO "h - this screen." $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 "Note: Run without any arguments will be in default mode."
$ECHO " Also, unbound-control must be configured." $ECHO " Also, unbound-control must be configured."
exit 0 exit 0
@ -68,7 +70,12 @@ check_uc ()
check_saved_file () 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 .
$ECHO "ERROR: File $CONF/$FNAME does not exists. Save it first." $ECHO "ERROR: File $CONF/$FNAME does not exists. Save it first."
exit 1 exit 1
@ -78,24 +85,42 @@ check_saved_file ()
save_cache () save_cache ()
{ {
# Save unbound cache # Save unbound cache
$PRINTF "Saving cache in $CONF/$FNAME..." filename=$1
$UC dump_cache>$CONF/$FNAME 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" $ECHO "ok"
} }
load_cache () load_cache ()
{ {
# Load saved cache contents and warmup DNS cache # Load saved cache contents and warmup cache
$PRINTF "Loading cache from saved $CONF/$FNAME..." filename=$1
check_saved_file if [ -z "$filename" ]; then
$CAT $CONF/$FNAME|$UC load_cache $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 () reload_cache ()
{ {
# Reloading and refresh existing cache and saved dump # Reloading and refresh existing cache and saved dump
save_cache filename=$1
load_cache save_cache $filename
load_cache $filename
} }
############## ##############
@ -109,27 +134,41 @@ root_check
check_uc check_uc
# Check command-line arguments # Check command-line arguments
if [ "x$1" = "x" ]; then if [ "x$*" = "x" ]; then
# If arguments list empty, load cache by default # If arguments list empty,load cache by default
load_cache load_cache
else else
arg_list=$1 arg_list=$*
# Parse command line # Parse command line
set -- `$GETOPT sSlLrRhH: $arg_list` || { set -- `$GETOPT sSlLrRhH: $arg_list` || {
usage_note 1>&2 usage_note 1>&2
} }
# Read arguments # Read arguments
for i in $arg_list for i in $arg_list
do do
case $i in case $i in
-s | -S) save_cache;; -s | -S) save="1";;
-l | -L) load_cache;; -l | -L) save="0";;
-r | -R) reload_cache;; -r | -R) save="2";;
-h | -H | \?) usage_note;; -h | -H | \?) usage_note;;
*) shift
file=$1
break;;
esac esac
break shift
done 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 fi
exit 0 exit 0

View File

@ -1,68 +1,153 @@
@echo off @echo off
rem -------------------------------------------------------------- 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 --
rem -- Version 1.0 rem -- Version 1.1
rem -- By Yuri Voinov (c) 2014 rem -- By Yuri Voinov (c) 2014
rem -------------------------------------------------------------- rem --------------------------------------------------------------
rem DNS host address
set address="127.0.0.1"
rem Check dig installed rem Check dig installed
for /f "delims=" %%a in ('where dig') do @set dig=%%a 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 if /I "%dig%"=="" echo Dig not found. If installed, add path to PATH environment variable. & exit 1
echo Dig found: %dig% echo Dig found: %dig%
echo Warming up cache by MRU domains... set arg=%1%
rem dig -f my_domains 1>nul 2>nul
rem echo Done.
if defined %arg% (goto builtin) else (goto from_file)
:builtin
echo Warming up cache by MRU domains...
for %%a in ( for %%a in (
mail.ru 2gis.ru
my.mail.ru admir.kz
mra.mail.ru adobe.com
agent.mail.ru agent.mail.ru
news.mail.ru aimp.ru
icq.com akamai.com
lenta.ru akamai.net
gazeta.ru almaty.tele2.kz
peerbet.ru aol.com
www.opennet.ru apple.com
snob.ru arin.com
artlebedev.ru artlebedev.ru
mail.google.com auto.mail.ru
translate.google.com beeline.kz
bing.com
blogspot.com
comodo.com
dnscrypt.org
drive.google.com 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.com
google.kz google.kz
drive.google.com google.ru
blogspot.com googlevideo.com
farmanager.com goto.kz
forum.farmanager.com 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 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 symantec.com
symantecliveupdate.com symantecliveupdate.com
shalla.de tele2.kz
torstatus.blutmagie.de
torproject.org
dnscrypt.org
unbound.net
getsharex.com
skype.com
vlc.org
aimp.ru
mozilla.org
libreoffice.org
piriform.com
raidcall.com
nvidia.com
intel.com
microsoft.com
windowsupdate.com
ru.wikipedia.org
www.bbc.co.uk
tengrinews.kz tengrinews.kz
) do "%dig%" %%a 1>nul 2>nul thunderbird.com
torproject.org
torstatus.blutmagie.de
translate.google.com
unbound.net
verisign.com
vk.com
vk.me
vk.ru
vkontakte.com
vkontakte.ru
vlc.org
watsapp.net
weather.mail.ru
windowsupdate.com
www.baidu.com
www.bbc.co.uk
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... echo Saving cache...
unbound_cache.cmd -s if exist unbound_cache.cmd unbound_cache.cmd -s
echo Done. echo Done.
exit 0

View File

@ -1,65 +1,150 @@
#!/bin/sh #!/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 # -- By Yuri Voinov (c) 2014
# -------------------------------------------------------------- # --------------------------------------------------------------
# Default DNS host address
address="127.0.0.1"
cat=`which cat`
dig=`which dig` dig=`which dig`
if [ -z "$1" ]; then
echo "Warming up cache by MRU domains..." echo "Warming up cache by MRU domains..."
$dig -f - >/dev/null 2>&1 <<EOT $dig -f - @$address >/dev/null 2>&1 <<EOT
mail.ru 2gis.ru
my.mail.ru admir.kz
mra.mail.ru adobe.com
agent.mail.ru agent.mail.ru
news.mail.ru aimp.ru
icq.com akamai.com
lenta.ru akamai.net
gazeta.ru almaty.tele2.kz
peerbet.ru aol.com
www.opennet.ru apple.com
snob.ru arin.com
artlebedev.ru artlebedev.ru
mail.google.com auto.mail.ru
translate.google.com beeline.kz
bing.com
blogspot.com
clamav.net
comodo.com
dnscrypt.org
drive.google.com 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.com
google.kz google.kz
drive.google.com google.ru
blogspot.com googlevideo.com
farmanager.com goto.kz
forum.farmanager.com 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 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 symantec.com
symantecliveupdate.com symantecliveupdate.com
shalla.de tele2.kz
torstatus.blutmagie.de
torproject.org
dnscrypt.org
unbound.net
getsharex.com
skype.com
vlc.org
aimp.ru
mozilla.org
libreoffice.org
piriform.com
raidcall.com
nvidia.com
intel.com
microsoft.com
windowsupdate.com
ru.wikipedia.org
www.bbc.co.uk
tengrinews.kz tengrinews.kz
thunderbird.com
torproject.org
torstatus.blutmagie.de
translate.google.com
unbound.net
verisign.com
vk.com
vk.me
vk.ru
vkontakte.com
vkontakte.ru
vlc.org
watsapp.net
weather.mail.ru
windowsupdate.com
www.baidu.com
www.bbc.co.uk
www.internic.net
www.opennet.ru
www.topgear.com
ya.ru
yahoo.com
yandex.com
yandex.ru
youtube.com
ytimg.com
EOT EOT
else
echo "Warming up cache from $1 file..."
$cat $1 | $dig -f - @$address >/dev/null 2>&1
fi
echo "Done." echo "Done."
echo "Saving cache..." echo "Saving cache..."
/usr/local/bin/unbound_cache.sh -s script=`which unbound_cache.sh`
[ -f "$script" ] && $script -s
echo "Done." echo "Done."
exit 0 exit 0

View File

@ -8,6 +8,12 @@
for installs where config is not in the prefix location. for installs where config is not in the prefix location.
- Fix #634: fix fail to start on Linux LTS 3.14.X, ignores missing - Fix #634: fix fail to start on Linux LTS 3.14.X, ignores missing
IP_MTU_DISCOVER OMIT option (fix from Remi Gacogne). 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 9 December 2014: Wouter
- svn trunk has 1.5.2 in development. - svn trunk has 1.5.2 in development.