From 2e4f342c6eada50d4c99c5f7a816dfcfebd679ff Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Sun, 22 Jun 2008 06:46:35 +0000 Subject: [PATCH] Randomize sync time --- time/CHANGELOG | 2 ++ time/index.cgi | 5 +++-- time/postinstall.pl | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 time/postinstall.pl diff --git a/time/CHANGELOG b/time/CHANGELOG index 2d1708cd2..50c8621b1 100644 --- a/time/CHANGELOG +++ b/time/CHANGELOG @@ -16,3 +16,5 @@ Display a more complete message if unable to get the hardware time from hwclock. ---- Changes since 1.390 ---- Changed the main page to use tabs to split up the system time, timezone and sync sections. Re-wrote all user interface code to use Webmin's new UI library. +---- Changes since 1.420 ---- +The default NTP sync time is now set randomly instead of at midnight, and any existing automatic sync done at midnight is changed to a random time. This reduces load on public NTP servers. diff --git a/time/index.cgi b/time/index.cgi index 85209eeb2..c3b14612d 100755 --- a/time/index.cgi +++ b/time/index.cgi @@ -166,8 +166,9 @@ if ( ( !$access{ 'sysdate' } && &has_command( "date" ) || !$access{ 'hwdate' } & print &ui_table_row($text{'index_sched'}, &ui_radio("sched", $job ? 1 : 0, [ [ 0, $text{'no'} ], [ 1, $text{'index_schedyes'} ] ])); - $job ||= { 'mins' => '0', - 'hours' => '0', + &seed_random(); + $job ||= { 'mins' => int(rand()*60), + 'hours' => int(rand()*24), 'days' => '*', 'months' => '*', 'weekdays' => '*' }; diff --git a/time/postinstall.pl b/time/postinstall.pl new file mode 100644 index 000000000..9877b9277 --- /dev/null +++ b/time/postinstall.pl @@ -0,0 +1,18 @@ + +require 'time-lib.pl'; + +# Change time sync jobs running at midnight to a random time, to stop +# overloading public NTP servers +sub module_install +{ +&foreign_require("cron", "cron-lib.pl"); +local $job = &find_cron_job(); +if ($job && $job->{'mins'} eq '0' && $job->{'hours'} eq '0') { + # Midnight .. fix it + &seed_random(); + $job->{'mins'} = int(rand()*60); + $job->{'hours'} = int(rand()*24); + &cron::change_cron_job($job); + } +} +