Merge pull request #232 from ClusterLabs/anvil-tools-dev

* Added a missing modified_date to ip_addresses in Database->get_ip_a…
main
Digimer 3 years ago committed by GitHub
commit 6ea8365067
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 872
      Anvil/Tools/Database.pm
  2. 10
      Anvil/Tools/Email.pm
  3. 2
      Anvil/Tools/Network.pm
  4. 2
      Anvil/Tools/ScanCore.pm
  5. 12
      Anvil/Tools/System.pm
  6. 19
      notes
  7. 267
      scancore-agents/scan-network/scan-network
  8. 3
      scancore-agents/scan-network/scan-network.xml
  9. 8
      share/words.xml
  10. 42
      tools/anvil-daemon
  11. 31
      tools/anvil-update-states
  12. 10
      tools/fence_delay
  13. 3
      tools/striker-auto-initialize-all
  14. 6
      tools/striker-manage-install-target
  15. 2
      tools/striker-prep-database
  16. 18
      tools/striker-purge-target

File diff suppressed because it is too large Load Diff

@ -669,7 +669,15 @@ Reply-To: ".$reply_to."
next if $alert_processed;
next if $alert_host_uuid ne $host_uuid;
my $query = "UPDATE alerts SET alert_processed = 1 WHERE alert_uuid = ".$anvil->Database->quote($alert_uuid).";";
my $query = "
UPDATE
alerts
SET
alert_processed = 1,
modified_date = ".$anvil->Database->quote($anvil->Database->refresh_timestamp)."
WHERE
alert_uuid = ".$anvil->Database->quote($alert_uuid)."
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__});
}

@ -1524,7 +1524,7 @@ FROM
WHERE
network_interface_operational != 'DELETED'
AND
network_interface_host_uuid = ".$anvil->Database->quote($host_uuid)."
network_interface_host_uuid = ".$anvil->Database->quote($host_uuid)."
ORDER BY
modified_date DESC
;";

