* Fixed a bug where finished jobs with a '0' picked-up time would be written to jobs.json.

* Updated anvil-configure-striker to use Job methods and reboot using anvil-manage-power. Also updated it to set/clear maintenance mode and mark a reboot required at the end of it's run just prior to reboot.
* Lots of log cleanup.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 6 years ago
parent 00565b123c
commit 94d8a9c495
  1. 9
      Anvil/Tools.pm
  2. 6
      Anvil/Tools/Database.pm
  3. 5
      Anvil/Tools/Log.pm
  4. 15
      Anvil/Tools/Storage.pm
  5. 23
      cgi-bin/striker
  6. 1
      share/words.xml
  7. 169
      tools/anvil-configure-striker
  8. 75
      tools/anvil-daemon
  9. 1
      tools/anvil-manage-power
  10. 69
      tools/anvil-prep-database
  11. 81
      tools/anvil-update-states
  12. 63
      tools/anvil-update-system

@ -362,26 +362,27 @@ sub nice_exit
my $self = shift; my $self = shift;
my $parameter = shift; my $parameter = shift;
my $anvil = $self; my $anvil = $self;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
my $exit_code = defined $parameter->{exit_code} ? $parameter->{exit_code} : 0; my $exit_code = defined $parameter->{exit_code} ? $parameter->{exit_code} : 0;
# Close database connections (if any). # Close database connections (if any).
$anvil->Database->disconnect(); $anvil->Database->disconnect({debug => $debug});
# Report the runtime. # Report the runtime.
my $end_time = Time::HiRes::time; my $end_time = Time::HiRes::time;
my $run_time = $end_time - $anvil->data->{ENV_VALUES}{START_TIME}; my $run_time = $end_time - $anvil->data->{ENV_VALUES}{START_TIME};
my $caller = ($0 =~ /^.*\/(.*)$/)[0]; my $caller = ($0 =~ /^.*\/(.*)$/)[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
's1:ENV_VALUES::START_TIME' => $anvil->data->{ENV_VALUES}{START_TIME}, 's1:ENV_VALUES::START_TIME' => $anvil->data->{ENV_VALUES}{START_TIME},
's2:end_time' => $end_time, 's2:end_time' => $end_time,
's3:run_time' => $run_time, 's3:run_time' => $run_time,
's4:caller' => $caller, 's4:caller' => $caller,
}}); }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0135", variables => { 'caller' => $caller, runtime => $run_time }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0135", variables => { 'caller' => $caller, runtime => $run_time }});
my ($package, $filename, $line) = caller; my ($package, $filename, $line) = caller;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
's1:package' => $package, 's1:package' => $package,
's2:filename' => $filename, 's2:filename' => $filename,
's3:line' => $line, 's3:line' => $line,

@ -120,7 +120,7 @@ sub archive_database
# Is archiving disabled? # Is archiving disabled?
if (not $anvil->data->{sys}{database}{archive}{trigger}) if (not $anvil->data->{sys}{database}{archive}{trigger})
{ {
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0189"}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0189"});
return(1); return(1);
} }
@ -128,7 +128,7 @@ sub archive_database
if (($< != 0) && ($> != 0)) if (($< != 0) && ($> != 0))
{ {
# Not root # Not root
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0188"}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0188"});
return(1); return(1);
} }
@ -1373,7 +1373,7 @@ WHERE
}}); }});
# If the job is done, see if it was recently enough to care about it. # If the job is done, see if it was recently enough to care about it.
if (($job_progress eq "100") && ($updated_seconds_ago > $ended_within)) if (($job_progress eq "100") && (($updated_seconds_ago == 0) or ($updated_seconds_ago > $ended_within)))
{ {
# Skip it # Skip it
next; next;

@ -291,7 +291,8 @@ sub entry
elsif ($key) elsif ($key)
{ {
# Build the string from the key/variables. # Build the string from the key/variables.
my $message .= $anvil->Words->string({ my $message .= $anvil->Words->string({
debug => $debug,
language => $language, language => $language,
key => $key, key => $key,
variables => $variables, variables => $variables,
@ -329,7 +330,7 @@ sub entry
$anvil->data->{HANDLE}{log_file} = $file_handle; $anvil->data->{HANDLE}{log_file} = $file_handle;
# Make sure it can be written to by apache. # Make sure it can be written to by apache.
$anvil->Storage->change_mode({target => $log_file, mode => "0666"}); $anvil->Storage->change_mode({debug => $debug, target => $log_file, mode => "0666"});
} }
if (not $anvil->data->{HANDLE}{log_file}) if (not $anvil->data->{HANDLE}{log_file})

@ -1008,11 +1008,11 @@ fi;";
if ($mode) if ($mode)
{ {
$anvil->Storage->change_mode({target => $working_directory, mode => $mode}); $anvil->Storage->change_mode({debug => $debug, target => $working_directory, mode => $mode});
} }
if (($user) or ($group)) if (($user) or ($group))
{ {
$anvil->Storage->change_owner({target => $working_directory, user => $user, group => $group}); $anvil->Storage->change_owner({debug => $debug, target => $working_directory, user => $user, group => $group});
} }
if (not -e $working_directory) if (not -e $working_directory)
@ -2260,11 +2260,8 @@ fi";
# the mode before writing it. # the mode before writing it.
if ($secure) if ($secure)
{ {
my $shell_call = $anvil->data->{path}{exe}{touch}." ".$file; $anvil->System->call({debug => $debug, shell_call => $anvil->data->{path}{exe}{touch}." ".$file});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { shell_call => $shell_call }}); $anvil->Storage->change_mode({debug => $debug, target => $file, mode => $mode});
$anvil->System->call({shell_call => $shell_call});
$anvil->Storage->change_mode({target => $file, mode => $mode});
} }
# Now write the file. # Now write the file.
@ -2276,11 +2273,11 @@ fi";
if ($mode) if ($mode)
{ {
$anvil->Storage->change_mode({target => $file, mode => $mode}); $anvil->Storage->change_mode({debug => $debug, target => $file, mode => $mode});
} }
if (($user) or ($group)) if (($user) or ($group))
{ {
$anvil->Storage->change_owner({target => $file, user => $user, group => $group}); $anvil->Storage->change_owner({debug => $debug, target => $file, user => $user, group => $group});
} }
} }
} }

