* Updated kickstart to write the basic tools/anvil-update-issue to a freshly installed machine and run it from cron.

* Updated Remote->call() to detect when a connection fails because the target's known_hosts entry has changed. Still need to add the function to report this to the user.
* Fixed a bug where new-lines in Words->parse_banged_string() where a double-banged word string's variable value would cause an infinite loop.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 5 years ago
parent 2ca19699b8
commit 37f36fe99c
  1. 3
      Anvil/Tools.pm
  2. 32
      Anvil/Tools/Remote.pm
  3. 4
      Anvil/Tools/Storage.pm
  4. 8
      Anvil/Tools/System.pm
  5. 58
      Anvil/Tools/Words.pm
  6. 1
      cgi-bin/striker
  7. 94
      html/skins/alteeve/pxe.txt
  8. 3
      share/words.xml
  9. 12
      tools/anvil-daemon
  10. 54
      tools/anvil-update-issue
  11. 13
      tools/striker-get-peer-data
  12. 38
      tools/striker-prep-database

@ -1018,10 +1018,11 @@ sub _set_paths
ssh_config => "/etc/ssh/ssh_config",
},
data => {
'.htpasswd' => "/etc/httpd/.htpasswd",
group => "/etc/group",
issue => "/etc/issue",
httpd_conf => "/etc/httpd/conf/httpd.conf",
host_ssh_key => "/etc/ssh/ssh_host_ecdsa_key.pub",
'.htpasswd' => "/etc/httpd/.htpasswd",
host_uuid => "/etc/anvil/host.uuid",
passwd => "/etc/passwd",
'redhat-release' => "/etc/redhat-release",

@ -432,6 +432,8 @@ sub call
my $connected = 0;
my $message_key = "message_0005";
my $last_loop = 2;
my $bad_file = "";
my $bad_line = "";
foreach (my $i = 0; $i <= $last_loop; $i++)
{
last if $connected;
@ -442,8 +444,8 @@ sub call
batch_mode => 1,
);
};
$connect_output =~ s/\r//gs;
$connect_output =~ s/\n$//;
$connect_output =~ s/\r$//;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
's1:i' => $i,
's2:target' => $target,
@ -466,6 +468,28 @@ sub call
$message_key = "message_0003";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { i => $i, message_key => $message_key }});
}
elsif ($connect_output =~ /IDENTIFICATION HAS CHANGED/i)
{
# Host's ID has changed, rebuilt? Find the line and file to tell the user.
foreach my $line (split/\n/, $connect_output)
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { line => $line }});
if ($line =~ /Offending .*? key in (\/.*?known_hosts):(\d+)$/)
{
$bad_file = $1;
$bad_line = $2;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
bad_file => $bad_file,
bad_line => $bad_line,
}});
}
}
$message_key = "message_0149";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { i => $i, message_key => $message_key }});
# TODO: Store this in the states table and have a function that makes
# removing the offending line from the WebUI.
}
elsif ($connect_output =~ /Host key verification failed/i)
{
# Need to accept the fingerprint
@ -549,6 +573,8 @@ sub call
target => $target.":".$port,
error => $ssh_fh->error,
connection => $ssh_fh_key,
file => $bad_file,
line => $bad_line,
};
if (not $connected)
{
@ -600,8 +626,8 @@ sub call
}
# Take the last new line off.
$output =~ s/\n$//; $output =~ s/\r$//;
$error =~ s/\n$//; $error =~ s/\r$//;
$output =~ s/\n$//; $output =~ s/\r//g;
$error =~ s/\n$//; $error =~ s/\r//g;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => $secure, list => {
error => $error,
output => $output,