@ -1602,7 +1602,7 @@ sub post_scan_analysis_node
# If we're still here, at least one issue exists. Any kind of load-shed or preventative live
# migration decision now depends on our peer's state. So see if we're both in the cluster or not.
my $problem = $anvil->Cluster->parse_cib({debug => 2});
my $problem = $anvil->Cluster->parse_cib({debug => $debug});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { problem => $problem }});
if (not $problem)
{

@ -5015,7 +5015,15 @@ sub test_ipmi
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, secure => 1, level => $debug, list => { shell_call => $shell_call }});
# Update it.
my $query = "UPDATE hosts SET host_ipmi = ".$anvil->Database->quote($shell_call)." WHERE host_uuid = ".$anvil->Database->quote($anvil->Get->host_uuid).";";
my $query = "
UPDATE
hosts
SET
host_ipmi = ".$anvil->Database->quote($shell_call).",
modified_date = ".$anvil->Database->quote($anvil->Database->refresh_timestamp)."
WHERE
host_uuid = ".$anvil->Database->quote($anvil->Get->host_uuid)."
;";
$anvil->Database->write({debug => $debug, query => $query, source => $THIS_FILE, line => __LINE__});
}
@ -5051,7 +5059,7 @@ sub update_hosts
$anvil->Database->get_ip_addresses({debug => $debug});
# Load the IPs we manage. If we find any entries for these that we don't expect, we'll remove them.
$anvil->Database->get_ip_addresses({debug => $debug});
$anvil->Network->load_ips({debug => $debug});
foreach my $host_uuid (keys %{$anvil->data->{hosts}{host_uuid}})
{

19
notes

@ -206,6 +206,25 @@ su - postgres -c "dropdb anvil" && su - postgres -c "createdb --owner admin anvi
Reload the DB;
su - postgres -c "dropdb anvil" && su - postgres -c "createdb --owner admin anvil" && su - postgres -c "psql anvil < /anvil.out" && su - postgres -c "psql anvil"
### Load client data
## Workstation setup
dnf -y install postgresql postgresql-server postgresql-plperl
postgresql-setup --initdb --unit postgresql
vim /var/lib/pgsql/data/postgresql.conf
# Add around line 60: listen_addresses = '*'
vim /var/lib/pgsql/data/pg_hba.conf
# Add around like 84: host all all all md5
systemctl start postgresql.service
su - postgres -c "createuser --no-superuser --createdb --no-createrole admin"
su - postgres -c "psql template1 -c \"ALTER ROLE postgres WITH PASSWORD 'Initial1';\""
su - postgres -c "psql template1 -c \"ALTER ROLE admin WITH PASSWORD 'Initial1';\""
# If there was a previous DB
su - postgres -c "dropdb client"
# Copy and load
cp /path/to/client_anvil.out /tmp/anvil.out
su - postgres -c "createdb --owner admin client" && su - postgres -c "psql client < /tmp/anvil.out" && su - postgres -c "psql client"
Changes made using tools such as nmcli do not require a reload but do require the associated interface to be put down and then up again. That can be done by using commands in the following format:

@ -103,23 +103,78 @@ sub clear_old_interfaces
# Read in all interfaces and for each, delete historical records over the age-out time.
my $age = $anvil->data->{scancore}{database}{age_out};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { age => $age }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { age => $age }});
if ($age =~ /\D/)
{
# Age is not valid, set it to defaults.
$age = 24;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { age => $age }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { age => $age }});
}
my $query = "SELECT now() - '".$age."h'::interval;";
my $old_timestamp = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__})->[0]->[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
query => $query,
old_timestamp => $old_timestamp,
}});
$query = "
# It is possible that a record exists on one DB, but not the other. Unsure how this happens, but this
# cleans it up.
foreach my $uuid (sort {$a cmp $b} keys %{$anvil->data->{cache}{database_handle}})
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
uuid => $anvil->Database->get_host_from_uuid({short => 1, host_uuid => $uuid})." (".$uuid.")",
}});
my $query = "
SELECT
ip_address_uuid,
ip_address_address
FROM
ip_addresses
WHERE
ip_address_host_uuid = ".$anvil->Database->quote($anvil->Get->host_uuid)."
AND
ip_address_note = 'DELETED'
AND
modified_date < '".$old_timestamp."'
ORDER BY
ip_address_address ASC
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
my $results = $anvil->Database->query({uuid => $uuid, query => $query, source => $THIS_FILE, line => __LINE__});
my $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
results => $results,
count => $count,
}});
foreach my $row (@{$results})
{
my $ip_address_uuid = $row->[0];
my $ip_address_address = $row->[1];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:ip_address_uuid' => $ip_address_uuid,
's2:ip_address_address' => $ip_address_address,
}});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "scan_network_log_0005", variables => {
age => $age,
ip => $ip_address_address,
}});
my $queries = [];
push @{$queries}, "DELETE FROM history.ip_addresses WHERE ip_address_uuid = '".$ip_address_uuid."';";
push @{$queries}, "DELETE FROM ip_addresses WHERE ip_address_uuid = '".$ip_address_uuid."';";
foreach my $query (@{$queries})
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
}
# Write to both DBs.
$anvil->Database->write({query => $queries, source => $THIS_FILE, line => __LINE__});
}
# Remove interfaces
$query = "
SELECT
network_interface_uuid,
network_interface_mac_address,
@ -127,45 +182,144 @@ SELECT
FROM
network_interfaces
WHERE
network_interface_host_uuid = ".$anvil->Database->quote($anvil->Get->host_uuid)."
network_interface_host_uuid = ".$anvil->Database->quote($anvil->Get->host_uuid)."
AND
network_interface_operational = 'DELETED'
AND
modified_date < '".$old_timestamp."'
AND
modified_date < '".$old_timestamp."'
ORDER BY
network_interface_name ASC;
network_interface_name ASC
;";
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
my $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
results => $results,
count => $count,
}});
foreach my $row (@{$results})
{
my $network_interface_uuid = $row->[0];
my $network_interface_mac_address = $row->[1];
my $network_interface_name = $row->[2];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
$results = $anvil->Database->query({uuid => $uuid, query => $query, source => $THIS_FILE, line => __LINE__});
$count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:network_interface_uuid' => $network_interface_uuid,
's2:network_interface_mac_address' => $network_interface_mac_address,
's3:network_interface_name' => $network_interface_name,
results => $results,
count => $count,
}});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "scan_network_log_0002", variables => {
age => $age,
mac => $network_interface_mac_address,
name => $network_interface_name,
foreach my $row (@{$results})
{
my $network_interface_uuid = $row->[0];
my $network_interface_mac_address = $row->[1];
my $network_interface_name = $row->[2];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:network_interface_uuid' => $network_interface_uuid,
's2:network_interface_mac_address' => $network_interface_mac_address,
's3:network_interface_name' => $network_interface_name,
}});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "scan_network_log_0002", variables => {
age => $age,
mac => $network_interface_mac_address,
name => $network_interface_name,
}});
my $queries = [];
push @{$queries}, "DELETE FROM history.network_interfaces WHERE network_interface_uuid = '".$network_interface_uuid."';";
push @{$queries}, "DELETE FROM network_interfaces WHERE network_interface_uuid = '".$network_interface_uuid."';";
foreach my $query (@{$queries})
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
}
# Write to both DBs.
$anvil->Database->write({query => $queries, source => $THIS_FILE, line => __LINE__});
}
# Delete old bonds
$query = "
SELECT
bond_uuid,
bond_name
FROM
bonds
WHERE
bond_host_uuid = ".$anvil->Database->quote($anvil->Get->host_uuid)."
AND
bond_mode = 'DELETED'
AND
modified_date < '".$old_timestamp."'
ORDER BY
bond_name ASC
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
$results = $anvil->Database->query({uuid => $uuid, query => $query, source => $THIS_FILE, line => __LINE__});
$count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
results => $results,
count => $count,
}});
foreach my $row (@{$results})
{
my $bond_uuid = $row->[0];
my $bond_name = $row->[1];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:bond_uuid' => $bond_uuid,
's2:bond_name' => $bond_name,
}});
my $queries = [];
push @{$queries}, "DELETE FROM history.network_interfaces WHERE network_interface_uuid = '".$network_interface_uuid."';";
push @{$queries}, "DELETE FROM network_interfaces WHERE network_interface_uuid = '".$network_interface_uuid."';";
foreach my $query (@{$queries})
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "scan_network_log_0003", variables => {
age => $age,
name => $bond_name,
}});
my $queries = [];
push @{$queries}, "DELETE FROM history.bonds WHERE bond_uuid = '".$bond_uuid."';";
push @{$queries}, "DELETE FROM bonds WHERE bond_uuid = '".$bond_uuid."';";
foreach my $query (@{$queries})
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
}
# Write to both DBs.
$anvil->Database->write({query => $queries, source => $THIS_FILE, line => __LINE__});
}
# Delete old bridges
$query = "
SELECT
bridge_uuid,
bridge_name
FROM
bridges
WHERE
bridge_host_uuid = ".$anvil->Database->quote($anvil->Get->host_uuid)."
AND
bridge_id = 'DELETED'
AND
modified_date < '".$old_timestamp."'
ORDER BY
bridge_name ASC
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
$results = $anvil->Database->query({uuid => $uuid, query => $query, source => $THIS_FILE, line => __LINE__});
$count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
results => $results,
count => $count,
}});
foreach my $row (@{$results})
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
my $bridge_uuid = $row->[0];
my $bridge_name = $row->[1];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:bridge_uuid' => $bridge_uuid,
's2:bridge_name' => $bridge_name,
}});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "scan_network_log_0004", variables => {
age => $age,
name => $bridge_name,
}});
my $queries = [];
push @{$queries}, "DELETE FROM history.bridges WHERE bridge_uuid = '".$bridge_uuid."';";
push @{$queries}, "DELETE FROM bridges WHERE bridge_uuid = '".$bridge_uuid."';";
foreach my $query (@{$queries})
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
}
# Write to both DBs.
$anvil->Database->write({query => $queries, source => $THIS_FILE, line => __LINE__});
}
$anvil->Database->write({query => $queries, source => $THIS_FILE, line => __LINE__});
}
return(0);
@ -1274,7 +1428,8 @@ FROM
WHERE
network_interface_host_uuid = ".$anvil->Database->quote($anvil->Get->host_uuid)."
ORDER BY
network_interface_name ASC;";
network_interface_name ASC
;";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0124", variables => { query => $query }});
$results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
$count = @{$results};
@ -1353,9 +1508,14 @@ ORDER BY
uuid => $network_interface_uuid,
}});
my $query = "DELETE FROM network_interfaces WHERE network_interface_uuid = ".$anvil->Database->quote($network_interface_uuid).";";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
$anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__});
my $queries = [];
push @{$queries}, "DELETE FROM history.network_interfaces WHERE network_interface_uuid = ".$anvil->Database->quote($network_interface_uuid).";";
push @{$queries}, "DELETE FROM network_interfaces WHERE network_interface_uuid = ".$anvil->Database->quote($network_interface_uuid).";";
foreach my $query (@{$queries})
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
}
$anvil->Database->write({query => $queries, source => $THIS_FILE, line => __LINE__});
$count--;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { count => $count }});
@ -1372,9 +1532,14 @@ ORDER BY
uuid => $network_interface_uuid,
}});
my $query = "DELETE FROM network_interfaces WHERE network_interface_uuid = ".$anvil->Database->quote($network_interface_uuid).";";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
$anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__});
my $queries = [];
push @{$queries}, "DELETE FROM history.network_interfaces WHERE network_interface_uuid = ".$anvil->Database->quote($network_interface_uuid).";";
push @{$queries}, "DELETE FROM network_interfaces WHERE network_interface_uuid = ".$anvil->Database->quote($network_interface_uuid).";";
foreach my $query (@{$queries})
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
}
$anvil->Database->write({query => $queries, source => $THIS_FILE, line => __LINE__});
$count--;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { count => $count }});
@ -1456,9 +1621,14 @@ ORDER BY
uuid => $ip_address_uuid,
}});
my $query = "DELETE FROM ip_addresses WHERE ip_address_uuid = ".$anvil->Database->quote($ip_address_uuid).";";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
$anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__});
my $queries = [];
push @{$queries}, "DELETE FROM history.ip_addresses WHERE ip_address_uuid = ".$anvil->Database->quote($ip_address_uuid).";";
push @{$queries}, "DELETE FROM ip_addresses WHERE ip_address_uuid = ".$anvil->Database->quote($ip_address_uuid).";";
foreach my $query (@{$queries})
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
}
$anvil->Database->write({query => $queries, source => $THIS_FILE, line => __LINE__});
$count--;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { count => $count }});
@ -1476,9 +1646,14 @@ ORDER BY
uuid => $ip_address_uuid,
}});
my $query = "DELETE FROM ip_addresses WHERE ip_address_uuid = ".$anvil->Database->quote($ip_address_uuid).";";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
$anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__});
my $queries = [];
push @{$queries}, "DELETE FROM history.ip_addresses WHERE ip_address_uuid = ".$anvil->Database->quote($ip_address_uuid).";";
push @{$queries}, "DELETE FROM ip_addresses WHERE ip_address_uuid = ".$anvil->Database->quote($ip_address_uuid).";";
foreach my $query (@{$queries})
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
}
$anvil->Database->write({query => $queries, source => $THIS_FILE, line => __LINE__});
$count--;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { count => $count }});