@ -52,7 +52,7 @@ if (not -e $anvil->data->{path}{data}{host_uuid})
} }
$anvil->Database->connect(); $anvil->Database->connect();
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132"}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0132"});
if (not $anvil->data->{sys}{database}{connections}) if (not $anvil->data->{sys}{database}{connections})
{ {
# No databases, exit. # No databases, exit.
@ -63,7 +63,7 @@ if (not $anvil->data->{sys}{database}{connections})
# If any jobs are pending/running, show the "unavailable" option. # If any jobs are pending/running, show the "unavailable" option.
my $available = check_availability($anvil); my $available = check_availability($anvil);
my $configured = $available ? check_if_configured($anvil) : 0; my $configured = $available ? check_if_configured($anvil) : 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
available => $available, available => $available,
configured => $configured, configured => $configured,
}}); }});
@ -140,7 +140,7 @@ sub print_and_exit
}}); }});
# Display the page. # Display the page.
my $body = $anvil->Template->get({debug => 3, file => "main.html", name => "master", variables => { my $body = $anvil->Template->get({file => "main.html", name => "master", variables => {
header => $header, header => $header,
skin_url => $anvil->data->{path}{urls}{skins}."/".$anvil->Template->skin, skin_url => $anvil->data->{path}{urls}{skins}."/".$anvil->Template->skin,
center_top_bar => $anvil->data->{form}{error_massage} ? $anvil->data->{form}{error_massage} : "&nbsp;", center_top_bar => $anvil->data->{form}{error_massage} ? $anvil->data->{form}{error_massage} : "&nbsp;",
@ -173,7 +173,7 @@ sub process_task
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "cgi::login::value" => $anvil->data->{cgi}{login}{value} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "cgi::login::value" => $anvil->data->{cgi}{login}{value} }});
# Woot! # Woot!
my $failed = $anvil->Account->login({debug => 3}); my $failed = $anvil->Account->login();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { failed => $failed }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { failed => $failed }});
if (not $failed) if (not $failed)
{ {
@ -195,7 +195,7 @@ sub process_task
# cookies were deleted (via C<< Account->logout() >>. The user needs to log back in. # cookies were deleted (via C<< Account->logout() >>. The user needs to log back in.
# 3 - There user's hash is invalid, it is probably expired. The user has been logged out and # 3 - There user's hash is invalid, it is probably expired. The user has been logged out and
# needs to log back in. # needs to log back in.
my $cookie_problem = $anvil->Account->read_cookies({debug => 2}); my $cookie_problem = $anvil->Account->read_cookies();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { cookie_problem => $cookie_problem }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { cookie_problem => $cookie_problem }});
if (not $cookie_problem) if (not $cookie_problem)
{ {
@ -292,7 +292,6 @@ sub process_power
{ {
# Record the job! # Record the job!
my ($job_uuid) = $anvil->Database->insert_or_update_jobs({ my ($job_uuid) = $anvil->Database->insert_or_update_jobs({
debug => 2,
file => $THIS_FILE, file => $THIS_FILE,
line => __LINE__, line => __LINE__,
job_command => $task eq "poweroff" ? "anvil-manage-power --poweroff -y" : "anvil-manage-power --reboot -y", job_command => $task eq "poweroff" ? "anvil-manage-power --poweroff -y" : "anvil-manage-power --reboot -y",
@ -339,7 +338,6 @@ sub process_update
{ {
# Record the job! # Record the job!
my ($job_uuid) = $anvil->Database->insert_or_update_jobs({ my ($job_uuid) = $anvil->Database->insert_or_update_jobs({
debug => 2,
file => $THIS_FILE, file => $THIS_FILE,
line => __LINE__, line => __LINE__,
job_command => "anvil-update-system", job_command => "anvil-update-system",
@ -361,7 +359,7 @@ sub process_update
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "form::body" => $anvil->data->{form}{body} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "form::body" => $anvil->data->{form}{body} }});
# Set maintenance mode. # Set maintenance mode.
$anvil->System->maintenance_mode({debug => 2, set => 1}); $anvil->System->maintenance_mode({set => 1});
} }
else else
{ {
@ -638,7 +636,6 @@ sub add_sync_peer
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
my ($error, $output) = $anvil->Remote->call({ my ($error, $output) = $anvil->Remote->call({
debug => 2,
password => $anvil->data->{cgi}{new_peer_password}{value}, password => $anvil->data->{cgi}{new_peer_password}{value},
target => $ssh_tcp != 22 ? $host.":".$ssh_tcp : $host, target => $ssh_tcp != 22 ? $host.":".$ssh_tcp : $host,
shell_call => $shell_call, shell_call => $shell_call,
@ -662,7 +659,6 @@ sub add_sync_peer
else else
{ {
my ($error, $output) = $anvil->Remote->call({ my ($error, $output) = $anvil->Remote->call({
debug => 2,
password => $anvil->data->{cgi}{new_peer_password}{value}, password => $anvil->data->{cgi}{new_peer_password}{value},
target => $ssh_tcp != 22 ? $host.":".$ssh_tcp : $host, target => $ssh_tcp != 22 ? $host.":".$ssh_tcp : $host,
shell_call => $anvil->data->{path}{exe}{hostnamectl}." --static", shell_call => $anvil->data->{path}{exe}{hostnamectl}." --static",
@ -781,7 +777,6 @@ sub configure_striker
{ {
# User has confirmed, update the system! # User has confirmed, update the system!
my ($job_uuid) = $anvil->Database->insert_or_update_jobs({ my ($job_uuid) = $anvil->Database->insert_or_update_jobs({
debug => 2,
file => $THIS_FILE, file => $THIS_FILE,
line => __LINE__, line => __LINE__,
job_command => "anvil-configure-striker", job_command => "anvil-configure-striker",
@ -793,7 +788,7 @@ sub configure_striker
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { job_uuid => $job_uuid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { job_uuid => $job_uuid }});
# Set maintenance mode. # Set maintenance mode.
$anvil->System->maintenance_mode({debug => 2, set => 1}); $anvil->System->maintenance_mode({set => 1});
# We don't need to store anything as hidden variables, we'll read it back from the database later. # We don't need to store anything as hidden variables, we'll read it back from the database later.
$anvil->data->{form}{body} = $anvil->Template->get({file => "striker.html", name => "network_job_recorded", variables => { $anvil->data->{form}{body} = $anvil->Template->get({file => "striker.html", name => "network_job_recorded", variables => {
@ -839,7 +834,7 @@ sub check_availability
{ {
my ($anvil) = @_; my ($anvil) = @_;
my $debug = 2; my $debug = 3;
my $available = 1; my $available = 1;
# Check maintenance mode. # Check maintenance mode.
@ -2335,7 +2330,7 @@ sub get_network_details_form
sub generate_ip sub generate_ip
{ {
my ($anvil, $network, $network_sequence, $device_sequence) = @_; my ($anvil, $network, $network_sequence, $device_sequence) = @_;
my $debug = 2; my $debug = 3;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
network => $network, network => $network,
network_sequence => $network_sequence, network_sequence => $network_sequence,

@ -346,6 +346,7 @@ The database connection error was:
<key name="log_0207"><![CDATA[Job->update_progress() called without 'job_uuid' being set, and 'jobs::job_uuid' was also not set. Unable to find the job to update.]]></key> <key name="log_0207"><![CDATA[Job->update_progress() called without 'job_uuid' being set, and 'jobs::job_uuid' was also not set. Unable to find the job to update.]]></key>
<key name="log_0208"><![CDATA[Job->update_progress() called with the 'job_uuid': [#!variable!job_uuid!#], which was not found. Unable to find the job to update.]]></key> <key name="log_0208"><![CDATA[Job->update_progress() called with the 'job_uuid': [#!variable!job_uuid!#], which was not found. Unable to find the job to update.]]></key>
<key name="log_0209"><![CDATA[Job->update_progress() called with 'progress' set to an invalid value: [#!variable!progress!#]. This must be a whole number between '0' and '100' (fractions not allowed).]]></key> <key name="log_0209"><![CDATA[Job->update_progress() called with 'progress' set to an invalid value: [#!variable!progress!#]. This must be a whole number between '0' and '100' (fractions not allowed).]]></key>
<key name="log_0210"><![CDATA[Requesting the job: [#!variable!command!#] be run by 'anvil-daemon'.]]></key>
<!-- Test words. Do NOT change unless you update 't/Words.t' or tests will needlessly fail. --> <!-- Test words. Do NOT change unless you update 't/Words.t' or tests will needlessly fail. -->
<key name="t_0000">Test</key> <key name="t_0000">Test</key>

@ -26,7 +26,7 @@ if (($running_directory =~ /^\./) && ($ENV{PWD}))
# Turn off buffering so that the pinwheel will display while waiting for the SSH call(s) to complete. # Turn off buffering so that the pinwheel will display while waiting for the SSH call(s) to complete.
$| = 1; $| = 1;
my $anvil = Anvil::Tools->new({log_level => 1, log_secure => 1}); my $anvil = Anvil::Tools->new({log_level => 2, log_secure => 1});
# Read switches # Read switches
$anvil->data->{switches}{'no-reboot'} = 0; $anvil->data->{switches}{'no-reboot'} = 0;
@ -34,6 +34,7 @@ $anvil->Get->switches;
# Paths # Paths
$anvil->Storage->read_config({file => $anvil->data->{path}{configs}{'anvil.conf'}}); $anvil->Storage->read_config({file => $anvil->data->{path}{configs}{'anvil.conf'}});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }});
# Make sure we're running as 'root' # Make sure we're running as 'root'
# $< == real UID, $> == effective UID # $< == real UID, $> == effective UID
@ -55,17 +56,19 @@ if (not $anvil->data->{sys}{database}{connections})
$anvil->nice_exit({exit_code => 2}); $anvil->nice_exit({exit_code => 2});
} }
# Set maintenance mode
$anvil->System->maintenance_mode({set => 1});
pickup_job_details($anvil); pickup_job_details($anvil);
reconfigure_network($anvil); reconfigure_network($anvil);
update_passwords($anvil); update_passwords($anvil);
$anvil->Database->insert_or_update_jobs({ $anvil->Job->update_progress({
job_uuid => $anvil->data->{job}{uuid}, debug => 3,
update_progress_only => 1, progress => 100,
job_progress => 100, job_uuid => $anvil->data->{job}{uuid},
job_status => $anvil->data->{job}{status},
}); });
# Record that we've configured this machine. # Record that we've configured this machine.
@ -79,17 +82,23 @@ $anvil->Database->insert_or_update_variables({
variable_source_table => "hosts", variable_source_table => "hosts",
}); });
# Clear maintenance mode. # Clear maintenance mode.
$anvil->System->maintenance_mode({debug => 2, set => 0}); $anvil->System->maintenance_mode({set => 0});
# Clear maintenance mode
$anvil->System->maintenance_mode({set => 0});
### TODO: This is only until we can get the damn networking stable on reconfigure. ### TODO: This is only until we can get the damn networking stable on reconfigure.
# Set reboot needed so that things clean up properly on reboot.
$anvil->System->reboot_needed({set => 1});
if (not $anvil->data->{switches}{'no-reboot'}) if (not $anvil->data->{switches}{'no-reboot'})
{ {
# Reboot. # Reboot.
$anvil->System->call({shell_call => $anvil->data->{path}{exe}{'shutdown'}." --reboot now"}); $anvil->System->call({shell_call => $anvil->data->{path}{exe}{'anvil-manager-power'}." --reboot -y"});
} }
$anvil->nice_exit({code => 0}); $anvil->nice_exit({code => 0});
############################################################################################################# #############################################################################################################
# Functions # # Functions #
############################################################################################################# #############################################################################################################
@ -102,12 +111,11 @@ sub update_passwords
# Set the passwords # Set the passwords
my $password = $anvil->data->{variables}{form}{config_step2}{striker_password}{value}; my $password = $anvil->data->{variables}{form}{config_step2}{striker_password}{value};
my $temp_file = "/tmp/anvil-".$anvil->Get->uuid; my $temp_file = "/tmp/anvil-".$anvil->Get->uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, secure => 1, list => { password => $password }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, secure => 1, list => { password => $password }});
# Write the password into a temporary file. # Write the password into a temporary file.
my $error = $anvil->Storage->write_file({ my $error = $anvil->Storage->write_file({
body => $password, body => $password,
debug => 2,
file => $temp_file, file => $temp_file,
group => "root", group => "root",
mode => "0600", mode => "0600",
@ -126,15 +134,15 @@ sub update_passwords
else else
{ {
my $return_code = ""; my $return_code = "";
my $output = $anvil->System->call({debug => 2, shell_call => $anvil->data->{path}{exe}{'anvil-change-password'}." -y --password-file ".$temp_file."; ".$anvil->data->{path}{exe}{'echo'}." return_code:\$!" }); my $output = $anvil->System->call({debug => 3, shell_call => $anvil->data->{path}{exe}{'anvil-change-password'}." -y --password-file ".$temp_file."; ".$anvil->data->{path}{exe}{'echo'}." return_code:\$!" });
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, list => { output => $output }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, list => { output => $output }});
foreach my $line (split/\n/, $output) foreach my $line (split/\n/, $output)
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, list => { line => $line }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, list => { line => $line }});
if ($line =~ /return_code:(\d+)$/) if ($line =~ /return_code:(\d+)$/)
{ {
$return_code = $1; $return_code = $1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, list => { return_code => $return_code }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, list => { return_code => $return_code }});
} }
} }
@ -148,11 +156,9 @@ sub update_passwords
} }
} }
$anvil->Database->insert_or_update_jobs({ $anvil->Job->update_progress({
job_uuid => $anvil->data->{job}{uuid}, progress => 95,
update_progress_only => 1, job_uuid => $anvil->data->{job}{uuid},
job_progress => 95,
job_status => $anvil->data->{job}{status},
}); });
return(0); return(0);
@ -172,7 +178,7 @@ sub reconfigure_network
my $ifn_count = $anvil->data->{variables}{form}{config_step1}{ifn_count}{value}; my $ifn_count = $anvil->data->{variables}{form}{config_step1}{ifn_count}{value};
my $new_hostname = defined $anvil->data->{variables}{form}{config_step2}{hostname}{value} ? $anvil->data->{variables}{form}{config_step2}{hostname}{value} : $prefix."-striker".sprintf("%02d", $sequence).".".$domain; my $new_hostname = defined $anvil->data->{variables}{form}{config_step2}{hostname}{value} ? $anvil->data->{variables}{form}{config_step2}{hostname}{value} : $prefix."-striker".sprintf("%02d", $sequence).".".$domain;
my $pretty_hostname = $organization." - Striker ".sprintf("%02d", $sequence); my $pretty_hostname = $organization." - Striker ".sprintf("%02d", $sequence);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, list => {
prefix => $prefix, prefix => $prefix,
sequence => $sequence, sequence => $sequence,
domain => $domain, domain => $domain,
@ -184,30 +190,25 @@ sub reconfigure_network
}}); }});
# Set the hostname # Set the hostname
my $hostname = $anvil->System->hostname({set => $new_hostname, pretty => $pretty_hostname, debug => 2}); my $hostname = $anvil->System->hostname({set => $new_hostname, pretty => $pretty_hostname, debug => 3});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { hostname => $hostname }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { hostname => $hostname }});
if ($hostname eq $new_hostname) if ($hostname eq $new_hostname)
{ {
# Success # Success
$anvil->data->{job}{status} .= "message_0016,!!hostname!$new_hostname!!\n"; $anvil->Job->update_progress({
$anvil->Database->insert_or_update_jobs({ progress => 10,
job_uuid => $anvil->data->{job}{uuid}, message => "message_0016,!!hostname!$new_hostname!!",
update_progress_only => 1, job_uuid => $anvil->data->{job}{uuid},
job_progress => 10,
job_status => $anvil->data->{job}{status},
}); });
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "message_0016", variables => { hostname => $new_hostname }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "message_0016", variables => { hostname => $new_hostname }});
} }
else else
{ {
# Failed # Failed
$anvil->data->{job}{status} .= "message_0017,!!hostname!$new_hostname!!,!!bad_hostname!$hostname!!\n"; $anvil->Job->update_progress({
$anvil->data->{job}{status} .= "failed\n"; progress => 0,
$anvil->Database->insert_or_update_jobs({ message => "message_0017,!!hostname!$new_hostname!!,!!bad_hostname!$hostname!!",
job_uuid => $anvil->data->{job}{uuid}, job_uuid => $anvil->data->{job}{uuid},
update_progress_only => 1,
job_progress => 100,
job_status => $anvil->data->{job}{status},
}); });
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, key => "message_0017", variables => { $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, key => "message_0017", variables => {
hostname => $new_hostname, hostname => $new_hostname,
@ -221,28 +222,28 @@ sub reconfigure_network
# Now configure the network. # Now configure the network.
my $dns = defined $anvil->data->{variables}{form}{config_step2}{dns}{value} ? [split/,/, $anvil->data->{variables}{form}{config_step2}{dns}{value}] : []; my $dns = defined $anvil->data->{variables}{form}{config_step2}{dns}{value} ? [split/,/, $anvil->data->{variables}{form}{config_step2}{dns}{value}] : [];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { dns => $dns }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { dns => $dns }});
for (my $i = 0; $i < @{$dns}; $i++) for (my $i = 0; $i < @{$dns}; $i++)
{ {
$dns->[$i] = $anvil->Words->clean_spaces({ string => $dns->[$i] }); $dns->[$i] = $anvil->Words->clean_spaces({ string => $dns->[$i] });
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "dns->[$i]" => $dns->[$i] }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "dns->[$i]" => $dns->[$i] }});
} }
my $gateway = defined $anvil->data->{variables}{form}{config_step2}{gateway}{value} ? $anvil->data->{variables}{form}{config_step2}{gateway}{value} : ""; my $gateway = defined $anvil->data->{variables}{form}{config_step2}{gateway}{value} ? $anvil->data->{variables}{form}{config_step2}{gateway}{value} : "";
my $gateway_interface = defined $anvil->data->{variables}{form}{config_step2}{gateway_interface}{value} ? $anvil->data->{variables}{form}{config_step2}{gateway_interface}{value} : ""; my $gateway_interface = defined $anvil->data->{variables}{form}{config_step2}{gateway_interface}{value} ? $anvil->data->{variables}{form}{config_step2}{gateway_interface}{value} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
gateway => $gateway, gateway => $gateway,
gateway_interface => $gateway_interface, gateway_interface => $gateway_interface,
}}); }});
foreach my $network_type ("bcn", "sn", "ifn") foreach my $network_type ("bcn", "sn", "ifn")
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { network_type => $network_type }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { network_type => $network_type }});
my $count = 0; my $count = 0;
if ($network_type eq "bcn") { $count = $bcn_count; } if ($network_type eq "bcn") { $count = $bcn_count; }
elsif ($network_type eq "sn") { $count = $sn_count; } elsif ($network_type eq "sn") { $count = $sn_count; }
elsif ($network_type eq "ifn") { $count = $ifn_count; } elsif ($network_type eq "ifn") { $count = $ifn_count; }
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { count => $count }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { count => $count }});
next if not $count; next if not $count;
foreach my $network_count (1..$count) foreach my $network_count (1..$count)
@ -257,7 +258,7 @@ sub reconfigure_network
my $link2_mac = defined $anvil->data->{variables}{form}{config_step2}{$link2_key}{value} ? $anvil->data->{variables}{form}{config_step2}{$link2_key}{value} : ""; my $link2_mac = defined $anvil->data->{variables}{form}{config_step2}{$link2_key}{value} ? $anvil->data->{variables}{form}{config_step2}{$link2_key}{value} : "";
my $old_link1_iface = $anvil->data->{sys}{mac}{$link1_mac}{iface} ? $anvil->data->{sys}{mac}{$link1_mac}{iface} : ""; my $old_link1_iface = $anvil->data->{sys}{mac}{$link1_mac}{iface} ? $anvil->data->{sys}{mac}{$link1_mac}{iface} : "";
my $old_link2_iface = defined $anvil->data->{sys}{mac}{$link2_mac}{iface} ? $anvil->data->{sys}{mac}{$link2_mac}{iface} : ""; my $old_link2_iface = defined $anvil->data->{sys}{mac}{$link2_mac}{iface} ? $anvil->data->{sys}{mac}{$link2_mac}{iface} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
ip_key => $ip_key, ip_key => $ip_key,
is_gateway => $is_gateway, is_gateway => $is_gateway,
link1_key => $link1_key, link1_key => $link1_key,
@ -278,7 +279,7 @@ sub reconfigure_network
} }
else else
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "variables::form::config_step2::${ip_key}::value" => $anvil->data->{variables}{form}{config_step2}{$ip_key}{value} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "variables::form::config_step2::${ip_key}::value" => $anvil->data->{variables}{form}{config_step2}{$ip_key}{value} }});
} }
if (($anvil->data->{variables}{form}{config_step2}{$ip_key}{value}) and (not $anvil->Validate->is_ipv4({ip => $anvil->data->{variables}{form}{config_step2}{$ip_key}{value}}))) if (($anvil->data->{variables}{form}{config_step2}{$ip_key}{value}) and (not $anvil->Validate->is_ipv4({ip => $anvil->data->{variables}{form}{config_step2}{$ip_key}{value}})))
{ {
@ -292,7 +293,7 @@ sub reconfigure_network
my $ip = $anvil->data->{variables}{form}{config_step2}{$ip_key}{value}; my $ip = $anvil->data->{variables}{form}{config_step2}{$ip_key}{value};
my $subnet = $anvil->data->{variables}{form}{config_step2}{$subnet_key}{value}; my $subnet = $anvil->data->{variables}{form}{config_step2}{$subnet_key}{value};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
ip => $ip, ip => $ip,
subnet => $subnet, subnet => $subnet,
}}); }});
@ -341,7 +342,7 @@ sub reconfigure_network
{ {
$old_link2_file = $anvil->data->{path}{directories}{ifcfg}."/ifcfg-".$anvil->data->{sys}{mac}{$link2_mac}{iface}; $old_link2_file = $anvil->data->{path}{directories}{ifcfg}."/ifcfg-".$anvil->data->{sys}{mac}{$link2_mac}{iface};
} }
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
say_defroute => $say_defroute, say_defroute => $say_defroute,
cidr => $cidr, cidr => $cidr,
bond_file => $bond_file, bond_file => $bond_file,
@ -358,7 +359,7 @@ sub reconfigure_network
my $bond_uuid = get_uuid_from_interface_file($anvil, $bond_file); my $bond_uuid = get_uuid_from_interface_file($anvil, $bond_file);
my $link1_uuid = get_uuid_from_interface_file($anvil, $old_link1_file); my $link1_uuid = get_uuid_from_interface_file($anvil, $old_link1_file);
my $link2_uuid = get_uuid_from_interface_file($anvil, $old_link2_file); my $link2_uuid = get_uuid_from_interface_file($anvil, $old_link2_file);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
bond_uuid => $bond_uuid, bond_uuid => $bond_uuid,
link1_uuid => $link1_uuid, link1_uuid => $link1_uuid,
link2_uuid => $link2_uuid, link2_uuid => $link2_uuid,
@ -525,7 +526,7 @@ sub reconfigure_network
{ {
# Single interface, set it up # Single interface, set it up
my $link1_mac = $anvil->data->{variables}{form}{config_step2}{$link1_key}{value}; my $link1_mac = $anvil->data->{variables}{form}{config_step2}{$link1_key}{value};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { link1_mac => $link1_mac }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { link1_mac => $link1_mac }});
my $say_network = ""; my $say_network = "";
my $say_interface = ""; my $say_interface = "";
@ -557,7 +558,7 @@ sub reconfigure_network
{ {
$old_link1_file = $anvil->data->{path}{directories}{ifcfg}."/ifcfg-".$anvil->data->{sys}{mac}{$link1_mac}{iface}; $old_link1_file = $anvil->data->{path}{directories}{ifcfg}."/ifcfg-".$anvil->data->{sys}{mac}{$link1_mac}{iface};
} }
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
say_defroute => $say_defroute, say_defroute => $say_defroute,
cidr => $cidr, cidr => $cidr,
new_link1_file => $new_link1_file, new_link1_file => $new_link1_file,
@ -567,7 +568,7 @@ sub reconfigure_network
# Gather (or create) UUIDs # Gather (or create) UUIDs
my $link1_uuid = get_uuid_from_interface_file($anvil, $old_link1_file); my $link1_uuid = get_uuid_from_interface_file($anvil, $old_link1_file);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { link1_uuid => $link1_uuid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { link1_uuid => $link1_uuid }});
my $link1_config = "# $say_network - Link 1\n"; my $link1_config = "# $say_network - Link 1\n";
$link1_config .= "HWADDR=\"".uc($link1_mac)."\"\n"; $link1_config .= "HWADDR=\"".uc($link1_mac)."\"\n";
@ -638,48 +639,46 @@ sub reconfigure_network
} }
} }
$anvil->Database->insert_or_update_jobs({ $anvil->Job->update_progress({
job_uuid => $anvil->data->{job}{uuid}, progress => 50,
update_progress_only => 1, job_uuid => $anvil->data->{job}{uuid},
job_progress => 50,
job_status => $anvil->data->{job}{status},
}); });
# If any virtio bridges exist, remove it/them. # If any virtio bridges exist, remove it/them.
my $start = 0; my $start = 0;
my $bridges = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{virsh}." net-list"}); my $bridges = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{virsh}." net-list"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { bridges => $bridges }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { bridges => $bridges }});
foreach my $line (split/\n/, $bridges) foreach my $line (split/\n/, $bridges)
{ {
$line = $anvil->Words->clean_spaces({ string => $line }); $line = $anvil->Words->clean_spaces({string => $line});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { line => $line }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { line => $line }});
if ($line =~ /^----------/) if ($line =~ /^----------/)
{ {
$start = 1; $start = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { start => $start }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { start => $start }});
next; next;
} }
next if not $start; next if not $start;
my $bridge = ($line =~ /(.*?)\s/)[0]; my $bridge = ($line =~ /(.*?)\s/)[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { bridge => $bridge }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { bridge => $bridge }});
$anvil->data->{virsh}{bridge}{$bridge} = 1; $anvil->data->{virsh}{bridge}{$bridge} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "virsh::bridge::$bridge" => $anvil->data->{virsh}{bridge}{$bridge} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "virsh::bridge::$bridge" => $anvil->data->{virsh}{bridge}{$bridge} }});
} }
foreach my $bridge (sort {$a cmp $b} keys %{$anvil->data->{virsh}{bridge}}) foreach my $bridge (sort {$a cmp $b} keys %{$anvil->data->{virsh}{bridge}})
{ {
# Destroy (stop) it. # Destroy (stop) it.
my $destroy = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{virsh}." net-destroy ".$bridge}); my $destroy = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{virsh}." net-destroy ".$bridge});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { destroy => $destroy }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { destroy => $destroy }});
# Disable it from auto-start. # Disable it from auto-start.
my $disable = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{virsh}." net-autostart ".$bridge." --disable"}); my $disable = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{virsh}." net-autostart ".$bridge." --disable"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { disable => $disable }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { disable => $disable }});
# Undefine (delete) # Undefine (delete)
my $undefine = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{virsh}." net-undefine ".$bridge}); my $undefine = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{virsh}." net-undefine ".$bridge});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { undefine => $undefine }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { undefine => $undefine }});
} }
### TODO: This isn't working... The route table won't set the IFN as the default route properly and ### TODO: This isn't working... The route table won't set the IFN as the default route properly and
@ -689,11 +688,9 @@ sub reconfigure_network
#print "reloading nmcli\n"; #print "reloading nmcli\n";
#$anvil->System->call({shell_call => $anvil->data->{path}{exe}{nmcli}." connection reload"}); #$anvil->System->call({shell_call => $anvil->data->{path}{exe}{nmcli}." connection reload"});
$anvil->Database->insert_or_update_jobs({ $anvil->Job->update_progress({
job_uuid => $anvil->data->{job}{uuid}, progress => 75,
update_progress_only => 1, job_uuid => $anvil->data->{job}{uuid},
job_progress => 75,
job_status => $anvil->data->{job}{status},
}); });
return(0); return(0);
@ -704,8 +701,8 @@ sub reconfigure_network
sub get_uuid_from_interface_file sub get_uuid_from_interface_file
{ {
my ($anvil, $file) = @_; my ($anvil, $file) = @_;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0131", variables => { function => "get_uuid_from_interface_file" }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0131", variables => { function => "get_uuid_from_interface_file" }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { file => $file }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { file => $file }});
my $uuid = ""; my $uuid = "";
if (-e $file) if (-e $file)
@ -713,16 +710,16 @@ sub get_uuid_from_interface_file
my $body = $anvil->Storage->read_file({file => $file}); my $body = $anvil->Storage->read_file({file => $file});
foreach my $line (split/\n/, $body) foreach my $line (split/\n/, $body)
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { line => $line }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { line => $line }});
$line =~ s/#.*//; $line =~ s/#.*//;
if ($line =~ /UUID=\"(.*?)\"/) if ($line =~ /UUID=\"(.*?)\"/)
{ {
my $test_uuid = $1; my $test_uuid = $1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { test_uuid => $test_uuid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { test_uuid => $test_uuid }});
if ($anvil->Validate->is_uuid({uuid => $test_uuid})) if ($anvil->Validate->is_uuid({uuid => $test_uuid}))
{ {
$uuid = $test_uuid; $uuid = $test_uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { uuid => $uuid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { uuid => $uuid }});
} }
last; last;
} }
@ -731,10 +728,10 @@ sub get_uuid_from_interface_file
if (not $uuid) if (not $uuid)
{ {
$uuid = $anvil->Get->uuid(); $uuid = $anvil->Get->uuid();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { uuid => $uuid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { uuid => $uuid }});
} }
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { uuid => $uuid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { uuid => $uuid }});
return($uuid); return($uuid);
} }
@ -764,11 +761,11 @@ AND
AND AND
job_host_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($anvil->Get->host_uuid)." job_host_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($anvil->Get->host_uuid)."
LIMIT 1;"; LIMIT 1;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }});
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
my $count = @{$results}; my $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
results => $results, results => $results,
count => $count, count => $count,
}}); }});
@ -779,7 +776,7 @@ LIMIT 1;";
my $job_picked_up_at = $results->[0]->[4]; my $job_picked_up_at = $results->[0]->[4];
my $job_updated = $results->[0]->[5]; my $job_updated = $results->[0]->[5];
my $job_progress = $results->[0]->[6]; my $job_progress = $results->[0]->[6];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
job_uuid => $job_uuid, job_uuid => $job_uuid,
job_command => $job_command, job_command => $job_command,
job_data => $job_data, job_data => $job_data,
@ -832,11 +829,11 @@ AND
AND AND
variable_source_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($anvil->Get->host_uuid)." variable_source_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($anvil->Get->host_uuid)."
;"; ;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }});
$results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
$count = @{$results}; $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
results => $results, results => $results,
count => $count, count => $count,
}}); }});
@ -845,7 +842,7 @@ AND
my $this_variable = $row->[0]; my $this_variable = $row->[0];
my $this_value = $row->[1]; my $this_value = $row->[1];
my $secure = $this_variable =~ /passw/ ? 1 : 0; my $secure = $this_variable =~ /passw/ ? 1 : 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
this_variable => $this_variable, this_variable => $this_variable,
this_value => (($anvil->Log->secure) or (not $secure)) ? $this_value : $anvil->Words->string({key => "log_0186"}), this_value => (($anvil->Log->secure) or (not $secure)) ? $this_value : $anvil->Words->string({key => "log_0186"}),
}}); }});
@ -854,15 +851,13 @@ AND
} }
# This will be used when updating the job # This will be used when updating the job
$anvil->data->{job}{uuid} = $job_uuid; $anvil->data->{job}{uuid} = $job_uuid;
$anvil->data->{job}{status} = "message_0015\n";
# Record that we've picked up this job. # Record that we've picked up this job.
$anvil->Database->insert_or_update_jobs({ $anvil->Job->update_progress({
job_uuid => $anvil->data->{job}{uuid}, progress => 1,
update_progress_only => 1, message => "message_0015",
job_progress => 1, job_uuid => $anvil->data->{job}{uuid},
job_status => $anvil->data->{job}{status},
}); });
return(0); return(0);

