* Started work on tools/anvil-manage-striker-peers to do the actual work on managing local and peer databases in anvil.conf.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 6 years ago
parent 0fa3c42f2f
commit 89c06b9f24
  1. 8
      cgi-bin/striker
  2. 3
      rpm/SPECS/anvil.spec
  3. 2
      share/words.xml
  4. 156
      tools/anvil-manage-striker-peers
  5. 18
      tools/anvil-prep-database

@ -51,10 +51,7 @@ if (not -e $anvil->data->{path}{data}{host_uuid})
print_and_exit($anvil); print_and_exit($anvil);
} }
$anvil->Database->connect({ $anvil->Database->connect();
sql_file => $anvil->data->{sys}{database}{schema},
test_table => "network_interfaces",
});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132", variables => { "sys::db_connections" => $anvil->data->{sys}{db_connections} }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132", variables => { "sys::db_connections" => $anvil->data->{sys}{db_connections} }});
if (not $anvil->data->{sys}{db_connections}) if (not $anvil->data->{sys}{db_connections})
{ {
@ -572,8 +569,7 @@ sub add_sync_peer
# Things look good. Is the save confirmed? # Things look good. Is the save confirmed?
if ($anvil->data->{cgi}{confirm}{value}) if ($anvil->data->{cgi}{confirm}{value})
{ {
# OK, save! # OK, save the job!
} }
else else
{ {

@ -379,6 +379,9 @@ systemctl stop postgresql.service
%changelog %changelog
* Thu Aug 02 2018 Madison Kelly <mkelly@alteeve.ca> 3.0-12
- Added perl-Proc-Simple to core dependencies.
* Tue Jul 24 2018 Madison Kelly <mkelly@alteeve.ca> 3.0-11 * Tue Jul 24 2018 Madison Kelly <mkelly@alteeve.ca> 3.0-11
- Added a check to enable the graphical target on boot. - Added a check to enable the graphical target on boot.
- Updated anvil-striker dependency list to pull in gnome. - Updated anvil-striker dependency list to pull in gnome.

@ -454,6 +454,8 @@ Here we will inject 't_0006', which injects 't_0001' which has a variable: [#!st
<key name="error_0028"><![CDATA[There appears to be a problem with Striker. The login failed, please check: [<span class="code">#!data!sys::log_file!#</span>] for details.]]></key> <key name="error_0028"><![CDATA[There appears to be a problem with Striker. The login failed, please check: [<span class="code">#!data!sys::log_file!#</span>] for details.]]></key>
<key name="error_0029"><![CDATA[Failed to find the template: [<span class="code">#!variable!template!#</span>] in the template file: [<span class="code">#!variable!file!#</span>].]]></key> <key name="error_0029"><![CDATA[Failed to find the template: [<span class="code">#!variable!template!#</span>] in the template file: [<span class="code">#!variable!file!#</span>].]]></key>
<key name="error_0030"><![CDATA[Failed to process the template: [<span class="code">#!variable!template!#</span>] in the template file: [<span class="code">#!variable!file!#</span>]. Details of the problem should be in: [<span class="code">#!data!sys::log_file!#</span>].]]></key> <key name="error_0030"><![CDATA[Failed to process the template: [<span class="code">#!variable!template!#</span>] in the template file: [<span class="code">#!variable!file!#</span>]. Details of the problem should be in: [<span class="code">#!data!sys::log_file!#</span>].]]></key>
<key name="error_0031">The 'host-uuid': [#!variable!host_uuid!#] is not valid.</key>
<key name="error_0032">The '#!variable!switch!#' switch is missing.</key>
<!-- These are units, words and so on used when displaying information. --> <!-- These are units, words and so on used when displaying information. -->
<key name="unit_0001">Yes</key> <key name="unit_0001">Yes</key>

@ -0,0 +1,156 @@
#!/usr/bin/perl
#
# This program adds, edits and removes striker peers (for replicating Anvil! database data).
#
# Exit codes;
# 0 = Normal exit.
# 1 = Program not run as root.
# 2 = A switch is missing or invalid.
# 3 =
#
use strict;
use warnings;
use Anvil::Tools;
my $THIS_FILE = ($0 =~ /^.*\/(.*)$/)[0];
my $running_directory = ($0 =~ /^(.*?)\/$THIS_FILE$/)[0];
if (($running_directory =~ /^\./) && ($ENV{PWD}))
{
$running_directory =~ s/^\./$ENV{PWD}/;
}
# Turn off buffering so that the pinwheel will display while waiting for the SSH call(s) to complete.
$| = 1;
my $anvil = Anvil::Tools->new({log_level => 2, log_secure => 1});
# Read switches
$anvil->Get->switches;
# Make sure we're running as 'root'
# $< == real UID, $> == effective UID
if (($< != 0) && ($> != 0))
{
# Not root
print $anvil->Words->string({key => "error_0005"})."\n";
$anvil->nice_exit({code => 1});
}
# Paths
$anvil->Storage->read_config({file => $anvil->data->{path}{configs}{'anvil.conf'}});
# Read in the anvil.conf, we're going to need it in any case.
$anvil->data->{body}{'anvil.conf'} = $anvil->Storage->read_file({file => $anvil->data->{path}{configs}{'anvil.conf'}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, secure => 1, level => 2, list => { anvil_conf_body => $anvil_conf_body }});
# Am I adding, editing or deleting?
if ($anvil->data->{switches}{add})
{
# Add a new entry.
add_entry($anvil);
}
elsif ($anvil->data->{switches}{remove})
{
}
elsif ($anvil->data->{switches}{modify})
{
}
else
{
# Bad call.
}
$anvil->nice_exit({code => 0});
#############################################################################################################
# Functions #
#############################################################################################################
sub add_entry
{
my ($anvil) = @_;
my $host_uuid = defined $anvil->data->{switches}{'host-uuid'} ? $anvil->data->{switches}{'host-uuid'} : "";
my $host = defined $anvil->data->{switches}{'host'} ? $anvil->data->{switches}{'host'} : "";
my $port = defined $anvil->data->{switches}{'port'} ? $anvil->data->{switches}{'port'} : 5432;
my $password_file = defined $anvil->data->{switches}{'password-file'} ? $anvil->data->{switches}{'password-file'} : "";
my $ping = defined $anvil->data->{switches}{'ping'} ? $anvil->data->{switches}{'ping'} : 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, secure => 0, level => 2, list => {
host_uuid => $host_uuid,
host => $host,
port => $port,
password_file => $password_file,
ping => $ping,
}});
# Is anything missing?
if ((not $host_uuid) or (not $anvil->Validate->is_uuid({uuid => $host_uuid})))
{
# Invalid UUID.
print $anvil->Words->string({key => "error_0031", variables => { host_uuid => $host_uuid }})."\n";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "error_0031", variables => { host_uuid => $host_uuid }});
$anvil->nice_exit({code => 2});
}
if (not $host)
{
# Invalid UUID.
print $anvil->Words->string({key => "error_0032", variables => { switch => "host" }})."\n";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "error_0032", variables => { host_uuid => $host_uuid }});
$anvil->nice_exit({code => 2});
}
if (($port =~ /\D/) or ($port < 1) or ($port > 65535))
{
# Invalid port.
print $anvil->Words->string({key => "error_0033", variables => { port => $port }})."\n";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "error_0033", variables => { port => $port }});
$anvil->nice_exit({code => 2});
}
# Pull the password out of the file.
my $password = $anvil->Storage->read_file({file => $password_file});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, secure => 1, level => 2, list => { password => $password }});
# If we don't find the entry, or if the entry exists but has changed, this will be set to '1' so
# we'll rewrite the file.
my $write = 0;
# If the config already exists, we'll look at each of the values to see if any changed (or are not defaults). If so, we'll rewrite
my $host_variable = "database::${host_uuid}::host";
my $host_different = 1;
my $port_variable = "database::${host_uuid}::port";
my $port_different = 1;
my $password_variable = "database::${host_uuid}::password";
my $password_different = 1;
my $ping_variable = "database::${host_uuid}::ping";
my $ping_different = 1;
# Loop through the existing file.
my $new_body = "";
my $test_line = "database::${host_uuid}::";
foreach my $line (split/\n/, $anvil->data->{body}{'anvil.conf'})
{
my $secure = (($line =~ /password/) && ($line !~ /^#/)) ? 1 : 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, secure => $secure, level => 2, list => { line => $line }});
if ($line =~ /^$host_variable(\s*)=(\s*)(.*)$/)
{
my $left_space = $1;
my $right_space = $2;
my $variable = $3;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
config_seen => $config_seen,
local_uuid => $local_uuid,
}});
}
if ($line eq "### end db list ###")
{
$new_body .= $insert;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, secure => 1, level => 2, list => { new_body => $new_body }});
}
$new_body .= $line."\n";
}
return(0);
}

@ -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 => 0}); my $anvil = Anvil::Tools->new({log_level => 2, log_secure => 0});
# Read switches # Read switches
$anvil->Get->switches; $anvil->Get->switches;
@ -429,6 +429,18 @@ sub add_to_local_config
{ {
my ($anvil) = @_; my ($anvil) = @_;
# Write the password to a file.
my $password_file = "/tmp/anvil-manage-striker-peers.".$anvil->Get->uuid;
$anvil->Storage->write_file({
secure => 1,
debug => 2,
file => $password_file,
body => "Initial1",
mode => "0600",
overwrite => 1,
});
my $shell_call = $anvil->{path}{exe}{'anvil-manage-striker-peers'}." --host-uuid ".$anvil->Get->host_uuid." --host localhost --port 5432 --password-file ".$password_file." --ping 0";
my $host_uuid = $anvil->Get->host_uuid(); my $host_uuid = $anvil->Get->host_uuid();
my $local_uuid = ""; my $local_uuid = "";
my $anvil_conf_body = $anvil->Storage->read_file({file => $anvil->data->{path}{configs}{'anvil.conf'}}); my $anvil_conf_body = $anvil->Storage->read_file({file => $anvil->data->{path}{configs}{'anvil.conf'}});
@ -438,10 +450,6 @@ sub add_to_local_config
}}); }});
# Setup the data we'll insert. The password will be changed after the user does the initial config. # Setup the data we'll insert. The password will be changed after the user does the initial config.
$anvil->data->{database}{$host_uuid}{host} = "localhost";
$anvil->data->{database}{$host_uuid}{port} = "5432";
$anvil->data->{database}{$host_uuid}{password} = "Initial1";
$anvil->data->{database}{$host_uuid}{ping} = "0";
my $insert = "database::".$host_uuid."::host = ".$anvil->data->{database}{$host_uuid}{host}."\n"; my $insert = "database::".$host_uuid."::host = ".$anvil->data->{database}{$host_uuid}{host}."\n";
$insert .= "database::".$host_uuid."::port = ".$anvil->data->{database}{$host_uuid}{port}."\n"; $insert .= "database::".$host_uuid."::port = ".$anvil->data->{database}{$host_uuid}{port}."\n";
$insert .= "database::".$host_uuid."::password = ".$anvil->data->{database}{$host_uuid}{password}."\n"; $insert .= "database::".$host_uuid."::password = ".$anvil->data->{database}{$host_uuid}{password}."\n";

Loading…
Cancel
Save