|
|
|
@ -10,6 +10,9 @@ |
|
|
|
|
# 3 = ScanCore user not set in the local ID in anvil.conf |
|
|
|
|
# 4 = Failed to create the database user. |
|
|
|
|
# 5 = PostgreSQL not installed. |
|
|
|
|
# |
|
|
|
|
# TODO: Much of this logic is duplicated in Database->configure_pgsql(), we should remove this tool entirely |
|
|
|
|
# and use that. |
|
|
|
|
|
|
|
|
|
use strict; |
|
|
|
|
use warnings; |
|
|
|
@ -41,8 +44,14 @@ $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list |
|
|
|
|
# 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) |
|
|
|
|
{ |
|
|
|
|
$local_uuid = add_to_local_config($anvil); |
|
|
|
|
$local_uuid = $anvil->Database->_add_to_local_config({debug => 2}); |
|
|
|
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { local_uuid => $local_uuid }}); |
|
|
|
|
|
|
|
|
|
if ($local_uuid eq "!!error!!") |
|
|
|
|
{ |
|
|
|
|
# Already logged the error, exit. |
|
|
|
|
$anvil->nice_exit({exit_code => 1}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
# Now configure! |
|
|
|
@ -61,7 +70,7 @@ if ($local_uuid) |
|
|
|
|
my $shell_call = $anvil->data->{path}{exe}{rpm}." -q postgresql-server"; |
|
|
|
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { shell_call => $shell_call }}); |
|
|
|
|
|
|
|
|
|
my ($output, $return_code) = $anvil->System->call({shell_call => $shell_call, debug => 2, source => $THIS_FILE, line => __LINE__}); |
|
|
|
|
my ($output, $return_code) = $anvil->System->call({shell_call => $shell_call, debug => 3, source => $THIS_FILE, line => __LINE__}); |
|
|
|
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { |
|
|
|
|
output => $output, |
|
|
|
|
return_code => $return_code, |
|
|
|
@ -336,6 +345,7 @@ if ($local_uuid) |
|
|
|
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0096", variables => { user => $database_user }}); |
|
|
|
|
$anvil->nice_exit({exit_code => 4}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
# 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} }}); |
|
|
|
@ -361,7 +371,6 @@ if ($local_uuid) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
# Create the database, if needed. |
|
|
|
|
my $create_database = 1; |
|
|
|
@ -636,54 +645,3 @@ sub configure_firewall |
|
|
|
|
return(0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
# This adds this machine to the local anvil.conf file. |
|
|
|
|
sub add_to_local_config |
|
|
|
|
{ |
|
|
|
|
my ($anvil) = @_; |
|
|
|
|
|
|
|
|
|
# Write the password to a file. |
|
|
|
|
my $password_file = "/tmp/striker-manage-peers.".$anvil->Get->uuid; |
|
|
|
|
$anvil->Storage->write_file({ |
|
|
|
|
debug => 3, |
|
|
|
|
secure => 1, |
|
|
|
|
file => $password_file, |
|
|
|
|
body => "Initial1", |
|
|
|
|
mode => "0600", |
|
|
|
|
overwrite => 1, |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
# Make the shell call, and parse the output looking for our own entry |
|
|
|
|
my $host_uuid = $anvil->Get->host_uuid(); |
|
|
|
|
my $shell_call = $anvil->data->{path}{exe}{'striker-manage-peers'}." --add --host-uuid ".$anvil->Get->host_uuid." --host localhost --port 5432 --password-file ".$password_file." --ping 0".$anvil->Log->switches; |
|
|
|
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
|
|
|
host_uuid => $host_uuid, |
|
|
|
|
shell_call => $shell_call, |
|
|
|
|
}}); |
|
|
|
|
my ($output, $return_code) = $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, |
|
|
|
|
return_code => $return_code, |
|
|
|
|
}}); |
|
|
|
|
|
|
|
|
|
# Remove the password. |
|
|
|
|
unlink $password_file; |
|
|
|
|
|
|
|
|
|
# Re-read the config and make sure we have our own entry. |
|
|
|
|
$anvil->refresh(); |
|
|
|
|
|
|
|
|
|
# If we still don't have a local_uuid, something went wrong. |
|
|
|
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
|
|
|
"database::${host_uuid}::host" => $anvil->data->{database}{$host_uuid}{host}, |
|
|
|
|
"database::${host_uuid}::port" => $anvil->data->{database}{$host_uuid}{port}, |
|
|
|
|
"database::${host_uuid}::password" => $anvil->Log->is_secure($anvil->data->{database}{$host_uuid}{password}), |
|
|
|
|
"database::${host_uuid}::ping" => $anvil->data->{database}{$host_uuid}{ping}, |
|
|
|
|
}}); |
|
|
|
|
if (not $anvil->data->{database}{$host_uuid}{host}) |
|
|
|
|
{ |
|
|
|
|
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, key => "error_0010"}); |
|
|
|
|
$anvil->nice_exit({exit_code => 1}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return($host_uuid); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|