@ -22,6 +22,7 @@ use strict;
use warnings; use warnings;
use Anvil::Tools; use Anvil::Tools;
use Proc::Simple; use Proc::Simple;
use Time::HiRes qw ( time sleep );
use JSON; use JSON;
use HTML::Strip; use HTML::Strip;
use HTML::FromText; use HTML::FromText;
@ -37,6 +38,7 @@ if (($running_directory =~ /^\./) && ($ENV{PWD}))
$| = 1; $| = 1;
my $anvil = Anvil::Tools->new({log_level => 2, log_secure => 1}); my $anvil = Anvil::Tools->new({log_level => 2, log_secure => 1});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }});
# Connect to the database(s). If we have no connections, we'll proceed anyway as one of the 'run_once' tasks # Connect to the database(s). If we have no connections, we'll proceed anyway as one of the 'run_once' tasks
# is to setup the database server. # is to setup the database server.
@ -53,7 +55,7 @@ if (not $anvil->data->{sys}{database}{connections})
# Try connecting again # Try connecting again
$anvil->Database->connect(); $anvil->Database->connect();
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132"}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, secure => 0, key => "log_0132"});
if (not $anvil->data->{sys}{database}{connections}) if (not $anvil->data->{sys}{database}{connections})
{ {
# Still nothing, sleep and exit. # Still nothing, sleep and exit.
@ -86,7 +88,7 @@ $anvil->Storage->record_md5sums;
# Disconnect. We'll reconnect inside the loop # Disconnect. We'll reconnect inside the loop
$anvil->Database->disconnect(); $anvil->Database->disconnect();
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0203"}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0203"});
# This will prevent restarting while jobs are running. # This will prevent restarting while jobs are running.
$anvil->data->{sys}{jobs_running} = 0; $anvil->data->{sys}{jobs_running} = 0;
@ -97,7 +99,7 @@ while(1)
# Connect to the database(s) # Connect to the database(s)
$anvil->Storage->read_config({file => "/etc/anvil/anvil.conf"}); $anvil->Storage->read_config({file => "/etc/anvil/anvil.conf"});
$anvil->Database->connect(); $anvil->Database->connect();
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132"}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0132"});
if ($anvil->data->{sys}{database}{connections}) if ($anvil->data->{sys}{database}{connections})
{ {
@ -131,7 +133,7 @@ while(1)
# Disconnect from the database(s) and sleep now. # Disconnect from the database(s) and sleep now.
$anvil->Database->disconnect(); $anvil->Database->disconnect();
sleep 2; sleep(0.5);
} }
$anvil->nice_exit({code => 0}); $anvil->nice_exit({code => 0});
@ -168,17 +170,16 @@ sub boot_time_tasks
# If the uptime is less than ten minutes, clear the reboot flag. # If the uptime is less than ten minutes, clear the reboot flag.
my $uptime = $anvil->Storage->read_file({ my $uptime = $anvil->Storage->read_file({
debug => 2,
force_read => 1, force_read => 1,
cache => 0, cache => 0,
file => $anvil->data->{path}{proc}{uptime}, file => $anvil->data->{path}{proc}{uptime},
}); });
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { uptime => $uptime }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { uptime => $uptime }});
# Clean it up. We'll have gotten two numbers, the uptime in seconds (to two decimal places) and the # Clean it up. We'll have gotten two numbers, the uptime in seconds (to two decimal places) and the
# total idle time. We only care about the int number. # total idle time. We only care about the int number.
$uptime =~ s/^(\d+)\..*$/$1/; $uptime =~ s/^(\d+)\..*$/$1/;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { uptime => $uptime }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { uptime => $uptime }});
# Now find out if a reboot is needed and when it was last changed. # Now find out if a reboot is needed and when it was last changed.
my $reboot_needed = 0; my $reboot_needed = 0;
@ -198,7 +199,7 @@ AND
;"; ;";
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
my $count = @{$results}; my $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
results => $results, results => $results,
count => $count, count => $count,
}}); }});
@ -207,7 +208,7 @@ AND
$reboot_needed = $results->[0]->[0]; $reboot_needed = $results->[0]->[0];
$changed_seconds_ago = $results->[0]->[1]; $changed_seconds_ago = $results->[0]->[1];
$changed_seconds_ago =~ s/^(\d+)\..*$/$1/; $changed_seconds_ago =~ s/^(\d+)\..*$/$1/;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
reboot_needed => $reboot_needed, reboot_needed => $reboot_needed,
changed_seconds_ago => $changed_seconds_ago, changed_seconds_ago => $changed_seconds_ago,
}}); }});
@ -216,7 +217,7 @@ AND
# If a reboot is needed, see if the uptime is less than the time since the reboot needed flag was # If a reboot is needed, see if the uptime is less than the time since the reboot needed flag was
# set. If the uptime is less, then the system rebooted since it was requested so clear it. h/t to # set. If the uptime is less, then the system rebooted since it was requested so clear it. h/t to
# Lisa Seelye (@thedoh) for this idea! # Lisa Seelye (@thedoh) for this idea!
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
reboot_needed => $reboot_needed, reboot_needed => $reboot_needed,
changed_seconds_ago => $changed_seconds_ago, changed_seconds_ago => $changed_seconds_ago,
uptime => $uptime, uptime => $uptime,
@ -225,11 +226,11 @@ AND
{ {
# Clear the reboot request. # Clear the reboot request.
$reboot_needed = $anvil->System->reboot_needed({set => 0}); $reboot_needed = $anvil->System->reboot_needed({set => 0});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { reboot_needed => $reboot_needed }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { reboot_needed => $reboot_needed }});
# Check to see if there was a reboot job in progress. If so, finish it off. # Check to see if there was a reboot job in progress. If so, finish it off.
my $job_uuid = $anvil->Job->get_job_uuid({debug => 2, program => "anvil-manage-power"}); my $job_uuid = $anvil->Job->get_job_uuid({program => "anvil-manage-power"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { job_uuid => $job_uuid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { job_uuid => $job_uuid }});
if ($job_uuid) if ($job_uuid)
{ {
@ -238,7 +239,6 @@ AND
if ($anvil->data->{jobs}{job_uuid}) if ($anvil->data->{jobs}{job_uuid})
{ {
$anvil->Job->update_progress({ $anvil->Job->update_progress({
debug => 2,
progress => 100, progress => 100,
message => "message_0064,!!date_and_time!".$date_time."!!", message => "message_0064,!!date_and_time!".$date_time."!!",
job_uuid => $job_uuid job_uuid => $job_uuid
@ -279,7 +279,7 @@ sub keep_running
{ {
# If it's not a handle, delete it. # If it's not a handle, delete it.
my $running = $anvil->data->{jobs}{handles}{$job_uuid}->poll(); my $running = $anvil->data->{jobs}{handles}{$job_uuid}->poll();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
"jobs::handles::${job_uuid}" => $anvil->data->{jobs}{handles}{$job_uuid}, "jobs::handles::${job_uuid}" => $anvil->data->{jobs}{handles}{$job_uuid},
running => $running, running => $running,
}}); }});
@ -288,7 +288,10 @@ sub keep_running
if (not $running) if (not $running)
{ {
my $exit_status = $anvil->data->{jobs}{handles}{$job_uuid}->exit_status(); my $exit_status = $anvil->data->{jobs}{handles}{$job_uuid}->exit_status();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { exit_status => $exit_status }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => {
job_uuid => $job_uuid,
exit_status => $exit_status,
}});
# Free up memory # Free up memory
$anvil->data->{jobs}{handles}{$job_uuid}->cleanup(); $anvil->data->{jobs}{handles}{$job_uuid}->cleanup();
@ -324,7 +327,7 @@ sub run_jobs
# Get a list of pending or incomplete jobs. # Get a list of pending or incomplete jobs.
my $return = $anvil->Database->get_jobs({ended_within => 300}); my $return = $anvil->Database->get_jobs({ended_within => 300});
my $count = @{$return}; my $count = @{$return};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
'return' => $return, 'return' => $return,
count => $count, count => $count,
}}); }});
@ -343,7 +346,7 @@ sub run_jobs
my $job_status = $hash_ref->{job_status}; my $job_status = $hash_ref->{job_status};
my $started_seconds_ago = $job_picked_up_at ? (time - $job_picked_up_at) : 0; my $started_seconds_ago = $job_picked_up_at ? (time - $job_picked_up_at) : 0;
my $updated_seconds_ago = $job_updated ? (time - $job_updated) : 0; my $updated_seconds_ago = $job_updated ? (time - $job_updated) : 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
job_uuid => $job_uuid, job_uuid => $job_uuid,
job_command => $job_command, job_command => $job_command,
job_data => $job_data, job_data => $job_data,
@ -362,7 +365,7 @@ sub run_jobs
if ($job_progress ne "100") if ($job_progress ne "100")
{ {
$anvil->data->{sys}{jobs_running} = 1; $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} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "sys::jobs_running" => $anvil->data->{sys}{jobs_running} }});
} }
# See if the job was picked up by a now-dead instance. # See if the job was picked up by a now-dead instance.
@ -389,7 +392,7 @@ sub run_jobs
# Clear some variables. # Clear some variables.
$job_progress = 0; $job_progress = 0;
$job_status = "message_0056"; $job_status = "message_0056";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
job_progress => $job_progress, job_progress => $job_progress,
job_status => $job_status, job_status => $job_status,
}}); }});
@ -397,15 +400,15 @@ sub run_jobs
# Clear the PID # Clear the PID
$job_picked_up_by = 0; $job_picked_up_by = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { job_picked_up_by => $job_picked_up_by }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { job_picked_up_by => $job_picked_up_by }});
} }
} }
# Convert the double-banged strings into a proper message. # Convert the double-banged strings into a proper message.
my $say_title = $job_title ? $anvil->Words->parse_banged_string({debug => 2, key_string => $job_title}) : ""; my $say_title = $job_title ? $anvil->Words->parse_banged_string({key_string => $job_title}) : "";
my $say_description = $job_description ? $anvil->Words->parse_banged_string({debug => 2, key_string => $job_description}) : ""; my $say_description = $job_description ? $anvil->Words->parse_banged_string({key_string => $job_description}) : "";
my $say_status = $job_status ? $anvil->Words->parse_banged_string({debug => 2, key_string => $job_status}) : ""; my $say_status = $job_status ? $anvil->Words->parse_banged_string({key_string => $job_status}) : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
job_title => $job_title, job_title => $job_title,
say_description => $say_description, say_description => $say_description,
say_status => $say_status, say_status => $say_status,
@ -416,7 +419,7 @@ sub run_jobs
{ {
my $html_strip = HTML::Strip->new(); my $html_strip = HTML::Strip->new();
$say_status = $html_strip->parse($say_status); $say_status = $html_strip->parse($say_status);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { say_status => $say_status }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { say_status => $say_status }});
# Now make the resulting text string HTML friendly # Now make the resulting text string HTML friendly
my $text_to_html = HTML::FromText->new({ my $text_to_html = HTML::FromText->new({
@ -425,7 +428,7 @@ sub run_jobs
lines => 1, lines => 1,
}); });
$say_status = $text_to_html->parse($say_status); $say_status = $text_to_html->parse($say_status);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { say_status => $say_status }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { say_status => $say_status }});
} }
# Add this to the jobs.json file # Add this to the jobs.json file
@ -443,7 +446,7 @@ sub run_jobs
started_seconds_ago => $started_seconds_ago, started_seconds_ago => $started_seconds_ago,
updated_seconds_ago => $updated_seconds_ago, updated_seconds_ago => $updated_seconds_ago,
}); });
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { json_string => $json_string }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { json_string => $json_string }});
$jobs_file .= $json_string.",\n"; $jobs_file .= $json_string.",\n";
# If the job is done, move on. # If the job is done, move on.
@ -453,27 +456,28 @@ sub run_jobs
if ((not $job_picked_up_by) && (not $anvil->data->{switches}{'no-start'})) if ((not $job_picked_up_by) && (not $anvil->data->{switches}{'no-start'}))
{ {
# Start the job, appending '--job-uuid' to the command. # Start the job, appending '--job-uuid' to the command.
my $command = $job_command." --job-uuid ".$job_uuid;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, secure => 0, key => "log_0210", variables => { command => $command }});
$anvil->data->{jobs}{handles}{$job_uuid} = $anvil->System->call({ $anvil->data->{jobs}{handles}{$job_uuid} = $anvil->System->call({
debug => 2,
background => 1, background => 1,
stdout_file => "/tmp/anvil.job.".$job_uuid.".stdout", stdout_file => "/tmp/anvil.job.".$job_uuid.".stdout",
stderr_file => "/tmp/anvil.job.".$job_uuid.".stderr", stderr_file => "/tmp/anvil.job.".$job_uuid.".stderr",
shell_call => $job_command." --job-uuid ".$job_uuid, shell_call => $command,
source => $THIS_FILE, source => $THIS_FILE,
line => __LINE__, line => __LINE__,
}); });
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "jobs::handles::${job_uuid}" => $anvil->data->{jobs}{handles}{$job_uuid} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "jobs::handles::${job_uuid}" => $anvil->data->{jobs}{handles}{$job_uuid} }});
# Log the PID (the job should update the database). # Log the PID (the job should update the database).
my $pid = $anvil->data->{jobs}{handles}{$job_uuid}->pid(); my $pid = $anvil->data->{jobs}{handles}{$job_uuid}->pid();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { pid => $pid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { pid => $pid }});
} }
} }
# Close the jobs file. # Close the jobs file.
$jobs_file =~ s/,\n$/\n/ms; $jobs_file =~ s/,\n$/\n/ms;
$jobs_file .= "]}\n"; $jobs_file .= "]}\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { jobs_file => $jobs_file }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { jobs_file => $jobs_file }});
# Write the JSON file # Write the JSON file
my $output_json = $anvil->data->{path}{directories}{html}."/status/jobs.json"; my $output_json = $anvil->data->{path}{directories}{html}."/status/jobs.json";
@ -496,10 +500,7 @@ sub update_state_file
{ {
my ($anvil) = @_; my ($anvil) = @_;
my $shell_call = $anvil->data->{path}{exe}{'anvil-update-states'}; my $states_output = $anvil->System->call({debug => 3, shell_call => $anvil->data->{path}{exe}{'anvil-update-states'}, source => $THIS_FILE, line => __LINE__});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { shell_call => $shell_call }});
my $states_output = $anvil->System->call({shell_call => $shell_call, source => $THIS_FILE, line => __LINE__});
if ($states_output) if ($states_output)
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { states_output => $states_output }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { states_output => $states_output }});

