Option to sync time at boot

This commit is contained in:
Jamie Cameron
2012-06-28 17:47:41 -07:00
parent 1b362d18b2
commit c3d71ffaff
5 changed files with 29 additions and 9 deletions

View File

@@ -678,7 +678,11 @@ $SIG{'USR1'} = 'miniserv::trigger_reload';
$SIG{'PIPE'} = 'IGNORE';
local $remove_session_count = 0;
$need_pipes = $config{'passdelay'} || $config{'session'};
$cron_runs = 0;
while(1) {
# Check if any webmin cron jobs are ready to run
&execute_ready_webmin_crons($cron_runs++);
# wait for a new connection, or a message from a child process
local ($i, $rmask);
if (@childpids <= $config{'maxconns'}) {
@@ -769,9 +773,6 @@ while(1) {
&write_blocked_file();
}
# Check if any webmin cron jobs are ready to run
&execute_ready_webmin_crons();
if ($config{'session'} && (++$remove_session_count%50) == 0) {
# Remove sessions with more than 7 days of inactivity,
local $s;
@@ -5572,16 +5573,25 @@ foreach $k (keys %{$_[1]}) {
close(ARFILE);
}
# execute_ready_webmin_crons()
# execute_ready_webmin_crons(run-count)
# Find and run any cron jobs that are due, based on their last run time and
# execution interval
sub execute_ready_webmin_crons
{
my ($runs) = @_;
my $now = time();
my $changed = 0;
foreach my $cron (@webmincrons) {
my $run = 0;
if (!$webmincron_last{$cron->{'id'}}) {
if ($runs == 0 && $cron->{'boot'}) {
# If cron job wants to be run at startup, run it now
$run = 1;
}
elsif ($cron->{'disabled'}) {
# Explicitly disabled
$run = 0;
}
elsif (!$webmincron_last{$cron->{'id'}}) {
# If not ever run before, don't run right away
$webmincron_last{$cron->{'id'}} = $now;
$changed = 1;

View File

@@ -22,3 +22,5 @@ The default NTP sync time is now set randomly instead of at midnight, and any ex
Support for setting the hardware clock is now detected automatically on Linux.
---- Changes since 1.510 ----
Switched background time syncing to use the new Webmin Cron service.
---- Changes since 1.580 ----
Added an option to have the time synced when Webmin starts at system boot.

View File

@@ -64,15 +64,18 @@ if( $in{ 'action' } eq $text{ 'action_apply' } )
# Create, update or delete the syncing cron job
$job = &find_webmin_cron_job();
if ($in{'sched'}) {
if ($in{'sched'} || $in{'boot'}) {
$job ||= { 'module' => $module_name,
'func' => 'sync_time_cron' };
'func' => 'sync_time_cron' };
$job->{'disabled'} = $in{'sched'} ? 0 : 1;
$job->{'boot'} = $in{'boot'};
&webmincron::parse_times_input($job, \%in);
&webmincron::create_webmin_cron($job);
}
elsif ($job) {
&webmincron::delete_webmin_cron($job);
}
&webmin_log("remote", $in{'action'} eq $text{'action_timeserver_sys'} ? "date" : "hwclock", $rawtime, \%in);
$mode = "sync";
}

View File

@@ -160,10 +160,14 @@ if ( ( !$access{ 'sysdate' } && &has_command( "date" ) || !$access{ 'hwdate' } &
$config{'timeserver_hardware'}));
}
# Show schedule input
# Show boot-time checkbox
$job = &find_webmin_cron_job();
print &ui_table_row($text{'index_boot'},
&ui_yesno_radio("boot", $job && $job->{'boot'}));
# Show schedule input
print &ui_table_row($text{'index_sched'},
&ui_radio("sched", $job ? 1 : 0,
&ui_radio("sched", $job && !$job->{'disabled'} ? 1 : 0,
[ [ 0, $text{'no'} ], [ 1, $text{'index_schedyes'} ] ]));
&seed_random();
$job ||= { 'mins' => int(rand()*60),

View File

@@ -7,6 +7,7 @@ index_sched=Synchronize on schedule?
index_schedyes=Yes, at times below ..
index_sync=Sync and Apply
index_hardware2=Set hardware time too
index_boot=Synchronize when Webmin starts?
index_tzheader=Time Zone
index_tz=Change timezone to
index_ehwclock=$1 failed : $2