Randomize sync time
authorJamie Cameron <jcameron@webmin.com>
Sun, 22 Jun 2008 06:46:35 +0000 (06:46 +0000)
committerJamie Cameron <jcameron@webmin.com>
Sun, 22 Jun 2008 06:46:35 +0000 (06:46 +0000)
time/CHANGELOG
time/index.cgi
time/postinstall.pl [new file with mode: 0644]

index 2d1708c..50c8621 100644 (file)
@@ -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.
index 85209ee..c3b1461 100755 (executable)
@@ -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 (file)
index 0000000..9877b92
--- /dev/null
@@ -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);
+       }
+}
+