@ -35,6 +35,7 @@ if (($running_directory =~ /^\./) && ($ENV{PWD}))
my $anvil = Anvil::Tools->new({log_level => 2, log_secure => 1}); my $anvil = Anvil::Tools->new({log_level => 2, log_secure => 1});
$anvil->Storage->read_config({file => "/etc/anvil/anvil.conf"}); $anvil->Storage->read_config({file => "/etc/anvil/anvil.conf"});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }});
# Read switches # Read switches
$anvil->data->{switches}{'poweroff'} = ""; $anvil->data->{switches}{'poweroff'} = "";

@ -26,32 +26,33 @@ if (($running_directory =~ /^\./) && ($ENV{PWD}))
# Turn off buffering so that the pinwheel will display while waiting for the SSH call(s) to complete. # Turn off buffering so that the pinwheel will display while waiting for the SSH call(s) to complete.
$| = 1; $| = 1;
my $anvil = Anvil::Tools->new({log_level => 3, log_secure => 0}); my $anvil = Anvil::Tools->new({log_level => 2, log_secure => 0});
# Read switches # Read switches
$anvil->Get->switches; $anvil->Get->switches;
# Read in our config. # Read in our config.
$anvil->Storage->read_config({file => $anvil->data->{path}{configs}{'anvil.conf'}}); $anvil->Storage->read_config({file => $anvil->data->{path}{configs}{'anvil.conf'}});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }});
my $local_uuid = $anvil->Database->get_local_uuid(); my $local_uuid = $anvil->Database->get_local_uuid();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { local_uuid => $local_uuid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { local_uuid => $local_uuid }});
# If we didn't get the $local_uuid, then there is no entry for this system in anvil.conf yet, so we'll add it. # If we didn't get the $local_uuid, then there is no entry for this system in anvil.conf yet, so we'll add it.
if (not $local_uuid) if (not $local_uuid)
{ {
$local_uuid = add_to_local_config($anvil); $local_uuid = add_to_local_config($anvil);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { local_uuid => $local_uuid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { local_uuid => $local_uuid }});
} }
# Now configure! # Now configure!
if ($local_uuid) if ($local_uuid)
{ {
# Start checks # Start checks
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "sys::service::postgresql" => $anvil->data->{sys}{service}{postgresql} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "sys::service::postgresql" => $anvil->data->{sys}{service}{postgresql} }});
my $running = $anvil->System->check_daemon({debug => 2, daemon => $anvil->data->{sys}{service}{postgresql}}); my $running = $anvil->System->check_daemon({daemon => $anvil->data->{sys}{service}{postgresql}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { running => $running }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { running => $running }});
if ($running eq "2") if ($running eq "2")
{ {
# Not installed. # Not installed.
@ -61,11 +62,11 @@ if ($local_uuid)
elsif (not $running) elsif (not $running)
{ {
# Do we need to initialize the databae? # Do we need to initialize the databae?
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "path::configs::pg_hba.conf" => $anvil->data->{path}{configs}{'pg_hba.conf'} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "path::configs::pg_hba.conf" => $anvil->data->{path}{configs}{'pg_hba.conf'} }});
if (-e $anvil->data->{path}{configs}{'pg_hba.conf'}) if (-e $anvil->data->{path}{configs}{'pg_hba.conf'})
{ {
# It already exists. # It already exists.
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "path::configs::pg_hba.conf" => $anvil->data->{path}{configs}{'pg_hba.conf'} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "path::configs::pg_hba.conf" => $anvil->data->{path}{configs}{'pg_hba.conf'} }});
} }
else else
{ {
@ -101,7 +102,7 @@ if ($local_uuid)
# Setup postgresql.conf # Setup postgresql.conf
my $postgresql_backup = $anvil->data->{path}{directories}{backups}."/pgsql/postgresql.conf"; my $postgresql_backup = $anvil->data->{path}{directories}{backups}."/pgsql/postgresql.conf";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { postgresql_backup => $postgresql_backup }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { postgresql_backup => $postgresql_backup }});
$anvil->Storage->copy_file({ $anvil->Storage->copy_file({
source_file => $anvil->data->{path}{configs}{'postgresql.conf'}, source_file => $anvil->data->{path}{configs}{'postgresql.conf'},
target_file => $postgresql_backup, target_file => $postgresql_backup,
@ -130,6 +131,7 @@ if ($local_uuid)
if ($update_file) if ($update_file)
{ {
$anvil->Storage->write_file({ $anvil->Storage->write_file({
debug => 2,
file => $anvil->data->{path}{configs}{'postgresql.conf'}, file => $anvil->data->{path}{configs}{'postgresql.conf'},
body => $new_postgresql_conf, body => $new_postgresql_conf,
user => "postgres", user => "postgres",
@ -153,12 +155,12 @@ if ($local_uuid)
my $new_pg_hba_conf = ""; my $new_pg_hba_conf = "";
foreach my $line (split/\n/, $pg_hba_conf) foreach my $line (split/\n/, $pg_hba_conf)
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { line => $line }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { line => $line }});
if ($line =~ /^host\s+all\s+all\s+\all\s+md5$/) if ($line =~ /^host\s+all\s+all\s+\all\s+md5$/)
{ {
# No need to update. # No need to update.
$update_file = 0; $update_file = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { update_file => $update_file }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { update_file => $update_file }});
last; last;
} }
elsif ($line =~ /^# TYPE\s+DATABASE/) elsif ($line =~ /^# TYPE\s+DATABASE/)
@ -176,6 +178,7 @@ if ($local_uuid)
if ($update_file) if ($update_file)
{ {
$anvil->Storage->write_file({ $anvil->Storage->write_file({
debug => 2,
file => $anvil->data->{path}{configs}{'pg_hba.conf'}, file => $anvil->data->{path}{configs}{'pg_hba.conf'},
body => $new_pg_hba_conf, body => $new_pg_hba_conf,
user => "postgres", user => "postgres",
@ -188,7 +191,7 @@ if ($local_uuid)
} }
# Start the daemon. '0' = started, anything else is a problem. # Start the daemon. '0' = started, anything else is a problem.
my $return_code = $anvil->System->start_daemon({debug => 2, daemon => $anvil->data->{sys}{service}{postgresql}}); my $return_code = $anvil->System->start_daemon({daemon => $anvil->data->{sys}{service}{postgresql}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { return_code => $return_code }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { return_code => $return_code }});
if ($return_code eq "0") if ($return_code eq "0")
{ {
@ -229,14 +232,14 @@ if ($local_uuid)
if (-e $anvil->data->{path}{secure}{postgres_pgpass}) if (-e $anvil->data->{path}{secure}{postgres_pgpass})
{ {
$created_pgpass = 1; $created_pgpass = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { created_pgpass => $created_pgpass }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { created_pgpass => $created_pgpass }});
} }
} }
# Does the database user exist? # Does the database user exist?
my $create_user = 1; my $create_user = 1;
my $database_user = $anvil->data->{database}{$local_uuid}{user} ? $anvil->data->{database}{$local_uuid}{user} : $anvil->data->{sys}{database}{user}; my $database_user = $anvil->data->{database}{$local_uuid}{user} ? $anvil->data->{database}{$local_uuid}{user} : $anvil->data->{sys}{database}{user};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { database_user => $database_user }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { database_user => $database_user }});
if (not $database_user) if (not $database_user)
{ {
# No database user defined # No database user defined
@ -244,24 +247,24 @@ if ($local_uuid)
$anvil->nice_exit({code => 3}); $anvil->nice_exit({code => 3});
} }
my $user_list = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{su}." - postgres -c \"".$anvil->data->{path}{exe}{psql}." template1 -c 'SELECT usename, usesysid FROM pg_catalog.pg_user;'\"", source => $THIS_FILE, line => __LINE__}); my $user_list = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{su}." - postgres -c \"".$anvil->data->{path}{exe}{psql}." template1 -c 'SELECT usename, usesysid FROM pg_catalog.pg_user;'\"", source => $THIS_FILE, line => __LINE__});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { user_list => $user_list }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { user_list => $user_list }});
foreach my $line (split/\n/, $user_list) foreach my $line (split/\n/, $user_list)
{ {
if ($line =~ /^ $database_user\s+\|\s+(\d+)/) if ($line =~ /^ $database_user\s+\|\s+(\d+)/)
{ {
# User exists already # User exists already
my $id = $1; my $id = $1;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0060", variables => { user => $database_user, id => $id }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0060", variables => { user => $database_user, id => $id }});
$create_user = 0; $create_user = 0;
last; last;
} }
} }
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { create_user => $create_user }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { create_user => $create_user }});
if ($create_user) if ($create_user)
{ {
# Create the user # Create the user
my $create_output = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{su}." - postgres -c \"".$anvil->data->{path}{exe}{createuser}." --no-superuser --createdb --no-createrole $database_user\"", source => $THIS_FILE, line => __LINE__}); my $create_output = $anvil->System->call({debug => 2, shell_call => $anvil->data->{path}{exe}{su}." - postgres -c \"".$anvil->data->{path}{exe}{createuser}." --no-superuser --createdb --no-createrole $database_user\"", source => $THIS_FILE, line => __LINE__});
my $user_list = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{su}." - postgres -c \"".$anvil->data->{path}{exe}{psql}." template1 -c 'SELECT usename, usesysid FROM pg_catalog.pg_user;'\"", source => $THIS_FILE, line => __LINE__}); my $user_list = $anvil->System->call({debug => 2, shell_call => $anvil->data->{path}{exe}{su}." - postgres -c \"".$anvil->data->{path}{exe}{psql}." template1 -c 'SELECT usename, usesysid FROM pg_catalog.pg_user;'\"", source => $THIS_FILE, line => __LINE__});
my $user_exists = 0; my $user_exists = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { create_output => $create_output, user_list => $user_list }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { create_output => $create_output, user_list => $user_list }});
foreach my $line (split/\n/, $user_list) foreach my $line (split/\n/, $user_list)
@ -270,7 +273,7 @@ if ($local_uuid)
{ {
# Success! # Success!
my $id = $1; my $id = $1;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0095", variables => { user => $database_user, id => $id }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0095", variables => { user => $database_user, id => $id }});
$user_exists = 1; $user_exists = 1;
last; last;
} }
@ -282,19 +285,19 @@ if ($local_uuid)
} }
# Update/set the passwords. # Update/set the passwords.
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, secure => 1, list => { "database::${local_uuid}::password" => $anvil->data->{database}{$local_uuid}{password} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, secure => 1, list => { "database::${local_uuid}::password" => $anvil->data->{database}{$local_uuid}{password} }});
if ($anvil->data->{database}{$local_uuid}{password}) if ($anvil->data->{database}{$local_uuid}{password})
{ {
foreach my $user ("postgres", $database_user) foreach my $user ("postgres", $database_user)
{ {
my $update_output = $anvil->System->call({secure => 1, shell_call => $anvil->data->{path}{exe}{su}." - postgres -c \"".$anvil->data->{path}{exe}{psql}." template1 -c \\\"ALTER ROLE $user WITH PASSWORD '".$anvil->data->{database}{$local_uuid}{password}."';\\\"\"", source => $THIS_FILE, line => __LINE__}); my $update_output = $anvil->System->call({secure => 1, shell_call => $anvil->data->{path}{exe}{su}." - postgres -c \"".$anvil->data->{path}{exe}{psql}." template1 -c \\\"ALTER ROLE $user WITH PASSWORD '".$anvil->data->{database}{$local_uuid}{password}."';\\\"\"", source => $THIS_FILE, line => __LINE__});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, secure => 1, list => { update_output => $update_output }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, secure => 1, list => { update_output => $update_output }});
foreach my $line (split/\n/, $user_list) foreach my $line (split/\n/, $user_list)
{ {
if ($line =~ /ALTER ROLE/) if ($line =~ /ALTER ROLE/)
{ {
# Password set # Password set
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0100", variables => { user => $user }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0100", variables => { user => $user }});
} }
} }
} }
@ -304,21 +307,21 @@ if ($local_uuid)
# Create the database, if needed. # Create the database, if needed.
my $create_database = 1; my $create_database = 1;
my $database_name = $anvil->data->{database}{$local_uuid}{name} ? $anvil->data->{database}{$local_uuid}{name} : $anvil->data->{sys}{database}{name}; my $database_name = $anvil->data->{database}{$local_uuid}{name} ? $anvil->data->{database}{$local_uuid}{name} : $anvil->data->{sys}{database}{name};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { database_name => $database_name }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { database_name => $database_name }});
my $database_list = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{su}." - postgres -c \"".$anvil->data->{path}{exe}{psql}." template1 -c 'SELECT datname FROM pg_catalog.pg_database;'\"", source => $THIS_FILE, line => __LINE__}); my $database_list = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{su}." - postgres -c \"".$anvil->data->{path}{exe}{psql}." template1 -c 'SELECT datname FROM pg_catalog.pg_database;'\"", source => $THIS_FILE, line => __LINE__});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { database_list => $database_list }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { database_list => $database_list }});
foreach my $line (split/\n/, $database_list) foreach my $line (split/\n/, $database_list)
{ {
if ($line =~ /^ $database_name$/) if ($line =~ /^ $database_name$/)
{ {
# Database already exists. # Database already exists.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0105", variables => { database => $database_name }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0105", variables => { database => $database_name }});
$create_database = 0; $create_database = 0;
last; last;
} }
} }
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { create_database => $create_database }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { create_database => $create_database }});
if ($create_database) if ($create_database)
{ {
my $create_output = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{su}." - postgres -c \"".$anvil->data->{path}{exe}{createdb}." --owner ".$database_user." ".$database_name."\"", source => $THIS_FILE, line => __LINE__}); my $create_output = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{su}." - postgres -c \"".$anvil->data->{path}{exe}{createdb}." --owner ".$database_user." ".$database_name."\"", source => $THIS_FILE, line => __LINE__});
@ -326,13 +329,13 @@ if ($local_uuid)
my $database_exists = 0; my $database_exists = 0;
my $database_list = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{su}." - postgres -c \"".$anvil->data->{path}{exe}{psql}." template1 -c 'SELECT datname FROM pg_catalog.pg_database;'\"", source => $THIS_FILE, line => __LINE__}); my $database_list = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{su}." - postgres -c \"".$anvil->data->{path}{exe}{psql}." template1 -c 'SELECT datname FROM pg_catalog.pg_database;'\"", source => $THIS_FILE, line => __LINE__});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { database_list => $database_list }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { database_list => $database_list }});
foreach my $line (split/\n/, $database_list) foreach my $line (split/\n/, $database_list)
{ {
if ($line =~ /^ $database_name$/) if ($line =~ /^ $database_name$/)
{ {
# Database created # Database created
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0110", variables => { database => $database_name }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0110", variables => { database => $database_name }});
$database_exists = 1; $database_exists = 1;
last; last;
} }
@ -388,6 +391,7 @@ RateLimitInterval=0
RateLimitBurst=0 RateLimitBurst=0
"; ";
$anvil->Storage->write_file({ $anvil->Storage->write_file({
debug => 2,
file => $anvil->data->{path}{configs}{'journald_anvil'}, file => $anvil->data->{path}{configs}{'journald_anvil'},
body => $body, body => $body,
user => "root", user => "root",
@ -397,10 +401,7 @@ RateLimitBurst=0
}); });
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "message_0012", variables => { file => $anvil->data->{path}{configs}{'journald_anvil'} }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "message_0012", variables => { file => $anvil->data->{path}{configs}{'journald_anvil'} }});
my $shell_call = $anvil->data->{path}{exe}{systemctl}." restart systemd-journald.service"; my $output = $anvil->System->call({debug => 2, shell_call => $anvil->data->{path}{exe}{systemctl}." restart systemd-journald.service", source => $THIS_FILE, line => __LINE__});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
my $output = $anvil->System->call({shell_call => $shell_call, source => $THIS_FILE, line => __LINE__});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { output => $output }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { output => $output }});
} }
} }
@ -426,7 +427,6 @@ sub add_to_local_config
my $password_file = "/tmp/anvil-manage-striker-peers.".$anvil->Get->uuid; my $password_file = "/tmp/anvil-manage-striker-peers.".$anvil->Get->uuid;
$anvil->Storage->write_file({ $anvil->Storage->write_file({
secure => 1, secure => 1,
debug => 2,
file => $password_file, file => $password_file,
body => "Initial1", body => "Initial1",
mode => "0600", mode => "0600",
@ -436,7 +436,6 @@ sub add_to_local_config
# Make the shell call, and parse the output looking for our own entry # Make the shell call, and parse the output looking for our own entry
my $host_uuid = $anvil->Get->host_uuid(); my $host_uuid = $anvil->Get->host_uuid();
my $output = $anvil->System->call({ my $output = $anvil->System->call({
debug => 2,
shell_call => $anvil->data->{path}{exe}{'anvil-manage-striker-peers'}." --add --host-uuid ".$anvil->Get->host_uuid." --host localhost --port 5432 --password-file ".$password_file." --ping 0", shell_call => $anvil->data->{path}{exe}{'anvil-manage-striker-peers'}." --add --host-uuid ".$anvil->Get->host_uuid." --host localhost --port 5432 --password-file ".$password_file." --ping 0",
source => $THIS_FILE, source => $THIS_FILE,
line => __LINE__, line => __LINE__,

@ -18,12 +18,14 @@ if (($running_directory =~ /^\./) && ($ENV{PWD}))
$running_directory =~ s/^\./$ENV{PWD}/; $running_directory =~ s/^\./$ENV{PWD}/;
} }
my $anvil = Anvil::Tools->new({log_level => 1, log_secure => 1}); my $anvil = Anvil::Tools->new({log_level => 2, log_secure => 1});
$anvil->Storage->read_config({file => "/etc/anvil/anvil.conf"}); $anvil->Storage->read_config({file => "/etc/anvil/anvil.conf"});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }});
$anvil->Database->connect; $anvil->Database->connect;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132"}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0132"});
if (not $anvil->data->{sys}{database}{connections}) if (not $anvil->data->{sys}{database}{connections})
{ {
# No databases, exit. # No databases, exit.
@ -35,6 +37,7 @@ update_network($anvil);
$anvil->nice_exit({exit_code => 0}); $anvil->nice_exit({exit_code => 0});
############################################################################################################# #############################################################################################################
# Functions # # Functions #
############################################################################################################# #############################################################################################################
@ -62,7 +65,7 @@ sub update_network
}; };
local(*DIRECTORY); local(*DIRECTORY);
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0018", variables => { directory => $directory }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0018", variables => { directory => $directory }});
opendir(DIRECTORY, $directory); opendir(DIRECTORY, $directory);
while(my $file = readdir(DIRECTORY)) while(my $file = readdir(DIRECTORY))
{ {
@ -71,7 +74,7 @@ sub update_network
next if $file eq "lo"; next if $file eq "lo";
next if $file =~ /virbr\d/; next if $file =~ /virbr\d/;
my $full_path = "$directory/$file"; my $full_path = "$directory/$file";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { full_path => $full_path }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { full_path => $full_path }});
if (-d $full_path) if (-d $full_path)
{ {
# Pull out the data I want. Note that some of these don't exist with virtio-net interfaces. # Pull out the data I want. Note that some of these don't exist with virtio-net interfaces.
@ -81,7 +84,7 @@ sub update_network
my $mtu = -e $full_path."/mtu" ? $anvil->Storage->read_file({file => $full_path."/mtu"}) : 0; my $mtu = -e $full_path."/mtu" ? $anvil->Storage->read_file({file => $full_path."/mtu"}) : 0;
my $duplex = -e $full_path."/duplex" ? $anvil->Storage->read_file({file => $full_path."/duplex"}) : "unknown"; # full or half? my $duplex = -e $full_path."/duplex" ? $anvil->Storage->read_file({file => $full_path."/duplex"}) : "unknown"; # full or half?
my $operational = -e $full_path."/operstate" ? $anvil->Storage->read_file({file => $full_path."/operstate"}) : "unknown"; # up or down my $operational = -e $full_path."/operstate" ? $anvil->Storage->read_file({file => $full_path."/operstate"}) : "unknown"; # up or down
my $speed = $link_state ? $anvil->Storage->read_file({file => $full_path."/speed", debug => 2}) : 0; # Mbps (ie: 1000 = Gbps), gives a very high number for unplugged link my $speed = $link_state ? $anvil->Storage->read_file({debug => 3, file => $full_path."/speed"}) : 0; # Mbps (ie: 1000 = Gbps), gives a very high number for unplugged link
my $media = "unknown"; my $media = "unknown";
my $type = "interface"; my $type = "interface";
@ -101,7 +104,7 @@ sub update_network
{ {
$ip_address = $anvil->data->{sys}{network}{interface}{$interface}{ip} ? $anvil->data->{sys}{network}{interface}{$interface}{ip} : ""; $ip_address = $anvil->data->{sys}{network}{interface}{$interface}{ip} ? $anvil->data->{sys}{network}{interface}{$interface}{ip} : "";
$subnet_mask = $anvil->data->{sys}{network}{interface}{$interface}{subnet} ? $anvil->data->{sys}{network}{interface}{$interface}{subnet} : ""; $subnet_mask = $anvil->data->{sys}{network}{interface}{$interface}{subnet} ? $anvil->data->{sys}{network}{interface}{$interface}{subnet} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
ip_address => $ip_address, ip_address => $ip_address,
subnet_mask => $subnet_mask, subnet_mask => $subnet_mask,
}}); }});
@ -114,7 +117,7 @@ sub update_network
{ {
# It's a slave. # It's a slave.
$mac_address = $anvil->Storage->read_file({file => $mac_bond_file}); $mac_address = $anvil->Storage->read_file({file => $mac_bond_file});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { mac_address => $mac_address }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { mac_address => $mac_address }});
} }
# If this is a virtual interface, set some fake values that don't actually exist on # If this is a virtual interface, set some fake values that don't actually exist on
@ -125,7 +128,7 @@ sub update_network
# Speed is "as fast as possible", so we'll record 100 Gbps, but that is really kind of arbitrary. # Speed is "as fast as possible", so we'll record 100 Gbps, but that is really kind of arbitrary.
$speed = 100000 if ((not $speed) or ($speed eq "-1")); $speed = 100000 if ((not $speed) or ($speed eq "-1"));
$duplex = "full" if not $duplex; $duplex = "full" if not $duplex;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
speed => $speed, speed => $speed,
duplex => $duplex, duplex => $duplex,
}}); }});
@ -134,7 +137,7 @@ sub update_network
if (not $link_state) if (not $link_state)
{ {
$speed = 0; $speed = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { speed => $speed }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { speed => $speed }});
} }
# Is this a bond interface? # Is this a bond interface?
@ -154,7 +157,7 @@ sub update_network
$mii_polling_interval = $anvil->Storage->read_file({file => "/sys/devices/virtual/net/".$interface."/bonding/miimon"}); $mii_polling_interval = $anvil->Storage->read_file({file => "/sys/devices/virtual/net/".$interface."/bonding/miimon"});
$up_delay = $anvil->Storage->read_file({file => "/sys/devices/virtual/net/".$interface."/bonding/updelay"}); $up_delay = $anvil->Storage->read_file({file => "/sys/devices/virtual/net/".$interface."/bonding/updelay"});
$down_delay = $anvil->Storage->read_file({file => "/sys/devices/virtual/net/".$interface."/bonding/downdelay"}); $down_delay = $anvil->Storage->read_file({file => "/sys/devices/virtual/net/".$interface."/bonding/downdelay"});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
active_slave => $active_slave, active_slave => $active_slave,
bond_mode => $bond_mode, bond_mode => $bond_mode,
mii_polling_interval => $mii_polling_interval, mii_polling_interval => $mii_polling_interval,
@ -168,13 +171,13 @@ sub update_network
# No, but it's slaved to one. # No, but it's slaved to one.
my $target = readlink($full_path."/master"); my $target = readlink($full_path."/master");
$bond_master = ($target =~ /^.*\/(.*)$/)[0]; $bond_master = ($target =~ /^.*\/(.*)$/)[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
target => $target, target => $target,
bond_master => $bond_master, bond_master => $bond_master,
}}); }});
} }
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
active_slave => $active_slave, active_slave => $active_slave,
bond_master => $bond_master, bond_master => $bond_master,
bond_mode => $bond_mode, bond_mode => $bond_mode,
@ -207,7 +210,7 @@ sub update_network
# NOTE: This is probably 0 now... Though someday >100 Gbps will be reasonable # NOTE: This is probably 0 now... Though someday >100 Gbps will be reasonable
# and we'll need to change this. # and we'll need to change this.
$speed = 0; $speed = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { speed => $speed }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { speed => $speed }});
} }
# Find the media, if possible. # Find the media, if possible.
@ -219,14 +222,14 @@ sub update_network
if ($line =~ /Supported ports: \[ (.*?) \]/i) if ($line =~ /Supported ports: \[ (.*?) \]/i)
{ {
$media = lc($1); $media = lc($1);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { media => $media }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { media => $media }});
last; last;
} }
} }
# Record this interface # Record this interface
$anvil->data->{seen}{$type}{$interface} = 1; $anvil->data->{seen}{$type}{$interface} = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "seen::${type}::${interface}" => $anvil->data->{seen}{$type}{$interface} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "seen::${type}::${interface}" => $anvil->data->{seen}{$type}{$interface} }});
# Log # Log
$anvil->data->{network}{interfaces}{by_name}{$interface} = { $anvil->data->{network}{interfaces}{by_name}{$interface} = {
@ -249,7 +252,7 @@ sub update_network
type => $type, type => $type,
up_delay => $up_delay, up_delay => $up_delay,
}; };
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
"network::interfaces::by_name::${interface}::active_slave" => $anvil->data->{network}{interfaces}{by_name}{$interface}{active_slave}, "network::interfaces::by_name::${interface}::active_slave" => $anvil->data->{network}{interfaces}{by_name}{$interface}{active_slave},
"network::interfaces::by_name::${interface}::bond_mode" => $anvil->data->{network}{interfaces}{by_name}{$interface}{bond_mode}, "network::interfaces::by_name::${interface}::bond_mode" => $anvil->data->{network}{interfaces}{by_name}{$interface}{bond_mode},
"network::interfaces::by_name::${interface}::bond_master" => $anvil->data->{network}{interfaces}{by_name}{$interface}{bond_master}, "network::interfaces::by_name::${interface}::bond_master" => $anvil->data->{network}{interfaces}{by_name}{$interface}{bond_master},
@ -276,7 +279,7 @@ sub update_network
# We need to record bonds first so that their UUIDs are available when recording interfaces. # We need to record bonds first so that their UUIDs are available when recording interfaces.
foreach my $processing ("bond", "interface") foreach my $processing ("bond", "interface")
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { processing => $processing }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { processing => $processing }});
foreach my $interface (sort {$a cmp $b} keys %{$anvil->data->{network}{interfaces}{by_name}}) foreach my $interface (sort {$a cmp $b} keys %{$anvil->data->{network}{interfaces}{by_name}})
{ {
my $active_slave = $anvil->data->{network}{interfaces}{by_name}{$interface}{active_slave}; my $active_slave = $anvil->data->{network}{interfaces}{by_name}{$interface}{active_slave};
@ -300,7 +303,7 @@ sub update_network
my $default_gateway = $anvil->data->{sys}{network}{interface}{$interface}{default_gateway}; my $default_gateway = $anvil->data->{sys}{network}{interface}{$interface}{default_gateway};
my $gateway = $anvil->data->{sys}{network}{interface}{$interface}{gateway}; my $gateway = $anvil->data->{sys}{network}{interface}{$interface}{gateway};
my $dns = $anvil->data->{sys}{network}{interface}{$interface}{dns}; my $dns = $anvil->data->{sys}{network}{interface}{$interface}{dns};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
active_slave => $active_slave, active_slave => $active_slave,
bond_mode => $bond_mode, bond_mode => $bond_mode,
bond_master => $bond_master, bond_master => $bond_master,
@ -328,7 +331,6 @@ sub update_network
if (($type eq $processing) && ($type eq "bond")) if (($type eq $processing) && ($type eq "bond"))
{ {
my $bond_uuid = $anvil->Database->insert_or_update_bonds({ my $bond_uuid = $anvil->Database->insert_or_update_bonds({
debug => 2,
file => $THIS_FILE, file => $THIS_FILE,
line => __LINE__, line => __LINE__,
bond_name => $interface, bond_name => $interface,
@ -345,13 +347,12 @@ sub update_network
bond_down_delay => $down_delay, bond_down_delay => $down_delay,
}); });
$anvil->data->{bond_by_name}{$interface} = $bond_uuid; $anvil->data->{bond_by_name}{$interface} = $bond_uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "bond_by_name::${interface}" => $anvil->data->{bond_by_name}{$interface} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "bond_by_name::${interface}" => $anvil->data->{bond_by_name}{$interface} }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { bond_uuid => $bond_uuid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { bond_uuid => $bond_uuid }});
if (($bond_uuid) && ($ip_address)) if (($bond_uuid) && ($ip_address))
{ {
my $ip_address_uuid = $anvil->Database->insert_or_update_ip_addresses({ my $ip_address_uuid = $anvil->Database->insert_or_update_ip_addresses({
debug => 2,
file => $THIS_FILE, file => $THIS_FILE,
line => __LINE__, line => __LINE__,
ip_address_on_type => $type, ip_address_on_type => $type,
@ -368,17 +369,16 @@ sub update_network
if (($type eq $processing) && ($type eq "interface")) if (($type eq $processing) && ($type eq "interface"))
{ {
my $say_bond_uuid = ""; my $say_bond_uuid = "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { bond_master => $bond_master }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { bond_master => $bond_master }});
if (($bond_master) && ($anvil->data->{bond_by_name}{$bond_master})) if (($bond_master) && ($anvil->data->{bond_by_name}{$bond_master}))
{ {
$say_bond_uuid = $anvil->data->{bond_by_name}{$bond_master}; $say_bond_uuid = $anvil->data->{bond_by_name}{$bond_master};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
"bond_by_name::${bond_master}" => $anvil->data->{bond_by_name}{$bond_master}, "bond_by_name::${bond_master}" => $anvil->data->{bond_by_name}{$bond_master},
say_bond_uuid => $say_bond_uuid, say_bond_uuid => $say_bond_uuid,
}}); }});
} }
my $network_interface_uuid = $anvil->Database->insert_or_update_network_interfaces({ my $network_interface_uuid = $anvil->Database->insert_or_update_network_interfaces({
debug => 2,
file => $THIS_FILE, file => $THIS_FILE,
line => __LINE__, line => __LINE__,
network_interface_bond_uuid => $say_bond_uuid, network_interface_bond_uuid => $say_bond_uuid,
@ -392,13 +392,12 @@ sub update_network
network_interface_speed => $speed, network_interface_speed => $speed,
}); });
$anvil->data->{interface_by_name}{$interface} = $network_interface_uuid; $anvil->data->{interface_by_name}{$interface} = $network_interface_uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "interface_by_name::${interface}" => $anvil->data->{interface_by_name}{$interface} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "interface_by_name::${interface}" => $anvil->data->{interface_by_name}{$interface} }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { network_interface_uuid => $network_interface_uuid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { network_interface_uuid => $network_interface_uuid }});
if (($network_interface_uuid) && ($ip_address)) if (($network_interface_uuid) && ($ip_address))
{ {
my $ip_address_uuid = $anvil->Database->insert_or_update_ip_addresses({ my $ip_address_uuid = $anvil->Database->insert_or_update_ip_addresses({
debug => 2,
file => $THIS_FILE, file => $THIS_FILE,
line => __LINE__, line => __LINE__,
ip_address_on_type => $type, ip_address_on_type => $type,
@ -461,7 +460,7 @@ AND
bond_mac_address => $row->[10], bond_mac_address => $row->[10],
bond_operational => $row->[11], bond_operational => $row->[11],
}; };
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
"bonds::${bond_uuid}::bond_name" => $anvil->data->{bonds}{$bond_uuid}{bond_name}, "bonds::${bond_uuid}::bond_name" => $anvil->data->{bonds}{$bond_uuid}{bond_name},
"bonds::${bond_uuid}::bond_mode" => $anvil->data->{bonds}{$bond_uuid}{bond_mode}, "bonds::${bond_uuid}::bond_mode" => $anvil->data->{bonds}{$bond_uuid}{bond_mode},
"bonds::${bond_uuid}::bond_mtu" => $anvil->data->{bonds}{$bond_uuid}{bond_mtu}, "bonds::${bond_uuid}::bond_mtu" => $anvil->data->{bonds}{$bond_uuid}{bond_mtu},
@ -516,7 +515,7 @@ AND
bridge_id => $row->[2], bridge_id => $row->[2],
bridge_stp_enabled => $row->[3], bridge_stp_enabled => $row->[3],
}; };
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
"bridges::${bridge_uuid}::bridge_name" => $anvil->data->{bridges}{$bridge_uuid}{bridge_name}, "bridges::${bridge_uuid}::bridge_name" => $anvil->data->{bridges}{$bridge_uuid}{bridge_name},
"bridges::${bridge_uuid}::bridge_id" => $anvil->data->{bridges}{$bridge_uuid}{bridge_id}, "bridges::${bridge_uuid}::bridge_id" => $anvil->data->{bridges}{$bridge_uuid}{bridge_id},
"bridges::${bridge_uuid}::bridge_stp_enabled" => $anvil->data->{bridges}{$bridge_uuid}{bridge_stp_enabled}, "bridges::${bridge_uuid}::bridge_stp_enabled" => $anvil->data->{bridges}{$bridge_uuid}{bridge_stp_enabled},
@ -556,7 +555,7 @@ AND
ORDER BY ORDER BY
modified_date DESC modified_date DESC
;"; ;";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0124", variables => { query => $query }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0124", variables => { query => $query }});
$results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
$count = @{$results}; $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
@ -585,7 +584,7 @@ ORDER BY
network_interface_bond_uuid => defined $row->[9] ? $row->[9] : 'NULL', network_interface_bond_uuid => defined $row->[9] ? $row->[9] : 'NULL',
network_interface_bridge_uuid => defined $row->[10] ? $row->[10] : 'NULL', network_interface_bridge_uuid => defined $row->[10] ? $row->[10] : 'NULL',
}; };
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
"network_interfaces::${network_interface_uuid}::network_interface_mac_address" => $anvil->data->{network_interfaces}{$network_interface_uuid}{network_interface_mac_address}, "network_interfaces::${network_interface_uuid}::network_interface_mac_address" => $anvil->data->{network_interfaces}{$network_interface_uuid}{network_interface_mac_address},
"network_interfaces::${network_interface_uuid}::network_interface_name" => $anvil->data->{network_interfaces}{$network_interface_uuid}{network_interface_name}, "network_interfaces::${network_interface_uuid}::network_interface_name" => $anvil->data->{network_interfaces}{$network_interface_uuid}{network_interface_name},
"network_interfaces::${network_interface_uuid}::network_interface_speed" => $anvil->data->{network_interfaces}{$network_interface_uuid}{network_interface_speed}, "network_interfaces::${network_interface_uuid}::network_interface_speed" => $anvil->data->{network_interfaces}{$network_interface_uuid}{network_interface_speed},
@ -670,7 +669,7 @@ WHERE
my $ip_address_gateway = $row->[5]; my $ip_address_gateway = $row->[5];
my $ip_address_default_gateway = $row->[6]; my $ip_address_default_gateway = $row->[6];
my $ip_address_dns = $row->[7]; my $ip_address_dns = $row->[7];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
ip_address_on_type => $ip_address_on_type, ip_address_on_type => $ip_address_on_type,
ip_address_on_uuid => $ip_address_on_uuid, ip_address_on_uuid => $ip_address_on_uuid,
ip_address_address => $ip_address_address, ip_address_address => $ip_address_address,
@ -684,7 +683,7 @@ WHERE
my $found = 0; my $found = 0;
foreach my $interface (sort {$a cmp $b} keys %{$anvil->data->{sys}{network}{interface}}) foreach my $interface (sort {$a cmp $b} keys %{$anvil->data->{sys}{network}{interface}})
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
interface => $interface, interface => $interface,
ip_address_address => $ip_address_address, ip_address_address => $ip_address_address,
"sys::network::interface::${interface}::ip" => $anvil->data->{sys}{network}{interface}{$interface}{ip}, "sys::network::interface::${interface}::ip" => $anvil->data->{sys}{network}{interface}{$interface}{ip},
@ -692,29 +691,29 @@ WHERE
if ((defined $anvil->data->{sys}{network}{interface}{$interface}{ip}) && ($anvil->data->{sys}{network}{interface}{$interface}{ip} eq $ip_address_address)) if ((defined $anvil->data->{sys}{network}{interface}{$interface}{ip}) && ($anvil->data->{sys}{network}{interface}{$interface}{ip} eq $ip_address_address))
{ {
$found = 1; $found = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { found => $found }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { found => $found }});
last; last;
} }
} }
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { found => $found }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { found => $found }});
if ($found) if ($found)
{ {
my $say_on = ""; my $say_on = "";
if ($ip_address_on_type eq "interface") if ($ip_address_on_type eq "interface")
{ {
$say_on = $anvil->data->{network_interfaces}{$ip_address_on_uuid}{network_interface_name}; $say_on = $anvil->data->{network_interfaces}{$ip_address_on_uuid}{network_interface_name};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { say_on => $say_on }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { say_on => $say_on }});
} }
elsif ($ip_address_on_type eq "bond") elsif ($ip_address_on_type eq "bond")
{ {
$say_on = $anvil->data->{bonds}{$ip_address_on_uuid}{bond_name}; $say_on = $anvil->data->{bonds}{$ip_address_on_uuid}{bond_name};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { say_on => $say_on }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { say_on => $say_on }});
} }
elsif ($ip_address_on_type eq "bridge") elsif ($ip_address_on_type eq "bridge")
{ {
$say_on = $anvil->data->{bridges}{$ip_address_on_uuid}{bridge_name}; $say_on = $anvil->data->{bridges}{$ip_address_on_uuid}{bridge_name};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { say_on => $say_on }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { say_on => $say_on }});
} }
$network_json .= " { \"address\":\"$ip_address_address\", \"on\":\"$say_on\", \"subnet\":\"$ip_address_subnet_mask\", \"gateway\":\"$ip_address_gateway\", \"default_gateway\":\"$ip_address_default_gateway\", \"dns\":\"$ip_address_dns\" },\n"; $network_json .= " { \"address\":\"$ip_address_address\", \"on\":\"$say_on\", \"subnet\":\"$ip_address_subnet_mask\", \"gateway\":\"$ip_address_gateway\", \"default_gateway\":\"$ip_address_default_gateway\", \"dns\":\"$ip_address_dns\" },\n";
@ -730,10 +729,10 @@ WHERE
$network_json =~ s/,$//s; $network_json =~ s/,$//s;
$network_json .= "]}\n"; $network_json .= "]}\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { network_json => $network_json }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { network_json => $network_json }});
$network_xml .= "</network>\n"; $network_xml .= "</network>\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { network_xml => $network_xml }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { network_xml => $network_xml }});
# Write the JSON file. # Write the JSON file.
my $output_json = $anvil->data->{path}{directories}{html}."/status/network.json"; my $output_json = $anvil->data->{path}{directories}{html}."/status/network.json";