@ -2928,8 +2928,8 @@ fi";
# Now write the file.
my $shell_call = $file;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, secure => 0, key => "log_0013", variables => { shell_call => $shell_call }});
#open (my $file_handle, ">", $shell_call) or $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, secure => $secure, priority => "err", key => "log_0016", variables => { shell_call => $shell_call, error => $! }});
open (my $file_handle, ">", $shell_call) or die "Failed to write: [$shell_call], error was: [".$!."]\n";;
open (my $file_handle, ">", $shell_call) or $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, secure => $secure, priority => "err", key => "log_0016", variables => { shell_call => $shell_call, error => $! }});
#open (my $file_handle, ">", $shell_call) or die "Failed to write: [$shell_call], error was: [".$!."]\n";;
print $file_handle $body;
close $file_handle;

@ -1298,11 +1298,11 @@ sub is_local
else
{
# Get the list of current IPs and see if they match.
my $network = $anvil->Network->get_network_details;
foreach my $interface (keys %{$network->{interface}})
$anvil->Network->get_ips;
foreach my $interface (sort {$a cmp $b} keys %{$anvil->data->{network}{'local'}{interface}})
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "network->interface::${interface}::ip" => $network->{interface}{$interface}{ip} }});
if ($host eq $network->{interface}{$interface}{ip})
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "network::local::interface::${interface}::ip" => $anvil->data->{network}{'local'}{interface}{$interface}{ip} }});
if ($host eq $anvil->data->{network}{'local'}{interface}{$interface}{ip})
{
$is_local = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { is_local => $is_local }});

@ -278,9 +278,57 @@ sub parse_banged_string
my $key_string = defined $parameter->{key_string} ? $parameter->{key_string} : 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { key_string => $key_string }});
# If the string ended with newline before the final '!!', it will break things.
$key_string =~ s/\n!!/!!/gs;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { key_string => $key_string }});
# Some variable values will be multi-line strings. We need to replace the new-lines in those
# multi-line values into '##br##' so that we can do a proper variable insertion. We can't simply
# replace all new-lines, however, as it's normal to have multiple keys, each on their own line.
if ($key_string =~ /\n/gs)
{
my $in_value = 0;
my $new_string = "";
foreach my $line (split/\n/, $key_string)
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { line => $line }});
if (($line =~ /^\w.*?,!!/) && ($line !~ /!!$/))
{
$in_value = 1;
$new_string .= $line."##br##";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
in_value => $in_value,
new_string => $new_string,
}});
}
elsif ($in_value)
{
if ($line =~ /!!$/)
{
$in_value = 0;
$new_string .= $line."\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
in_value => $in_value,
new_string => $new_string,
}});
}
else
{
$new_string .= $line."##br##";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
in_value => $in_value,
new_string => $new_string,
}});
}
}
else
{
$new_string .= $line."\n";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
in_value => $in_value,
new_string => $new_string,
}});
}
}
$new_string =~ s/\n$//;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { new_string => $new_string }});
}
# There might be multiple keys, split by newlines.
foreach my $message (split/\n/, $key_string)
@ -353,7 +401,9 @@ sub parse_banged_string
}
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { out_string => $out_string }});
# Switch the breaks back to new-lines
$out_string =~ s/##br##/\n/gs;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { key_string => $key_string }});
return($out_string);
}

