From 621052478037570fb7b8d0f64961d15dee8d3550 Mon Sep 17 00:00:00 2001 From: Digimer Date: Sat, 1 Sep 2018 00:59:14 -0400 Subject: [PATCH] * Fixed a bug where long-finished jobs where being displayed in the Striker maintenance mode display. * Made it so that anvil-daemon won't restart when on-disk version has changed while jobs are still running. * Made it so that anvil-update-system reloads systemctl after the update finishes to pickup changes in updated system daemons. Signed-off-by: Digimer --- cgi-bin/striker | 16 +++++++++++++++- tools/anvil-daemon | 19 ++++++++++++++++--- tools/anvil-update-system | 4 ++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/cgi-bin/striker b/cgi-bin/striker index 93e752e8..2fcaf741 100755 --- a/cgi-bin/striker +++ b/cgi-bin/striker @@ -825,6 +825,20 @@ sub check_availability job_title => $job_title, }}); + # Skip jobs that finished more than five minutes ago. + my $job_finished = time - $job_updated; + + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + 's1:time' => time, + 's2:job_updated' => $job_updated, + 's3:job_finished' => $job_finished, + }}); + if (($job_progress eq "100") && ($job_finished > 600)) + { + # Skip it + next; + } + # Convert the double-banged strings into a proper message. my $say_title = $job_title ? $anvil->Words->parse_banged_string({key_string => $job_title}) : ""; my $say_description = $job_description ? $anvil->Words->parse_banged_string({key_string => $job_description}) : ""; @@ -855,7 +869,7 @@ sub check_availability description => $anvil->Words->string({key => "striker_0090", variables => { }}), job_list => $jobs_list }}); - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { 'say::maintenance' => $anvil->data->{say}{maintenance} }}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { 'say::maintenance' => $anvil->data->{say}{maintenance} }}); } # TODO: Phase this out diff --git a/tools/anvil-daemon b/tools/anvil-daemon index 64987ecc..f15155f1 100755 --- a/tools/anvil-daemon +++ b/tools/anvil-daemon @@ -73,12 +73,15 @@ $anvil->Storage->record_md5sums; $anvil->Database->disconnect(); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0203"}); +# This will prevent restarting while jobs are running. +$anvil->data->{sys}{jobs_running} = 0; + # These are the things we always want running. while(1) { # Connect to the database(s) $anvil->Storage->read_config({file => "/etc/anvil/anvil.conf"}); - $anvil->Database->connect(); + $anvil->Database->connect({debug => 2}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132"}); if ($anvil->data->{sys}{database}{connections}) @@ -98,7 +101,7 @@ while(1) } # Has the file on disk changed? - if ($anvil->Storage->check_md5sums) + if ((not $anvil->data->{sys}{jobs_running}) && ($anvil->Storage->check_md5sums)) { $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "warn", key => "message_0014"}); $anvil->nice_exit({code => 1}); @@ -112,7 +115,7 @@ while(1) } # Disconnect from the database(s) and sleep now. - $anvil->Database->disconnect(); + $anvil->Database->disconnect({debug => 2}); sleep 2; } @@ -243,6 +246,10 @@ sub run_jobs { my ($anvil) = @_; + # This will be set to 1 if any jobs are not complete, preventing a restart of the daemon if it's + # changed on disk. + $anvil->data->{sys}{jobs_running} = 0; + # We'll also update the jobs.json file. my $jobs_file = "{\"jobs\":[\n"; @@ -284,6 +291,12 @@ sub run_jobs updated_seconds_ago => $updated_seconds_ago, }}); + if ($job_progress ne "100") + { + $anvil->data->{sys}{jobs_running} = 1; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "sys::jobs_running" => $anvil->data->{sys}{jobs_running} }}); + } + # See if the job was picked up by a now-dead instance. if ($job_picked_up_by) { diff --git a/tools/anvil-update-system b/tools/anvil-update-system index 93b5dcc0..26bffeef 100755 --- a/tools/anvil-update-system +++ b/tools/anvil-update-system @@ -382,6 +382,10 @@ sub run_os_update } close $file_handle; + # Reload daemons to pick up any changed systemctl daemons. + my $output = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{systemctl}." daemon-reload", source => $THIS_FILE, line => __LINE__}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { output => $output }}); + # Did it work? if (not $success) {