#!/usr/bin/perl # # This updates the host system. # NOTE: This doesn't update the Anvil! software stack yet, just the OS. # # - On Striker; This will take the system offline and then run 'dnf -y update'. # - On Nodes; This will do nothing until all servers are off the node. Then the node will be withdrawn, # updated and then rejoin the cluster. # - On DR; This will do nothing until no servers are running, then it will update the system. # # In all cases, the system will be rebooted # use strict; use warnings; use Anvil::Tools; # Disable buffering $| = 1; my $THIS_FILE = ($0 =~ /^.*\/(.*)$/)[0]; my $running_directory = ($0 =~ /^(.*?)\/$THIS_FILE$/)[0]; if (($running_directory =~ /^\./) && ($ENV{PWD})) { $running_directory =~ s/^\./$ENV{PWD}/; } my $anvil = Anvil::Tools->new({log_level => 1, log_secure => 1}); $anvil->Storage->read_config({file => "/etc/anvil/anvil.conf"}); $anvil->Database->connect; $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132", variables => { "sys::db_connections" => $anvil->data->{sys}{db_connections} }}); if (not $anvil->data->{sys}{db_connections}) { # No databases, exit. print $anvil->Words->string({key => "error_0003"})."\n"; $anvil->nice_exit({exit_code => 2}); } # Did we get called with a job UUID? $anvil->data->{jobs}{job_uuid} = defined $anvil->data->{switches}{'job-uuid'} ? $anvil->data->{switches}{'job-uuid'} : ""; update_progress($anvil, 1); run_os_update($anvil); $anvil->nice_exit({exit_code => 0}); ############################################################################################################# # Functions # ############################################################################################################# # This updates the progress if we were called with a job UUID. sub update_progress { my ($anvil, $progress) = @_; if ($anvil->data->{jobs}{job_uuid}) { my $query = " UPDATE jobs SET job_picked_up_by = ".$anvil->data->{sys}{use_db_fh}->quote($$).", job_progress = ".$progress.", modified_date = ".$anvil->data->{sys}{use_db_fh}->quote($anvil->data->{sys}{db_timestamp})." WHERE job_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($job_uuid)." "; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }}); $anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__}); } return(0); } # This updates the OS. sub run_os_update { my ($anvil) = @_; my $stdout_file = "/tmp/os_update.stdout"; my $stderr_file = "/tmp/os_update.stderr"; my $shell_call = $anvil->data->{path}{exe}{dnf}." clean expire-cache && ".$anvil->data->{path}{exe}{dnf}." -y update"; my $process = $anvil->System->call({ debug => 2, background => 1, stdout_file => $stdout_file, stderr_file => $stderr_file, shell_call => $job_command." --job-uuid ".$job_uuid, source => $THIS_FILE, line => __LINE__, }); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { process => $process }}); # Record our PID my $pid = $anvil->data->{jobs}{handles}{$job_uuid}->pid(); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { pid => $pid }}); my $query = " UPDATE jobs SET job_picked_up_by = ".$anvil->data->{sys}{use_db_fh}->quote($pid).", modified_date = ".$anvil->data->{sys}{use_db_fh}->quote($anvil->data->{sys}{db_timestamp})." WHERE job_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($job_uuid)." "; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }}); $anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__}); return(0); };