@ -216,5 +216,8 @@ This mode is NOT supported by the Anvil! Intelligent Availability™ platform!
<key name="scan_network_log_0001">Aging out RX and TX data under: [#!variable!records!#] interfaces. These have 1 or more historical records older than: [#!variable!age!#] hours old from the database host: [#!variable!host!#].</key>
<key name="scan_network_log_0002">The old network interface: [#!variable!name!#] with the MAC address: [#!variable!mac!#] was marked as deleted more than: [#!variable!age!#] hours ago. Purging it from the database.</key>
<key name="scan_network_log_0003">The old bond: [#!variable!name!#] was marked as deleted more than: [#!variable!age!#] hours ago. Purging it from the database.</key>
<key name="scan_network_log_0004">The old bridge: [#!variable!name!#] was marked as deleted more than: [#!variable!age!#] hours ago. Purging it from the database.</key>
<key name="scan_network_log_0005">The old IP address: [#!variable!ip!#] was marked as deleted more than: [#!variable!age!#] hours ago. Purging it from the database.</key>
</language>
</words>

@ -508,6 +508,8 @@ The output, if any, was;
<key name="error_0360">Unable to find the Anvil! information for the Anvil! UUID: [#!variable!anvil_uuid!#].</key>
<key name="error_0361">Unable to find the DRBD config from either node in the Anvil! with the Anvil! UUID: [#!variable!anvil_uuid!#]. Has scan_drbd (as part of scancore) run on either nodes?</key>
<key name="error_0362"><![CDATA[The level: [#!variable!level!#] is invalid. Please use '--level <critical,warning,notice,info>' to specify the alert level of the test message.]]></key>
<key name="error_0363">There are two or more entries on the host: [#!variable!host!#] in the history table: [#!variable!table!#]! The duplicate modidied_date and column UUID are: [#!variable!key!#] (time is UTC), and the query that exposed the dupplicate was: [#!variable!query!#]. This is likely caused by two database writes where the 'modified_date' wasn't updated between writes.</key>
<key name="error_0364">[ Error ] - There was a problem purging records. The details of the problem should be in the logs.</key>
<!-- Files templates -->
<!-- NOTE: Translating these files requires an understanding of which lines are translatable -->
@ -2120,6 +2122,9 @@ The file: [#!variable!file!#] needs to be updated. The difference is:
<key name="log_0699">[ Note ] - The Striker database host: [#!variable!host!#] is inactive, skipping it.</key>
<key name="log_0700">[ Note ] - Deleting the contents of the hash: [#!variable!hash!#].</key>
<key name="log_0701">Running the scan agent: [#!variable!agent_name!#]...</key>
<key name="log_0702">I was asked to update the timestamp, but the returned timestamp matches the last one. Will loop until a new timestamp is returned.</key>
<key name="log_0703">The timestamp has been updated from: [#!variable!old_time!#] to: [#!variable!new_time!#].</key>
<key name="log_0704"><![CDATA[[ Error ] - The method Database->read_state() was called but both the 'state_name' and 'state_uuid' parameters were not passed or both were empty.]]></key>
<!-- Messages for users (less technical than log entries), though sometimes used for logs, too. -->
<key name="message_0001">The host name: [#!variable!target!#] does not resolve to an IP address.</key>
@ -2540,6 +2545,7 @@ Available options;
<key name="message_0288">#!variable!total_cores!#c (#!variable!sockets!#s, #!variable!cores!#c, #!variable!threads!#t), #!variable!model!#, #!variable!mode!#</key>
<key name="message_0289">#!variable!cores!#c (#!variable!threads!#t)</key>
<key name="message_0290">-=] Server Usage and Anvil! Node Resource Availability</key>
<key name="message_0291">This program is currently disabled, please see NOTE in the header for more information.</key>
<!-- Success messages shown to the user -->
<key name="ok_0001">Saved the mail server information successfully!</key>
@ -3211,7 +3217,7 @@ We will sleep a bit and try again.
<key name="warning_0137">[ Warning ] - Timed out waiting for the connections to the peers, and the local resource(s) is not in 'UpToDate' state. Booting the server will likely fail.</key>
<key name="warning_0138">[ Warning ] - Timed out waiting for the connections to the peers.</key>
<key name="warning_0139">[ Warning ] - We're using: [#!variable!ram_used!#] (#!variable!ram_used_bytes!# Bytes). but there is a job: [#!variable!job_command!#] is runnng, which might be why the RAM is high. NOT exiting while this program is running.</key>
<key name="warning_0140">[ Warning ] - A no-longer active PID: [#!variable!pid!#] had marked our database as "in_use", but the PID is gone now. Reaping the flag.</key>
<key name="warning_0140">[ Warning ] - A no-longer active PID: [#!variable!pid!#] had marked the database: [#!variable!db!#] as "in_use", but the PID is gone now. Reaping the flag.</key>
<key name="warning_0141">[ Warning ] - We waited for: [#!variable!wait_time!#] seconds for all users of the local database to exit. Giving up waiting and taking the database down now.</key>
<key name="warning_0142">[ Warning ] - The command: [#!variable!command!#] is still using our database.</key>
<key name="warning_0143">[ Warning ] - While evaluating database shutdown, the host UUID: [#!variable!host_uuid!#] was not yet found in the database on host: [#!variable!db_uuid!#]. DB shutdown will not happen until all hosts are in all DBs.</key>

@ -143,6 +143,7 @@ $anvil->data->{switches}{'refresh-json'} = "";
$anvil->data->{switches}{'run-once'} = 0;
$anvil->data->{switches}{'main-loop-only'} = 0;
$anvil->data->{switches}{'no-start'} = 0;
$anvil->data->{switches}{'purge'} = 0;
$anvil->data->{switches}{'startup-only'} = 0;
$anvil->Get->switches;
@ -681,6 +682,11 @@ sub handle_periodic_tasks
}
}
# Reap old db_in_use states over 6 hours old.
my $query = "DELETE FROM states WHERE state_name LIKE 'db_in_use%' AND modified_date < (SELECT now() - interval '6 hour');\n";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0124", variables => { query => $query }});
$anvil->Database->write({debug => 2, query => $query, source => $THIS_FILE, line => __LINE__});
# Update the next check time.
$anvil->data->{timing}{next_ten_minute_check} = $now_time + $anvil->data->{timing}{ten_minute_checks};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
@ -718,7 +724,7 @@ sub handle_periodic_tasks
job_description => "job_0017",
job_progress => 0,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { job_uuid => $job_uuid }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { job_uuid => $job_uuid }});
# Update the OUI data.
($job_uuid) = $anvil->Database->insert_or_update_jobs({
@ -766,9 +772,7 @@ sub check_db_in_use_states
# We only reap db_in_use entries for us.
$anvil->System->pids();
my $host_uuid = $anvil->Database->quote($anvil->Get->host_uuid);
$host_uuid =~ s/^'(.*)'$/$1/;
my $query = "
my $query = "
SELECT
state_uuid,
state_name,
@ -776,7 +780,7 @@ SELECT
FROM
states
WHERE
state_name LIKE 'db_in_use::".$host_uuid."::%'
state_name LIKE 'db_in_use::%'
AND
state_host_uuid = ".$anvil->Database->quote($anvil->Get->host_uuid)."
;";
@ -794,18 +798,25 @@ AND
my $state_uuid = $row->[0];
my $state_name = $row->[1];
my $state_note = $row->[2];
my $state_pid = ($state_name =~ /db_in_use::.*?::(.*)$/)[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:state_uuid' => $state_uuid,
's2:state_name' => $state_name,
's3:state_note' => $state_note,
's4:state_pid' => $state_pid,
}});
my ($db_uuid, $state_pid) = ($state_name =~ /db_in_use::(.*?)::(\d+)$/);
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:db_uuid' => $anvil->Get->host_name_from_uuid({host_uuid => $db_uuid})." (".$db_uuid.")",
's4:state_pid' => $state_pid,
}});
if (not exists $anvil->data->{pids}{$state_pid})
{
# Reap the 'db_is_use'.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, priority => "alert", key => "warning_0140", variables => { pid => $state_pid }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, priority => "alert", key => "warning_0140", variables => {
db => $anvil->Get->host_name_from_uuid({host_uuid => $db_uuid})." (".$db_uuid.")",
pid => $state_pid,
}});
my $query = "DELETE FROM states WHERE state_uuid = ".$anvil->Database->quote($state_uuid).";";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0124", variables => { query => $query }});
@ -1348,6 +1359,21 @@ sub handle_special_cases
$anvil->DRBD->_initialize_kmod({debug => 2});
}
### TODO: Remove these later. This is here to clean up how we used to handle db_in_use and lock_request flags.
if (1)
{
# Broadly clear all states that are '0' now.
my $queries = [];
push @{$queries}, "DELETE FROM states WHERE state_name LIKE 'db_in_use::%' AND state_note != '1';";
push @{$queries}, "DELETE FROM history.variables WHERE variable_name = 'lock_request';";
push @{$queries}, "DELETE FROM variables WHERE variable_name = 'lock_request';";
foreach my $query (@{$queries})
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0124", variables => { query => $query }});
}
$anvil->Database->write({debug => 2, query => $queries, source => $THIS_FILE, line => __LINE__});
}
return(0);
}

@ -861,7 +861,15 @@ AND
if ((not exists $anvil->data->{seen}{bond}{$bond_name}) or (not $anvil->data->{seen}{bond}{$bond_name}))
{
# Mark it as deleted.
my $query = "UPDATE bonds SET bond_mode = 'DELETED' WHERE bond_uuid = ".$anvil->Database->quote($bond_uuid).";";
my $query = "
UPDATE
bonds
SET
bond_mode = 'DELETED',
modified_date = ".$anvil->Database->quote($anvil->Database->refresh_timestamp)."
WHERE
bond_uuid = ".$anvil->Database->quote($bond_uuid)."
;";
$anvil->Database->write({debug => 3, query => $query, source => $THIS_FILE, line => __LINE__});
# Remove it from the hash so we don't add it to the .json and .xml files.
@ -918,7 +926,14 @@ AND
if ((not exists $anvil->data->{seen}{bridge}{$bridge_name}) or (not $anvil->data->{seen}{bridge}{$bridge_name}))
{
# Mark it as deleted.
my $query = "UPDATE bridges SET bridge_id = 'DELETED' WHERE bridge_uuid = ".$anvil->Database->quote($bridge_uuid).";";
my $query = "
UPDATE
bridges
SET
bridge_id = 'DELETED',
modified_date = ".$anvil->Database->quote($anvil->Database->refresh_timestamp)."
WHERE
bridge_uuid = ".$anvil->Database->quote($bridge_uuid).";";
$anvil->Database->write({debug => 3, query => $query, source => $THIS_FILE, line => __LINE__});
# Remove it from the hash so we don't add it to the .json and .xml files.
@ -997,8 +1012,16 @@ ORDER BY
if ($anvil->data->{network_interfaces}{$network_interface_uuid}{network_interface_operational} ne "DELETED")
{
# Mark it as deleted.
my $query = "UPDATE network_interfaces SET network_interface_operational = 'DELETED' WHERE network_interface_uuid = ".$anvil->Database->quote($network_interface_uuid).";";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0124", variables => { query => $query }});
my $query = "
UPDATE
network_interfaces
SET
network_interface_operational = 'DELETED',
modified_date = ".$anvil->Database->quote($anvil->Database->refresh_timestamp)."
WHERE
network_interface_uuid = ".$anvil->Database->quote($network_interface_uuid)."
;";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0124", variables => { query => $query }});
$anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__});
}

@ -120,9 +120,6 @@ sub do_exit
my ($conf, $log, $exit_status) = @_;
$exit_status = 9 if not defined $exit_status;
# Close the log file handle, if it exists.
$log->close() if $log;
record($conf, $log, "system::do_chown: [".$conf->{'system'}{do_chown}."].\n", 2);
if ($conf->{'system'}{do_chown})
{
@ -133,6 +130,9 @@ sub do_exit
chown $uid, $gid, $conf->{'system'}{'log'};
}
# Close the log file handle, if it exists.
$log->close() if $log;
exit ($exit_status);
}
@ -213,8 +213,8 @@ sub metadata
</resource-agent>
`;
# Done, exit.
do_exit($conf, $log, 0);
# Done
return(0);
}
# This handles the actual actions.

@ -618,7 +618,8 @@ sub initialize_machines
if ($network !~ /^sn/)
{
push @{$machine_ips}, $ip_address;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { ip_count => @{$machine_ips} }});
my $ip_count = @{$machine_ips};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { ip_count => $ip_count }});
}
if (not $machine_host_uuid)

@ -43,6 +43,7 @@
# --status - This checks to see if dhcpd is running or not, then exits (effectively checking if the
# "Install Target" feature is running).
#
# NOTE: This is currently broken. Re-enable when a solution to anvil-striker-extra is found.
#
# TODO:
# - Support building the install target by mounting the ISO and checking /mnt/shared/incoming for needed
@ -186,6 +187,11 @@ if (not $configured)
$anvil->nice_exit({exit_code => 9});
}
### TODO: Remove this when re-enabled.
print $anvil->Words->string({key => "message_0291"})."\n";
update_progress($anvil, 100, "message_0291");
$anvil->nice_exit({exit_code => 0});
# Figure out what this machine is.
load_os_info($anvil);

@ -311,7 +311,7 @@ if ($local_uuid)
if ($create_user)
{
# Create the user
my $shell_call = $anvil->data->{path}{exe}{su}." - postgres -c \"".$anvil->data->{path}{exe}{createuser}." --no-superuser --createdb --no-createrole $database_user\"";
my $shell_call = $anvil->data->{path}{exe}{su}." - postgres -c \"".$anvil->data->{path}{exe}{createuser}." --no-superuser --createdb --no-createrole ".$database_user."\"";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
my ($create_output, $return_code) = $anvil->System->call({shell_call => $shell_call, debug => 2, source => $THIS_FILE, line => __LINE__});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {

@ -226,7 +226,7 @@ else
}
# List all database tables in reverse order with X_host_uuid tables
$anvil->Database->find_host_uuid_columns({search_column => "host_uuid", main_table => "hosts"});
$anvil->Database->find_host_uuid_columns({debug => 3, search_column => "host_uuid", main_table => "hosts"});
# For each host
foreach my $host_uuid (@{$anvil->data->{purge}{hosts}})
@ -295,7 +295,13 @@ WHERE
}
# Commit.
$anvil->Database->write({query => $queries, source => $THIS_FILE, line => __LINE__});
my $problem = $anvil->Database->write({query => $queries, source => $THIS_FILE, line => __LINE__});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }});
if ($problem)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, priority => "err", key => "error_0364"});
$anvil->nice_exit({exit_code => 1});
}
$vacuum = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { vacuum => $vacuum }});
@ -363,7 +369,13 @@ if ($anvil->data->{purge}{anvil_uuid})
}
# Commit.
$anvil->Database->write({query => $queries, source => $THIS_FILE, line => __LINE__});
my $problem = $anvil->Database->write({query => $queries, source => $THIS_FILE, line => __LINE__});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }});
if ($problem)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, priority => "err", key => "error_0364"});
$anvil->nice_exit({exit_code => 1});
}
$vacuum = 1;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { vacuum => $vacuum }});

Loading…
Cancel
Save