More logging to debug apparent hang

* Added an explicit 'sync' call when writing to logs. TO BE REMOVED!
* Disabled anvil-monitor-daemons and anvil-monitor-performance in case
  this is somehow trigging program exits.
* Converted prints to Log->entry calls in anvil-change-password
* Added PID state info logging for running jobs.

Signed-off-by: digimer <mkelly@alteeve.ca>
main
digimer 4 months ago
parent 4766ceff70
commit b86493fff4
  1. 1
      Anvil/Tools/Log.pm
  2. 4
      anvil.spec.in
  3. 31
      tools/anvil-change-password
  4. 12
      tools/anvil-configure-host
  5. 12
      tools/anvil-daemon

@ -544,6 +544,7 @@ sub entry
# The handle has to be wrapped in a block to make 'print' happy as it doesn't like non-scalars for file handles
print { $anvil->data->{HANDLE}{'log'}{alert} } $log_to_alert;
system('/usr/bin/sync');
}
$anvil->data->{loop}{count} = 0;
}

@ -263,10 +263,10 @@ setenforce 0
### TODO: check it if was disabled (if it existed before) and, if so, leave it disabled.
systemctl enable --now chronyd.service
systemctl enable --now anvil-daemon.service
systemctl enable --now anvil-monitor-daemons.service
systemctl enable --now anvil-monitor-network.service
systemctl enable --now anvil-monitor-performance.service
systemctl enable --now scancore.service
systemctl disable --now anvil-monitor-daemons.service
systemctl disable --now anvil-monitor-performance.service
%pre striker
getent passwd %{suiapi} >/dev/null \

@ -36,7 +36,7 @@ my $anvil = Anvil::Tools->new();
if (($< != 0) && ($> != 0))
{
# Not root
print $anvil->Words->string({key => "error_0005"})."\n";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "error_0005"});
$anvil->nice_exit({exit_code => 1});
}
@ -50,7 +50,7 @@ $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure =
if (not $anvil->data->{sys}{database}{connections})
{
# No databases, exit.
print $anvil->Words->string({key => "error_0003"})."\n";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "error_0003"});
$anvil->nice_exit({exit_code => 2});
}
@ -71,7 +71,7 @@ if ($anvil->data->{switches}{'password-file'})
else
{
# The file doesn't exist.
print $anvil->Words->string({key => "error_0008", variables => { file => $anvil->data->{switches}{'password-file'} }})."\n";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "error_0008", variables => { file => $anvil->data->{switches}{'password-file'} }});
$anvil->nice_exit({exit_code => 4});
}
}
@ -110,7 +110,7 @@ elsif (not $anvil->data->{switches}{'new-password'})
}
else
{
print $anvil->Words->string({key => "error_0007"})."\n";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "error_0007"});
$anvil->nice_exit({exit_code => 3});
}
}
@ -130,7 +130,7 @@ else
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, secure => 1, list => { "switches::new-password" => $anvil->data->{switches}{'new-password'} }});
if (($anvil->data->{switches}{y}) or ($anvil->data->{switches}{yes}))
{
print $anvil->Words->string({key => "message_0023"})."\n";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, secure => 0, key => "message_0023"});
update_local_passwords($anvil);
}
else
@ -151,9 +151,10 @@ else
}
}
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "log_0750"});
$anvil->nice_exit({exit_code => 0});
#############################################################################################################
# Functions #
#############################################################################################################
@ -165,7 +166,7 @@ sub update_local_passwords
# Update the 'admin' user password in the database.
my $user = "admin";
print $anvil->Words->string({key => "message_0024", variables => { user => $user }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "message_0024", variables => { user => $user }});
my $user_uuid = $anvil->Database->insert_or_update_users({
debug => 2,
@ -177,7 +178,7 @@ sub update_local_passwords
});
# Log out any Striker sessions.
$anvil->Account->logout({host_uuid => "all"});
print $anvil->Words->string({key => "message_0025"})."\n";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "message_0025"});
# Validate
my $valid = $anvil->Account->validate_password({
@ -215,25 +216,25 @@ sub update_local_passwords
my $owner_name = $results->[0]->[1];
foreach my $user ("postgres", $owner_name)
{
print $anvil->Words->string({key => "message_0026", variables => { user => $user }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "message_0026", variables => { user => $user }});
my $query = "ALTER ROLE ".$user." WITH PASSWORD ".$dbh->quote($anvil->data->{switches}{'new-password'});
$dbh->do($query) or $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0090", variables => {
query => $anvil->Log->is_secure($query),
server => "localhost",
db_error => $DBI::errstr,
}});
print $anvil->Words->string({key => "message_0025"})."\n";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "message_0025"});
}
# Update our database password in anvil.conf
print $anvil->Words->string({key => "message_0027", variables => { file => $anvil->data->{switches}{'new-password'} }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "message_0027", variables => { file => $anvil->data->{switches}{'new-password'} }});
$anvil->Storage->update_config({
debug => 2,
secure => 1,
variable => "database::${host_uuid}::password",
value => $anvil->data->{switches}{'new-password'},
});
print $anvil->Words->string({key => "message_0025"})."\n";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "message_0025"});
### TODO: Loop through any other dashboards and nodes we know about and call the above with 'target'
### (and password, port and remote_user) set.
@ -241,13 +242,13 @@ sub update_local_passwords
# Update the local users.
foreach my $user ("admin", "root")
{
print $anvil->Words->string({key => "message_0028", variables => { user => $user }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "message_0028", variables => { user => $user }});
$anvil->System->change_shell_user_password({debug => 2, user => $user, new_password => $anvil->data->{switches}{'new-password'}});
print $anvil->Words->string({key => "message_0025"})."\n";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "message_0025"});
}
# All done!
print $anvil->Words->string({key => "message_0029"})."\n";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, 'print' => 1, key => "message_0029"});
return(0);
}

@ -245,8 +245,14 @@ sub update_passwords
my $shell_call = $anvil->data->{path}{exe}{'anvil-change-password'}." -y --password-file ".$temp_file.$anvil->Log->switches;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
my ($output, $return_code) = $anvil->System->call({timeout => 15, shell_call => $shell_call });
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { output => $output, return_code => $return_code }});
my ($output, $return_code) = $anvil->System->call({
debug => 2,
timeout => 30,
shell_call => $shell_call });
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
output => $output,
return_code => $return_code,
}});
if ($return_code)
{
@ -271,7 +277,9 @@ sub update_passwords
}
# Unlink the temp file.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0263", variables => { file => $temp_file }});
unlink $temp_file;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0283"});
}
}

@ -1752,6 +1752,18 @@ sub run_jobs
# The job is running.
$anvil->data->{jobs_started}{$short_command} = $job_uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "jobs_started::${short_command}" => $anvil->data->{jobs_started}{$short_command} }});
if ($short_command =~ /anvil-configure-host/)
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"pids::${job_picked_up_by}::cpu" => $anvil->data->{pids}{$job_picked_up_by}{cpu},
"pids::${job_picked_up_by}::memory" => $anvil->data->{pids}{$job_picked_up_by}{memory},
"pids::${job_picked_up_by}::state_codes" => $anvil->data->{pids}{$job_picked_up_by}{state_codes},
"pids::${job_picked_up_by}::start_time" => $anvil->data->{pids}{$job_picked_up_by}{start_time},
"pids::${job_picked_up_by}::time" => $anvil->data->{pids}{$job_picked_up_by}{'time'},
"pids::${job_picked_up_by}::command" => $anvil->data->{pids}{$job_picked_up_by}{command},
}});
}
}
}

Loading…
Cancel
Save