@ -16,6 +16,9 @@
# 2 = The job UUID was passed, but it wasn't valid. # 2 = The job UUID was passed, but it wasn't valid.
# 3 = It looks like the update failed, reset progress to '0'. # 3 = It looks like the update failed, reset progress to '0'.
# #
# TODO:
# - Use this to update local repos for when we get to the Install Manifest stage.
#
use strict; use strict;
use warnings; use warnings;
@ -34,9 +37,10 @@ if (($running_directory =~ /^\./) && ($ENV{PWD}))
my $anvil = Anvil::Tools->new({log_level => 2, log_secure => 1}); my $anvil = Anvil::Tools->new({log_level => 2, log_secure => 1});
$anvil->Storage->read_config({file => "/etc/anvil/anvil.conf"}); $anvil->Storage->read_config({file => "/etc/anvil/anvil.conf"});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }});
# Read switches # Read switches
$anvil->data->{switches}{'job-uuid'} = ""; $anvil->data->{switches}{'job-uuid'} = "";
$anvil->Get->switches; $anvil->Get->switches;
# Log that we've started. # Log that we've started.
@ -44,7 +48,7 @@ $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, secure =
# Connect to DBs. # Connect to DBs.
$anvil->Database->connect; $anvil->Database->connect;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132"}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0132"});
if (not $anvil->data->{sys}{database}{connections}) if (not $anvil->data->{sys}{database}{connections})
{ {
# No databases, exit. # No databases, exit.
@ -54,12 +58,12 @@ if (not $anvil->data->{sys}{database}{connections})
} }
# Did we get called with a job UUID? If not, try to find a pending job and take it. # Did we get called with a job UUID? If not, try to find a pending job and take it.
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "switches::job-uuid" => $anvil->data->{switches}{'job-uuid'} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "switches::job-uuid" => $anvil->data->{switches}{'job-uuid'} }});
if (not $anvil->data->{switches}{'job-uuid'}) if (not $anvil->data->{switches}{'job-uuid'})
{ {
# See if a job is waiting to run. # See if a job is waiting to run.
$anvil->data->{switches}{job_uuid} = $anvil->Job->get_job_uuid({debug => 2, program => $THIS_FILE}); $anvil->data->{switches}{job_uuid} = $anvil->Job->get_job_uuid({program => $THIS_FILE});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "switches::job-uuid" => $anvil->data->{switches}{'job-uuid'} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "switches::job-uuid" => $anvil->data->{switches}{'job-uuid'} }});
} }
if ($anvil->data->{switches}{'job-uuid'}) if ($anvil->data->{switches}{'job-uuid'})
{ {
@ -85,11 +89,11 @@ FROM
WHERE WHERE
job_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($anvil->data->{switches}{'job-uuid'})." job_uuid = ".$anvil->data->{sys}{database}{use_handle}->quote($anvil->data->{switches}{'job-uuid'})."
;"; ;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }});
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
my $count = @{$results}; my $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
results => $results, results => $results,
count => $count, count => $count,
}}); }});
@ -107,7 +111,7 @@ WHERE
$anvil->data->{jobs}{job_updated} = $results->[0]->[2]; $anvil->data->{jobs}{job_updated} = $results->[0]->[2];
$anvil->data->{jobs}{job_name} = $results->[0]->[3]; $anvil->data->{jobs}{job_name} = $results->[0]->[3];
$anvil->data->{jobs}{job_status} = $results->[0]->[4]; $anvil->data->{jobs}{job_status} = $results->[0]->[4];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
"jobs::job_uuid" => $anvil->data->{jobs}{job_uuid}, "jobs::job_uuid" => $anvil->data->{jobs}{job_uuid},
"jobs::job_host_uuid" => $anvil->data->{jobs}{job_host_uuid}, "jobs::job_host_uuid" => $anvil->data->{jobs}{job_host_uuid},
"jobs::job_data" => $anvil->data->{jobs}{job_data}, "jobs::job_data" => $anvil->data->{jobs}{job_data},
@ -131,14 +135,14 @@ update_progress($anvil, 1, "message_0058,!!downloaded!0!!,!!installed!0!!,!!veri
update_progress($anvil, 2, "message_0033"); update_progress($anvil, 2, "message_0033");
# Make sure maintenance mode is enabled. # Make sure maintenance mode is enabled.
$anvil->System->maintenance_mode({debug => 3, set => 1}); $anvil->System->maintenance_mode({set => 1});
# Run the update # Run the update
run_os_update($anvil); run_os_update($anvil);
# We're done updating # We're done updating
my $reboot_needed = $anvil->System->reboot_needed({debug => 2, set => 1}); my $reboot_needed = $anvil->System->reboot_needed();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { reboot_needed => $reboot_needed }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { reboot_needed => $reboot_needed }});
if ($reboot_needed) if ($reboot_needed)
{ {
update_progress($anvil, 100, "message_0039"); update_progress($anvil, 100, "message_0039");
@ -149,7 +153,7 @@ else
} }
# Clear maintenance mode. # Clear maintenance mode.
$anvil->System->maintenance_mode({debug => 3, set => 0}); $anvil->System->maintenance_mode({set => 0});
$anvil->nice_exit({exit_code => 0}); $anvil->nice_exit({exit_code => 0});
@ -164,7 +168,7 @@ sub update_progress
my ($anvil, $progress, $message) = @_; my ($anvil, $progress, $message) = @_;
# Log the progress percentage. # Log the progress percentage.
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
progress => $progress, progress => $progress,
message => $message, message => $message,
"jobs::job_uuid" => $anvil->data->{jobs}{job_uuid}, "jobs::job_uuid" => $anvil->data->{jobs}{job_uuid},
@ -173,7 +177,7 @@ sub update_progress
if ($anvil->data->{jobs}{job_uuid}) if ($anvil->data->{jobs}{job_uuid})
{ {
$anvil->Job->update_progress({ $anvil->Job->update_progress({
debug => 2, debug => 3,
progress => $progress, progress => $progress,
message => $message, message => $message,
job_uuid => $anvil->data->{jobs}{job_uuid}, job_uuid => $anvil->data->{jobs}{job_uuid},
@ -199,7 +203,7 @@ sub run_os_update
my $verifying = 0; my $verifying = 0;
my $output = ""; my $output = "";
my $shell_call = $anvil->data->{path}{exe}{dnf}." clean expire-cache && ".$anvil->data->{path}{exe}{dnf}." -y update; ".$anvil->data->{path}{exe}{echo}." return_code:\$?"; my $shell_call = $anvil->data->{path}{exe}{dnf}." clean expire-cache && ".$anvil->data->{path}{exe}{dnf}." -y update; ".$anvil->data->{path}{exe}{echo}." return_code:\$?";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { shell_call => $shell_call }});
open (my $file_handle, $shell_call." 2>&1 |") or $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, secure => 0, priority => "err", key => "log_0014", variables => { shell_call => $shell_call, error => $! }}); open (my $file_handle, $shell_call." 2>&1 |") or $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, secure => 0, priority => "err", key => "log_0014", variables => { shell_call => $shell_call, error => $! }});
while(<$file_handle>) while(<$file_handle>)
{ {
@ -215,8 +219,8 @@ sub run_os_update
# Reboot will be needed. # Reboot will be needed.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, secure => 0, key => "log_0199"}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, secure => 0, key => "log_0199"});
my $reboot_needed = $anvil->System->reboot_needed({debug => 2, set => 1}); my $reboot_needed = $anvil->System->reboot_needed({set => 1});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { reboot_needed => $reboot_needed }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { reboot_needed => $reboot_needed }});
} }
# If there were no updates, let the user know. # If there were no updates, let the user know.
@ -245,11 +249,11 @@ sub run_os_update
if ($line =~ /return_code:(\d+)$/) if ($line =~ /return_code:(\d+)$/)
{ {
my $return_code = $1; my $return_code = $1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { return_code => $return_code }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { return_code => $return_code }});
if ($return_code == 0) if ($return_code == 0)
{ {
$success = 1; $success = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { success => $success }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { success => $success }});
} }
} }
@ -257,7 +261,7 @@ sub run_os_update
{ {
my $counted_lines = $1; my $counted_lines = $1;
$to_update += $counted_lines; $to_update += $counted_lines;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
counted_lines => $counted_lines, counted_lines => $counted_lines,
to_update => $to_update, to_update => $to_update,
}}); }});
@ -266,7 +270,7 @@ sub run_os_update
if ($line =~ /Total download size: (.*)$/i) if ($line =~ /Total download size: (.*)$/i)
{ {
my $update_size = $1; my $update_size = $1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { update_size => $update_size }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { update_size => $update_size }});
# Ready to install, update to 5%. The next step will count up to 95%. # Ready to install, update to 5%. The next step will count up to 95%.
update_progress($anvil, $progress, "message_0035,!!size!$update_size!!"); update_progress($anvil, $progress, "message_0035,!!size!$update_size!!");
@ -278,7 +282,7 @@ sub run_os_update
$to_update *= 4; $to_update *= 4;
$percent_step = $anvil->Convert->round({number => ($to_update / 90)}); $percent_step = $anvil->Convert->round({number => ($to_update / 90)});
$next_step = $percent_step; $next_step = $percent_step;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
to_update => $to_update, to_update => $to_update,
percent_step => $percent_step, percent_step => $percent_step,
next_step => $next_step, next_step => $next_step,
@ -289,22 +293,22 @@ sub run_os_update
if (($percent_step) && (($line =~ /\(\d+\/\d+\): /) or ($line =~ /^Upgrading /i) or ($line =~ /^Installing /) or ($line =~ /^Cleanup /i) or ($line =~ /^Verifying /i))) if (($percent_step) && (($line =~ /\(\d+\/\d+\): /) or ($line =~ /^Upgrading /i) or ($line =~ /^Installing /) or ($line =~ /^Cleanup /i) or ($line =~ /^Verifying /i)))
{ {
$counted_lines++; $counted_lines++;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { counted_lines => $counted_lines }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { counted_lines => $counted_lines }});
if ($line =~ /\(\d+\/\d+\): /) if ($line =~ /\(\d+\/\d+\): /)
{ {
$anvil->data->{counts}{downloaded}++; $anvil->data->{counts}{downloaded}++;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "counts::downloaded" => $anvil->data->{counts}{downloaded} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "counts::downloaded" => $anvil->data->{counts}{downloaded} }});
} }
if (($line =~ /^Upgrading /i) or ($line =~ /^Installing /)) if (($line =~ /^Upgrading /i) or ($line =~ /^Installing /))
{ {
$anvil->data->{counts}{installed}++; $anvil->data->{counts}{installed}++;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "counts::installed" => $anvil->data->{counts}{installed} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "counts::installed" => $anvil->data->{counts}{installed} }});
} }
if ($line =~ /^Verifying /i) if ($line =~ /^Verifying /i)
{ {
$anvil->data->{counts}{verified}++; $anvil->data->{counts}{verified}++;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "counts::verified" => $anvil->data->{counts}{verified} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "counts::verified" => $anvil->data->{counts}{verified} }});
} }
if ($counted_lines > $next_step) if ($counted_lines > $next_step)
@ -316,7 +320,7 @@ sub run_os_update
next_step => $next_step, next_step => $next_step,
progress => $progress, progress => $progress,
}}); }});
next if $progress > 95; $progress = 95 if $progress > 95;
update_progress($anvil, $progress, ""); update_progress($anvil, $progress, "");
} }
@ -325,14 +329,15 @@ sub run_os_update
# Update the progress if it's been more than a second since the last update. # Update the progress if it's been more than a second since the last update.
if (time > $anvil->data->{sys}{last_update}) if (time > $anvil->data->{sys}{last_update})
{ {
$progress = 95 if $progress > 95;
update_progress($anvil, $progress, ""); update_progress($anvil, $progress, "");
} }
} }
close $file_handle; close $file_handle;
# Reload daemons to pick up any changed systemctl daemons. # Reload daemons to pick up any changed systemctl daemons.
my $systemctl_output = $anvil->System->call({debug => 2, shell_call => $anvil->data->{path}{exe}{systemctl}." daemon-reload", source => $THIS_FILE, line => __LINE__}); my $systemctl_output = $anvil->System->call({debug => 3, 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 => { systemctl_output => $systemctl_output }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { systemctl_output => $systemctl_output }});
# Did it work? # Did it work?
if (not $success) if (not $success)

Loading…
Cancel
Save