* Fixed a bug in Database->get_local_uuid() where it was calling the now-removed Get->network_details().

* Bumped the logging in and fixed a compile-time bug in striker-prep-database.
* Bumped the anvil.spec release to .25.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 5 years ago
parent ffceb2312d
commit ed048a5483
  1. 22
      Anvil/Tools/Database.pm
  2. 5
      rpm/SPECS/anvil.spec
  3. 58
      tools/striker-prep-database

@ -1653,14 +1653,12 @@ sub get_local_uuid
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3; my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Database->get_local_uuid()" }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Database->get_local_uuid()" }});
my $local_uuid = ""; my $local_uuid = "";
my $network_details = $anvil->Network->get_network_details;
foreach my $uuid (sort {$a cmp $b} keys %{$anvil->data->{database}}) foreach my $uuid (sort {$a cmp $b} keys %{$anvil->data->{database}})
{ {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { my $db_host = $anvil->data->{database}{$uuid}{host};
"network_details->hostname" => $network_details->{hostname}, $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { db_host => $db_host }});
"database::${uuid}::host" => $anvil->data->{database}{$uuid}{host},
}});
# If the uuid matches our host_uuid or if the hostname matches ours (or is localhost), return # If the uuid matches our host_uuid or if the hostname matches ours (or is localhost), return
# that UUID. # that UUID.
if ($uuid eq $anvil->Get->host_uuid) if ($uuid eq $anvil->Get->host_uuid)
@ -1669,7 +1667,7 @@ sub get_local_uuid
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { local_uuid => $local_uuid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { local_uuid => $local_uuid }});
last; last;
} }
elsif (($network_details->{hostname} eq $anvil->data->{database}{$uuid}{host}) or ($anvil->data->{database}{$uuid}{host} eq "localhost")) elsif ($anvil->Network->is_local($db_host))
{ {
$local_uuid = $uuid; $local_uuid = $uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { local_uuid => $local_uuid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { local_uuid => $local_uuid }});
@ -1677,13 +1675,17 @@ sub get_local_uuid
} }
} }
# Get out IPs.
$anvil->Network->get_ips({debug => $debug});
# Look for matches
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { local_uuid => $local_uuid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { local_uuid => $local_uuid }});
if (not $local_uuid) if (not $local_uuid)
{ {
foreach my $interface (sort {$a cmp $b} keys %{$network_details->{interface}}) foreach my $interface (sort {$a cmp $b} keys %{$anvil->data->{network}{'local'}{interface}})
{ {
my $ip_address = $network_details->{interface}{$interface}{ip}; my $ip_address = $anvil->data->{network}{'local'}{interface}{$interface}{ip};
my $subnet_mask = $network_details->{interface}{$interface}{netmask}; my $subnet_mask = $anvil->data->{network}{'local'}{interface}{$interface}{subnet};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
ip_address => $ip_address, ip_address => $ip_address,
subnet_mask => $subnet_mask, subnet_mask => $subnet_mask,

@ -3,7 +3,7 @@
%define anvilgroup admin %define anvilgroup admin
Name: anvil Name: anvil
Version: 3.0 Version: 3.0
Release: 24%{?dist} Release: 25%{?dist}
Summary: Alteeve Anvil! complete package. Summary: Alteeve Anvil! complete package.
License: GPLv2+ License: GPLv2+
@ -287,6 +287,9 @@ firewall-cmd --add-service=postgresql --permanent
%changelog %changelog
* Mon Sep 23 2019 Madison Kelly <mkelly@alteeve.ca> 3.0-25
- Fixed a couple bugs found in the previous release.
* Sun Sep 22 2019 Madison Kelly <mkelly@alteeve.ca> 3.0-24 * Sun Sep 22 2019 Madison Kelly <mkelly@alteeve.ca> 3.0-24
- Added syslinux to core requirements. - Added syslinux to core requirements.
- Added installation of ocf:alteeve:server resource agent to nodes. - Added installation of ocf:alteeve:server resource agent to nodes.

@ -27,26 +27,28 @@ if (($running_directory =~ /^\./) && ($ENV{PWD}))
$| = 1; $| = 1;
my $anvil = Anvil::Tools->new(); my $anvil = Anvil::Tools->new();
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }}); $anvil->Log->level({set => 2});
$anvil->Log->secure({set => 1});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, 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 => 3, list => { local_uuid => $local_uuid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, 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 => 3, list => { local_uuid => $local_uuid }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, 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 => 3, list => { "sys::service::postgresql" => $anvil->data->{sys}{daemon}{postgresql} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "sys::service::postgresql" => $anvil->data->{sys}{daemon}{postgresql} }});
my $running = $anvil->System->check_daemon({daemon => $anvil->data->{sys}{daemon}{postgresql}}); my $running = $anvil->System->check_daemon({debug => 2, daemon => $anvil->data->{sys}{daemon}{postgresql}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { running => $running }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { running => $running }});
if ($running eq "2") if ($running eq "2")
{ {
# Not installed. # Not installed.
@ -56,11 +58,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 => 3, list => { "path::configs::pg_hba.conf" => $anvil->data->{path}{configs}{'pg_hba.conf'} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, 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 => 3, list => { "path::configs::pg_hba.conf" => $anvil->data->{path}{configs}{'pg_hba.conf'} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "path::configs::pg_hba.conf" => $anvil->data->{path}{configs}{'pg_hba.conf'} }});
} }
else else
{ {
@ -96,7 +98,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 => 3, list => { postgresql_backup => $postgresql_backup }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, 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,
@ -149,12 +151,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 => 3, list => { line => $line }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, 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 => 3, list => { update_file => $update_file }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { update_file => $update_file }});
last; last;
} }
elsif ($line =~ /^# TYPE\s+DATABASE/) elsif ($line =~ /^# TYPE\s+DATABASE/)
@ -185,7 +187,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({daemon => $anvil->data->{sys}{daemon}{postgresql}}); my $return_code = $anvil->System->start_daemon({debug => 2, daemon => $anvil->data->{sys}{daemon}{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")
{ {
@ -193,7 +195,7 @@ if ($local_uuid)
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0059"}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0059"});
# Make sure it is enabled on boot. # Make sure it is enabled on boot.
my $return_code = $anvil->System->enable_daemon({daemon => $anvil->data->{sys}{daemon}{postgresql}}); my $return_code = $anvil->System->enable_daemon({debug => 2, daemon => $anvil->data->{sys}{daemon}{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 }});
} }
else else
@ -226,14 +228,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 => 3, list => { created_pgpass => $created_pgpass }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, 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 => 3, list => { database_user => $database_user }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { database_user => $database_user }});
if (not $database_user) if (not $database_user)
{ {
# No database user defined # No database user defined
@ -241,19 +243,19 @@ if ($local_uuid)
$anvil->nice_exit({code => 3}); $anvil->nice_exit({code => 3});
} }
my ($user_list, $return_code) = $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, $return_code) = $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 => 3, list => { output => $output, return_code => $return_code }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { user_list => $user_list, return_code => $return_code }});
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 => 3, key => "log_0060", variables => { user => $database_user, id => $id }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, 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 => 3, list => { create_user => $create_user }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { create_user => $create_user }});
if ($create_user) if ($create_user)
{ {
# Create the user # Create the user
@ -279,13 +281,13 @@ if ($local_uuid)
} }
# Update/set the passwords. # Update/set the passwords.
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, secure => 1, list => { "database::${local_uuid}::password" => $anvil->data->{database}{$local_uuid}{password} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, 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, $return_code) = $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, $return_code) = $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 => 3, secure => 1, list => { update_output => $update_output, return_code => $return_code }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, secure => 1, list => { update_output => $update_output, return_code => $return_code }});
foreach my $line (split/\n/, $user_list) foreach my $line (split/\n/, $user_list)
{ {
if ($line =~ /ALTER ROLE/) if ($line =~ /ALTER ROLE/)
@ -301,29 +303,31 @@ 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 => 3, list => { database_name => $database_name }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { database_name => $database_name }});
my ($database_list, $return_code) = $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__}); undef $return_code;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { database_list => $database_list, return_code => $return_code }}); (my $database_list, $return_code) = $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, return_code => $return_code }});
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 => 3, key => "log_0105", variables => { database => $database_name }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0105", variables => { database => $database_name }});
$create_database = 0; $create_database = 0;
last; last;
} }
} }
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { create_database => $create_database }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { create_database => $create_database }});
if ($create_database) if ($create_database)
{ {
my ($create_output, $return_code) = $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, $return_code) = $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__});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { create_output => $create_output, return_code => $return_code }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { create_output => $create_output, return_code => $return_code }});
undef $return_code;
my $database_exists = 0; my $database_exists = 0;
my ($database_list, $return_code) = $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, $return_code) = $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 => 3, list => { database_list => $database_list, return_code => $return_code }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { database_list => $database_list, return_code => $return_code }});
foreach my $line (split/\n/, $database_list) foreach my $line (split/\n/, $database_list)
{ {
if ($line =~ /^ $database_name$/) if ($line =~ /^ $database_name$/)

Loading…
Cancel
Save