* Resolved a words.xml conflict.

* Reworked where and how Database->configure_pgsql() is called, and boosted logging around it (trying to debug a build test issues).
* Updated Database->configure_pgsql() to only check if the Anvil! user and DB exists if another step of the config happened.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 3 years ago
parent e60a1b46b3
commit 5c07179aa6
  1. 49
      Anvil/Tools/Database.pm
  2. 4
      share/words.xml
  3. 4
      tools/anvil-manage-dr
  4. 2
      tools/striker-manage-install-target

@ -803,11 +803,11 @@ sub configure_pgsql
my $initialized = 0; my $initialized = 0;
my $running = $anvil->System->check_daemon({debug => $debug, daemon => $anvil->data->{sys}{daemon}{postgresql}}); my $running = $anvil->System->check_daemon({debug => $debug, daemon => $anvil->data->{sys}{daemon}{postgresql}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { running => $running }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { running => $running }});
if ((not $running) && (not -e $anvil->data->{path}{configs}{'pg_hba.conf'})) if (not -e $anvil->data->{path}{configs}{'pg_hba.conf'})
{ {
# Initialize. Record that we did so, so that we know to start the daemon. # Initialize. Record that we did so, so that we know to start the daemon.
my ($output, $return_code) = $anvil->System->call({debug => $debug, shell_call => $anvil->data->{path}{exe}{'postgresql-setup'}." initdb", source => $THIS_FILE, line => __LINE__}); my ($output, $return_code) = $anvil->System->call({debug => 1, shell_call => $anvil->data->{path}{exe}{'postgresql-setup'}." initdb", source => $THIS_FILE, line => __LINE__});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { output => $output, return_code => $return_code }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { output => $output, return_code => $return_code }});
# Did it succeed? # Did it succeed?
if (not -e $anvil->data->{path}{configs}{'pg_hba.conf'}) if (not -e $anvil->data->{path}{configs}{'pg_hba.conf'})
@ -911,7 +911,7 @@ sub configure_pgsql
{ {
# Back up the existing one, if needed. # Back up the existing one, if needed.
my $pg_hba_backup = $anvil->data->{path}{directories}{backups}."/pgsql/pg_hba.conf"; my $pg_hba_backup = $anvil->data->{path}{directories}{backups}."/pgsql/pg_hba.conf";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { pg_hba_backup => $pg_hba_backup }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { pg_hba_backup => $pg_hba_backup }});
if (not -e $pg_hba_backup) if (not -e $pg_hba_backup)
{ {
$anvil->Storage->copy_file({ $anvil->Storage->copy_file({
@ -940,7 +940,7 @@ sub configure_pgsql
{ {
# Start the daemon. # Start the daemon.
my $return_code = $anvil->System->start_daemon({daemon => $anvil->data->{sys}{daemon}{postgresql}}); my $return_code = $anvil->System->start_daemon({daemon => $anvil->data->{sys}{daemon}{postgresql}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { return_code => $return_code }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { return_code => $return_code }});
if ($return_code eq "0") if ($return_code eq "0")
{ {
# Started the daemon. # Started the daemon.
@ -958,7 +958,7 @@ sub configure_pgsql
{ {
# Reload # Reload
my $return_code = $anvil->System->start_daemon({daemon => $anvil->data->{sys}{daemon}{postgresql}}); my $return_code = $anvil->System->start_daemon({daemon => $anvil->data->{sys}{daemon}{postgresql}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { return_code => $return_code }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { return_code => $return_code }});
if ($return_code eq "0") if ($return_code eq "0")
{ {
# Reloaded the daemon. # Reloaded the daemon.
@ -971,6 +971,9 @@ sub configure_pgsql
} }
} }
# Do user and DB checks only if we're made a change above.
if (($initialized) or ($update_postgresql_file) or ($update_pg_hba_file))
{
# Create the .pgpass file, if needed. # Create the .pgpass file, if needed.
my $created_pgpass = 0; my $created_pgpass = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 1, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 1, list => {
@ -1117,6 +1120,7 @@ sub configure_pgsql
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "alert", key => "log_0107"}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "alert", key => "log_0107"});
} }
} }
}
# Make sure the psql TCP port is open. # Make sure the psql TCP port is open.
$anvil->data->{database}{$uuid}{port} = 5432 if not $anvil->data->{database}{$uuid}{port}; $anvil->data->{database}{$uuid}{port} = 5432 if not $anvil->data->{database}{$uuid}{port};
@ -1314,6 +1318,23 @@ sub connect
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { check_for_resync => $check_for_resync }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { check_for_resync => $check_for_resync }});
} }
# If we're a Striker, see if we're configured.
my $local_host_type = $anvil->Get->host_type();
my $local_host_uuid = $anvil->Get->host_uuid();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
local_host_type => $local_host_type,
local_host_uuid => $local_host_uuid,
check_if_configured => $check_if_configured,
real_uid => $<,
effective_uid => $>,
}});
# If requested, and if running with root access, set it up (or update it) if needed.
# This method just returns if nothing is needed.
if (($local_host_type eq "striker") && ($check_if_configured) && ($< == 0) && ($> == 0))
{
$anvil->Database->configure_pgsql({debug => 2, uuid => $local_host_uuid});
}
# Now setup or however-many connections # Now setup or however-many connections
my $seen_connections = []; my $seen_connections = [];
my $failed_connections = []; my $failed_connections = [];
@ -1636,24 +1657,12 @@ sub connect
} }
# Before we try to connect, see if this is a local database and, if so, make sure it's setup. # Before we try to connect, see if this is a local database and, if so, make sure it's setup.
my $is_local = $anvil->Network->is_local({debug => $debug, host => $host}); my $is_local = $anvil->Network->is_local({debug => 2, host => $host});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { is_local => $is_local }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { is_local => $is_local }});
if ($is_local) if ($is_local)
{ {
$anvil->data->{sys}{database}{read_uuid} = $uuid; $anvil->data->{sys}{database}{read_uuid} = $uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "sys::database::read_uuid" => $anvil->data->{sys}{database}{read_uuid} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "sys::database::read_uuid" => $anvil->data->{sys}{database}{read_uuid} }});
# If requested, and if running with root access, set it up (or update it) if needed.
# This method just returns if nothing is needed.
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
check_if_configured => $check_if_configured,
real_uid => $<,
effective_uid => $>,
}});
if (($check_if_configured) && ($< == 0) && ($> == 0))
{
$anvil->Database->configure_pgsql({debug => $debug, uuid => $uuid});
}
} }
elsif (not $anvil->data->{sys}{database}{read_uuid}) elsif (not $anvil->data->{sys}{database}{read_uuid})
{ {
@ -1699,8 +1708,6 @@ sub connect
} }
# If we're a striker and no connections were found, start our database. # If we're a striker and no connections were found, start our database.
my $local_host_type = $anvil->Get->host_type();
my $local_host_uuid = $anvil->Get->host_uuid();
if (($local_host_type eq "striker") && (not $anvil->data->{sys}{database}{connections})) if (($local_host_type eq "striker") && (not $anvil->data->{sys}{database}{connections}))
{ {
# Tell the user we're going to try to load and start. # Tell the user we're going to try to load and start.

@ -1229,8 +1229,6 @@ It should be provisioned in the next minute or two.</key>
<key name="job_0353">* Please enter the name of the server you want to manage</key> <key name="job_0353">* Please enter the name of the server you want to manage</key>
<key name="job_0354">-=] Servers available to manage on the Anvil! [#!variable!anvil_name!#] [=-</key> <key name="job_0354">-=] Servers available to manage on the Anvil! [#!variable!anvil_name!#] [=-</key>
<key name="job_0355">-=] Managing the server: [#!variable!server_name!#] on the Anvil!: [#!variable!anvil_name!#]</key> <key name="job_0355">-=] Managing the server: [#!variable!server_name!#] on the Anvil!: [#!variable!anvil_name!#]</key>
<key name="job_0356">Manage DR tasks for a given server</key>
<key name="job_0357">This job can protect, remove (unprotect), connect, disconnect or update (connect, sync, disconnect) a given server.</key>
<key name="job_0358">Running sanity checks.</key> <key name="job_0358">Running sanity checks.</key>
<key name="job_0359">Sanity checks complete!</key> <key name="job_0359">Sanity checks complete!</key>
<key name="job_0360">Beginning to protect the server: [#!variable!server!#]!</key> <key name="job_0360">Beginning to protect the server: [#!variable!server!#]!</key>
@ -1265,6 +1263,8 @@ It will take time for it to initialize, please be patient.</key>
<key name="job_0381">- Running the scan agent 'scan-drbd' locally to record the newly used TCP ports.</key> <key name="job_0381">- Running the scan agent 'scan-drbd' locally to record the newly used TCP ports.</key>
<key name="job_0382">- Running the scan agent 'scan-drbd' on: [#!variable!host_name!#] to record the newly used TCP ports.</key> <key name="job_0382">- Running the scan agent 'scan-drbd' on: [#!variable!host_name!#] to record the newly used TCP ports.</key>
<key name="job_0383">The job has been recorded with the UUID: [#!variable!job_uuid!#], it will start in just a moment if anvil-daemon is running.</key> <key name="job_0383">The job has been recorded with the UUID: [#!variable!job_uuid!#], it will start in just a moment if anvil-daemon is running.</key>
<key name="job_0384">Manage DR tasks for a given server</key>
<key name="job_0385">This job can protect, remove (unprotect), connect, disconnect or update (connect, sync, disconnect) a given server.</key>
<!-- Log entries --> <!-- Log entries -->
<key name="log_0001">Starting: [#!variable!program!#].</key> <key name="log_0001">Starting: [#!variable!program!#].</key>

@ -850,8 +850,8 @@ sub process_protect
job_command => $anvil->data->{path}{exe}{'anvil-manage-dr'}.$anvil->Log->switches, job_command => $anvil->data->{path}{exe}{'anvil-manage-dr'}.$anvil->Log->switches,
job_data => $job_data, job_data => $job_data,
job_name => "server::dr", job_name => "server::dr",
job_title => "job_0356", job_title => "job_0384",
job_description => "job_0357", job_description => "job_0385",
job_progress => 0, job_progress => 0,
job_host_uuid => $anvil->Get->host_uuid, job_host_uuid => $anvil->Get->host_uuid,
}); });

@ -176,7 +176,7 @@ if ($anvil->data->{switches}{disable})
# Exit if we're not configured yet # Exit if we're not configured yet
my $configured = $anvil->System->check_if_configured; my $configured = $anvil->System->check_if_configured;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { configured => $configured }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { configured => $configured }});
if (not $configured) if (not $configured)
{ {
print $anvil->Words->string({key => "error_0046"})."\n"; print $anvil->Words->string({key => "error_0046"})."\n";

Loading…
Cancel
Save