@ -664,6 +664,7 @@ sub process_prep_host_page
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { rh_template => $rh_template }});
}
### NOTE: Left off here. Need to pick up the message from a bad/changed fingerprint when it's the cause of a failed login. Create a button to remove the bad key.
if (not $connected)
{
$anvil->data->{form}{error_massage} = $anvil->Template->get({file => "main.html", name => "error_message", variables => { error_message => $anvil->Words->string({key => "striker_warning_0012"}) }});

@ -73,7 +73,7 @@ selinux --permissive
%packages
@^minimal-environment
alteeve-el8-repo
perl
perl-interpreter
rsync
vim
@ -106,6 +106,98 @@ rsync -av /tmp /mnt/sysimage/root/install_logs/
rsync -av /run/install /mnt/sysimage/root/install_logs/run/
rsync -av /var/log /mnt/sysimage/root/install_logs/var/
echo 'Writing out the initial /etc/issue script.'
reset
cat << EOF > /mnt/sysimage/usr/sbin/anvil-update-issue
#!/usr/bin/perl
#
# This parses the current IP addresses on the local system and writes them to /etc/issue so that they're seen
# by a user at the login prompt. This is meant to be useful during the initialization and setup stages, so
# it's expected to run before the Anvil::Tools module is installed. As such, it doesn't use those modules.
#
use strict;
use warnings;
use IO::Handle;
# Turn off buffering so that the pinwheel will display while waiting for the SSH call(s) to complete.
\$| = 1;
my \$THIS_FILE = (\$0 =~ /^.*\/(.*)\$/)[0];
my \$running_directory = (\$0 =~ /^(.*?)\/\$THIS_FILE\$/)[0];
if ((\$running_directory =~ /^\./) && (\$ENV{PWD}))
{
\$running_directory =~ s/^\./\$ENV{PWD}/;
}
my \$shell_call = "/usr/sbin/ip addr list";
my \$new_issue = '\S
Kernel \r on an \m
';
my \$ips = {};
my \$interface = "";
open (my \$file_handle, \$shell_call." 2>&1 |") or die "Failed to call: [".\$shell_call."], error was: [".\$!."]\n";
while(<\$file_handle>)
{
chomp;
my \$line = \$_;
\$line =~ s/\n\$//;
\$line =~ s/\r\$//;
if (\$line =~ /^\d+: (.*?): </)
{
\$interface = \$1;
}
next if not \$interface;
next if \$interface eq "lo";
if (\$line =~ / inet (\d+\.\d+\.\d+\.\d+\/\d+) /)
{
my \$ip = \$1;
\$ips->{\$interface} = \$ip;
}
}
close \$file_handle;
if (keys %{\$ips})
{
\$new_issue .= "\nActive IPs:\n";
foreach my \$interface (sort {\$a cmp \$b} keys %{\$ips})
{
\$new_issue .= "- ".\$interface.": ".\$ips->{\$interface}."\n";
}
\$new_issue .= "\n";
}
# Read in the current issue file and see if there is any difference.
my \$old_issue = "";
my \$issue_file = "/etc/issue";
open (\$file_handle, "<", \$issue_file) or die "Failed to read: [".\$issue_file."], error was: [".\$!."]\n";
while(<\$file_handle>)
{
### NOTE: Don't chop this, we want to record exactly what we read
\$old_issue .= \$_;
}
close \$file_handle;
my \$update = \$new_issue eq \$old_issue ? 0 : 1;
if (\$update)
{
open (my \$file_handle, ">", \$issue_file) or die "Failed to write: [".\$issue_file."], the error was: [".\$!."]\n";
print \$file_handle \$new_issue;
close \$file_handle;
}
exit(0);
EOF
chmod 755 /mnt/sysimage/usr/sbin/anvil-update-issue
# Add this to crontab.
cat << EOF > /mnt/sysimage/var/spool/cron/root
MAILTO=""
* * * * * /usr/sbin/anvil-update-issue >> /var/log/anvil.cron 2>&1
EOF
chown 0:0 /mnt/sysimage/var/spool/cron/root
chmod 0600 /mnt/sysimage/var/spool/cron/root
%end

@ -253,6 +253,7 @@ About to try to download aproximately: [#!variable!packages!#] packages needed t
<key name="message_0146">What kind of machine will this host be?</key>
<key name="message_0147"><![CDATA[What is the host's <b>current</b> IP address and password?]]></key>
<key name="message_0148"><![CDATA[This is a RHEL host and has not yet been subscribed.<br />You can enter your Red Hat subscription credentials below.<br />The host will be subscribed during setup.]]></key>
<key name="message_0149">The target's host key has changed. If the target has been rebuilt, or the target IP reused, the old key will need to be removed. If this is the case, remove line: [#!variable!line!#] from: [#!variable!file!#].</key>
<!-- Log entries -->
<key name="log_0001">Starting: [#!variable!program!#].</key>
@ -972,7 +973,7 @@ Here we will inject 't_0006', which injects 't_0001' which has a variable: [#!st
<key name="job_0024">Connected!</key>
<key name="job_0025">Unable to connect to: [#!variable!target!#]. Will keep trying for another: [#!variable!timeout!#] seconds...</key>
<key name="job_0026">Unable to connect, the job has failed.</key>
<key name="job_0027">'Initialize host' job: [#!variable!switches::job-uuid!#] picked up.</key>
<key name="job_0027">'Initialize host' job: [#!variable!job-uuid!#] picked up.</key>
<key name="job_0028">Adding repositories.</key>
<key name="job_0029">Added the repository for this dashboard.</key>
<key name="job_0030">Red Hat subscription information provides, attempting to register now.</key>

@ -65,14 +65,14 @@ $| = 1;
# NOTE: Setting 'log_level' and 'log_secure' here will get overridden in the main lopp. Use the Log methods
# in the loop as well to override defaults in code.
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 }});
# Connect to the database(s). If we have no connections, we'll proceed anyway as one of the 'run_once' tasks
# is to setup the database server.
$anvil->Database->connect({debug => 3, check_if_configured => 1});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132"});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0132"});
# If I have no databases, sleep for a second and then exit (systemd will restart us).
if (not $anvil->data->{sys}{database}{connections})
@ -138,7 +138,7 @@ $anvil->Storage->record_md5sums;
# Disconnect. We'll reconnect inside the loop
$anvil->Database->disconnect();
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0203"});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0203"});
# This will prevent restarting while jobs are running.
$anvil->data->{sys}{jobs_running} = 0;
@ -152,7 +152,7 @@ $anvil->data->{timing}{minute_checks} = 60;
$anvil->data->{timing}{repo_update_interval} = 86400;
$anvil->data->{timing}{next_minute_check} = $now_time - 1;
$anvil->data->{timing}{next_repo_check} = $now_time; # We want to run on daemon startup
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
"s1:timing::minute_checks" => $anvil->data->{timing}{minute_checks},
"s2:timing::repo_update_interval" => $anvil->data->{timing}{repo_update_interval},
"s3:now_time" => $now_time,
@ -1033,11 +1033,11 @@ sub prep_database
# Only run this if we're a dashboard.
my $host_type = $anvil->System->get_host_type();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { host_type => $host_type }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { host_type => $host_type }});
if ($host_type eq "dashboard")
{
my ($database_output, $return_code) = $anvil->System->call({
debug => 2,
debug => 3,
shell_call => $anvil->data->{path}{exe}{'striker-prep-database'},
source => $THIS_FILE,
line => __LINE__,

@ -9,12 +9,23 @@ use strict;
use warnings;
use IO::Handle;
my $shell_call = "/usr/sbin/ip ip list all";
my $issue = '\S
# Turn off buffering so that the pinwheel will display while waiting for the SSH call(s) to complete.
$| = 1;
my $THIS_FILE = ($0 =~ /^.*\/(.*)$/)[0];
my $running_directory = ($0 =~ /^(.*?)\/$THIS_FILE$/)[0];
if (($running_directory =~ /^\./) && ($ENV{PWD}))
{
$running_directory =~ s/^\./$ENV{PWD}/;
}
my $shell_call = "/usr/sbin/ip addr list";
my $new_issue = '\S
Kernel \r on an \m
';
my $ips = {};
my $interface = "";
open (my $file_handle, $shell_call.$redirect."; ".$anvil->data->{path}{exe}{echo}." return_code:\$? |") or $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, secure => $secure, priority => "err", key => "log_0014", variables => { shell_call => $shell_call, error => $! }});
open (my $file_handle, $shell_call." 2>&1 |") or die "Failed to call: [".$shell_call."], error was: [".$!."]\n";
while(<$file_handle>)
{
chomp;
@ -23,18 +34,45 @@ while(<$file_handle>)
$line =~ s/\r$//;
if ($line =~ /^\d+: (.*?): </)
{
$interface = $1
print "In interface: [".$interface."]\n";
$interface = $1;
}
next if not $interface;
if ($line =~ / inet (\d+\.\d+\.\d+\.\d+)\//)
next if $interface eq "lo";
if ($line =~ / inet (\d+\.\d+\.\d+\.\d+\/\d+) /)
{
my $ip = $1;
print "- IP: [".$ip."]\n";
$ips->{$interface} = $ip;
}
}
close $file_handle;
if (keys %{$ips})
{
$new_issue .= "\nActive IPs:\n";
foreach my $interface (sort {$a cmp $b} keys %{$ips})
{
$new_issue .= "- ".$interface.": ".$ips->{$interface}."\n";
}
$new_issue .= "\n";
}
exit(0);
# Read in the current issue file and see if there is any difference.
my $old_issue = "";
my $issue_file = "/etc/issue";
open ($file_handle, "<", $issue_file) or die "Failed to read: [".$issue_file."], error was: [".$!."]\n";
while(<$file_handle>)
{
### NOTE: Don't chop this, we want to record exactly what we read
$old_issue .= $_;
}
close $file_handle;
my $update = $new_issue eq $old_issue ? 0 : 1;
if ($update)
{
open (my $file_handle, ">", $issue_file) or die "Failed to write: [".$issue_file."], the error was: [".$!."]\n";
print $file_handle $new_issue;
close $file_handle;
}
exit(0);

@ -31,13 +31,16 @@ $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 }});
# Read switches (target ([user@]host[:port]) and the file with the target's password.
# Read switches (target ([user@]host[:port]) and the file with the target's password. If the password is
# passed directly, it will be used. Otherwise, the password will be read from the database.
$anvil->data->{switches}{target} = "";
$anvil->data->{switches}{'state-uuid'} = "";
$anvil->data->{switches}{password} = "";
$anvil->Get->switches;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
'switches::target' => $anvil->data->{switches}{target},
'switches::state-uuid' => $anvil->data->{switches}{'state-uuid'},
'switches::password' => $anvil->Log->is_secure($anvil->data->{switches}{password}),
}});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0435", variables => {
@ -210,11 +213,13 @@ sub get_host_uuid
# This is the first thing called, so start by verifying we can talk to the target at all.
my $access = $anvil->Remote->test_access({
debug => 2,
user => $anvil->data->{target}{user},
target => $anvil->data->{target}{host},
port => $anvil->data->{target}{port},
password => $anvil->data->{target}{password},
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { access => $access }});
if (not $access)
{
@ -297,6 +302,12 @@ sub get_password
{
my ($anvil) = @_;
# If we were given the password directly, use it.
if ($anvil->data->{switches}{password})
{
return($anvil->data->{switches}{password});
}
# We'll pick up the peer's password from the database.
$anvil->Database->connect();
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0132"});

@ -29,10 +29,10 @@ $| = 1;
my $anvil = Anvil::Tools->new();
$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 }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }});
my $local_uuid = $anvil->Database->get_local_uuid();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { local_uuid => $local_uuid }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, 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 (not $local_uuid)
@ -45,10 +45,10 @@ if (not $local_uuid)
if ($local_uuid)
{
# Start checks
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "sys::service::postgresql" => $anvil->data->{sys}{daemon}{postgresql} }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "sys::service::postgresql" => $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 => 2, list => { running => $running }});
my $running = $anvil->System->check_daemon({debug => 3, daemon => $anvil->data->{sys}{daemon}{postgresql}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { running => $running }});
if ($running eq "2")
{
# Not installed.
@ -187,7 +187,7 @@ if ($local_uuid)
}
# Start the daemon. '0' = started, anything else is a problem.
my $return_code = $anvil->System->start_daemon({debug => 2, daemon => $anvil->data->{sys}{daemon}{postgresql}});
my $return_code = $anvil->System->start_daemon({debug => 3, daemon => $anvil->data->{sys}{daemon}{postgresql}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { return_code => $return_code }});
if ($return_code eq "0")
{
@ -195,7 +195,7 @@ if ($local_uuid)
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0059"});
# Make sure it is enabled on boot.
my $return_code = $anvil->System->enable_daemon({debug => 2, daemon => $anvil->data->{sys}{daemon}{postgresql}});
my $return_code = $anvil->System->enable_daemon({debug => 3, daemon => $anvil->data->{sys}{daemon}{postgresql}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { return_code => $return_code }});
}
else
@ -208,7 +208,7 @@ if ($local_uuid)
# Create the .pgpass file, if needed.
my $created_pgpass = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, secure => 1, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, secure => 1, list => {
'path::secure::postgres_pgpass' => $anvil->data->{path}{secure}{postgres_pgpass},
"database::${local_uuid}::password" => $anvil->data->{database}{$local_uuid}{password},
}});
@ -235,7 +235,7 @@ if ($local_uuid)
# Does the database user exist?
my $create_user = 1;
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 => 2, list => { database_user => $database_user }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { database_user => $database_user }});
if (not $database_user)
{
# No database user defined
@ -243,24 +243,24 @@ if ($local_uuid)
$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__});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { user_list => $user_list, return_code => $return_code }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { user_list => $user_list, return_code => $return_code }});
foreach my $line (split/\n/, $user_list)
{
if ($line =~ /^ $database_user\s+\|\s+(\d+)/)
{
# User exists already
my $id = $1;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0060", variables => { user => $database_user, id => $id }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0060", variables => { user => $database_user, id => $id }});
$create_user = 0;
last;
}
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { create_user => $create_user }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { create_user => $create_user }});
if ($create_user)
{
# Create the user
my ($create_output, $return_code) = $anvil->System->call({debug => 2, shell_call => $anvil->data->{path}{exe}{su}." - postgres -c \"".$anvil->data->{path}{exe}{createuser}." --no-superuser --createdb --no-createrole $database_user\"", source => $THIS_FILE, line => __LINE__});
(my $user_list, $return_code) = $anvil->System->call({debug => 2, 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 ($create_output, $return_code) = $anvil->System->call({debug => 3, shell_call => $anvil->data->{path}{exe}{su}." - postgres -c \"".$anvil->data->{path}{exe}{createuser}." --no-superuser --createdb --no-createrole $database_user\"", source => $THIS_FILE, line => __LINE__});
(my $user_list, $return_code) = $anvil->System->call({debug => 3, 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_exists = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { create_output => $create_output, user_list => $user_list }});
foreach my $line (split/\n/, $user_list)
@ -303,22 +303,22 @@ if ($local_uuid)
# Create the database, if needed.
my $create_database = 1;
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 => 2, list => { database_name => $database_name }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { database_name => $database_name }});
undef $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 }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { database_list => $database_list, return_code => $return_code }});
foreach my $line (split/\n/, $database_list)
{
if ($line =~ /^ $database_name$/)
{
# Database already exists.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0105", variables => { database => $database_name }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0105", variables => { database => $database_name }});
$create_database = 0;
last;
}
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { create_database => $create_database }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { create_database => $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__});
@ -399,7 +399,7 @@ RateLimitBurst=0
});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "message_0012", variables => { file => $anvil->data->{path}{configs}{'journald_anvil'} }});
my ($output, $return_code) = $anvil->System->call({debug => 2, shell_call => $anvil->data->{path}{exe}{systemctl}." restart systemd-journald.service", source => $THIS_FILE, line => __LINE__});
my ($output, $return_code) = $anvil->System->call({debug => 3, shell_call => $anvil->data->{path}{exe}{systemctl}." restart systemd-journald.service", source => $THIS_FILE, line => __LINE__});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { output => $output, return_code => $return_code }});
}
}

Loading…
Cancel
Save