Randomize sync time

This commit is contained in:
Jamie Cameron
2008-06-22 06:46:35 +00:00
parent 50d96e1171
commit 2e4f342c6e
3 changed files with 23 additions and 2 deletions

View 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.

View File

@@ -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' => '*' };

18
time/postinstall.pl Normal file
View File

@@ -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);
}
}