diff --git a/Anvil/Tools/Database.pm b/Anvil/Tools/Database.pm index 365c1689..69263a7a 100644 --- a/Anvil/Tools/Database.pm +++ b/Anvil/Tools/Database.pm @@ -1197,6 +1197,10 @@ This module will return the number of databases that were successfully connected Parameters; +=head3 all (optional, default 0) + +If set, then the checks to see if a database is active or not is ignored. If the postgresql server is running, we will connect to it. + =head3 check_for_resync (optional, default 0) If set to C<< 1 >>, and there are 2 or more databases available, a check will be make to see if the databases need to be resync'ed or not. This is also set if the command line switch C<< --resync-db >> is used. @@ -1281,6 +1285,7 @@ sub connect my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3; $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Database->connect()" }}); + my $all = defined $parameter->{all} ? $parameter->{all} : 0; my $check_if_configured = defined $parameter->{check_if_configured} ? $parameter->{check_if_configured} : 0; my $db_uuid = defined $parameter->{db_uuid} ? $parameter->{db_uuid} : ""; my $check_for_resync = defined $parameter->{check_for_resync} ? $parameter->{check_for_resync} : 0; @@ -1292,6 +1297,7 @@ sub connect my $tables = defined $parameter->{tables} ? $parameter->{tables} : ""; my $test_table = defined $parameter->{test_table} ? $parameter->{test_table} : $anvil->data->{sys}{database}{test_table}; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + all => $all, check_if_configured => $check_if_configured, db_uuid => $db_uuid, check_for_resync => $check_for_resync, @@ -1682,49 +1688,52 @@ sub connect "cache::database_handle::${uuid}" => $anvil->data->{cache}{database_handle}{$uuid}, }}); - # Before I continue, see if this database is going offline. - my ($active_value, undef, undef) = $anvil->Database->read_variable({ - debug => $debug, - uuid => $uuid, - variable_name => "database::".$uuid."::active", - }); - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { active_value => $active_value }}); - if (not $active_value) + # Before I continue, see if this database is inactive (unless 'all' is set). + if (not $all) { - # If we're "retry", we just started up. - if (($retry) && ($is_local)) - { - # Set the variable saying we're active. - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0698"}); - my $variable_uuid = $anvil->Database->insert_or_update_variables({ - uuid => $uuid, - variable_name => "database::".$uuid."::active", - variable_value => "1", - variable_default => "0", - variable_description => "striker_0294", - variable_section => "database", - variable_source_uuid => "NULL", - variable_source_table => "", - }); - - $anvil->data->{db_status}{$uuid}{active} = 1; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { - "db_status::${uuid}::active" => $anvil->data->{db_status}{$uuid}{active}, - }}); - } - else + my ($active_value, undef, undef) = $anvil->Database->read_variable({ + debug => $debug, + uuid => $uuid, + variable_name => "database::".$uuid."::active", + }); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { active_value => $active_value }}); + if (not $active_value) { - # Don't use this database. - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0699", variables => { host => $uuid }}); - $anvil->data->{cache}{database_handle}{$uuid}->disconnect; - delete $anvil->data->{cache}{database_handle}{$uuid}; - - if ($anvil->data->{sys}{database}{read_uuid} eq $uuid) + # If we're "retry", we just started up. + if (($retry) && ($is_local)) { - $anvil->data->{sys}{database}{read_uuid} = ""; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "sys::database::read_uuid" => $anvil->data->{sys}{database}{read_uuid} }}); + # Set the variable saying we're active. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0698"}); + my $variable_uuid = $anvil->Database->insert_or_update_variables({ + uuid => $uuid, + variable_name => "database::".$uuid."::active", + variable_value => "1", + variable_default => "0", + variable_description => "striker_0294", + variable_section => "database", + variable_source_uuid => "NULL", + variable_source_table => "", + }); + + $anvil->data->{db_status}{$uuid}{active} = 1; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + "db_status::${uuid}::active" => $anvil->data->{db_status}{$uuid}{active}, + }}); + } + else + { + # Don't use this database. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0699", variables => { host => $uuid }}); + $anvil->data->{cache}{database_handle}{$uuid}->disconnect; + delete $anvil->data->{cache}{database_handle}{$uuid}; + + if ($anvil->data->{sys}{database}{read_uuid} eq $uuid) + { + $anvil->data->{sys}{database}{read_uuid} = ""; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "sys::database::read_uuid" => $anvil->data->{sys}{database}{read_uuid} }}); + } + next; } - next; } } @@ -1776,25 +1785,30 @@ sub connect $anvil->data->{sys}{database}{read_uuid} = $uuid; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "sys::database::read_uuid" => $anvil->data->{sys}{database}{read_uuid} }}); - # If we're a striker, set the variable saying we're active if we need to. - my ($active_value, undef, undef) = $anvil->Database->read_variable({ - debug => $debug, - uuid => $uuid, - variable_name => "database::".$uuid."::active", - }); - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { active_value => $active_value }}); - if (not $active_value) + # If we're being called with 'all', don't set active as we could be just checking if + # we're active or not. + if (not $all) { - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0698"}); - my $variable_uuid = $anvil->Database->insert_or_update_variables({ - variable_name => "database::".$uuid."::active", - variable_value => "1", - variable_default => "0", - variable_description => "striker_0294", - variable_section => "database", - variable_source_uuid => "NULL", - variable_source_table => "", + # If we're a striker, set the variable saying we're active if we need to. + my ($active_value, undef, undef) = $anvil->Database->read_variable({ + debug => $debug, + uuid => $uuid, + variable_name => "database::".$uuid."::active", }); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { active_value => $active_value }}); + if (not $active_value) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0698"}); + my $variable_uuid = $anvil->Database->insert_or_update_variables({ + variable_name => "database::".$uuid."::active", + variable_value => "1", + variable_default => "0", + variable_description => "striker_0294", + variable_section => "database", + variable_source_uuid => "NULL", + variable_source_table => "", + }); + } } } elsif (not $anvil->data->{sys}{database}{read_uuid}) @@ -1841,6 +1855,10 @@ sub connect } # If we're a striker and no connections were found, start our database. + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + local_host_type => $local_host_type, + "sys::database::connections" => $anvil->data->{sys}{database}{connections}, + }}); if (($local_host_type eq "striker") && (not $anvil->data->{sys}{database}{connections})) { # Tell the user we're going to try to load and start. @@ -1854,7 +1872,7 @@ sub connect my $db_name = "anvil"; my $dump_files = []; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { directory => $directory }}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { directory => $directory }}); local(*DIRECTORY); opendir(DIRECTORY, $directory); while(my $file = readdir(DIRECTORY)) @@ -1982,7 +2000,7 @@ sub connect # Check if the dameon is running my $running = $anvil->System->check_daemon({daemon => $anvil->data->{sys}{daemon}{postgresql}}); - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { running => $running }}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { running => $running }}); if (not $running) { my $return_code = $anvil->System->start_daemon({daemon => $anvil->data->{sys}{daemon}{postgresql}}); @@ -12245,15 +12263,15 @@ sub insert_or_update_states } foreach my $db_uuid (@{$db_uuids}) { - my $count = $anvil->Database->query({debug => 2, uuid => $db_uuid, query => $query, source => $THIS_FILE, line => __LINE__})->[0]->[0]; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + my $count = $anvil->Database->query({uuid => $db_uuid, query => $query, source => $THIS_FILE, line => __LINE__})->[0]->[0]; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { 's2:db_uuid' => $db_uuid, 's2:count' => $count, }}); if (not $count) { $hosts_ok = 0; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { hosts_ok => $hosts_ok }}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { hosts_ok => $hosts_ok }}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "warning_0144", variables => { state_info => $state_name." -> ".$state_note, @@ -15912,12 +15930,10 @@ sub resync_databases # Before resync, age out the data in each DB $anvil->Database->_age_out_data({debug => $debug}); - ### NOTE: Don't sort this array, we need to resync in the order that the user passed the tables to us - ### to avoid trouble with primary/foreign keys. - # We're going to use the array of tables assembles by _find_behind_databases() stored in - # 'sys::database::check_tables' + # Build a list of tables + my $tables = $anvil->Database->get_tables_from_schema({debug => $debug, schema_file => "all"}); my $start_time = time; - foreach my $table (@{$anvil->data->{sys}{database}{check_tables}}) + foreach my $table (@{$tables}) { # We don't sync 'states' as it's transient and sometimes per-DB. next if $table eq "states"; @@ -17143,13 +17159,25 @@ sub _age_out_data uuid_column => $uuid_column, }}); + # Make sure the table exists, skip it if not. + my $query = "SELECT COUNT(*) FROM pg_catalog.pg_tables WHERE tablename=".$anvil->Database->quote($child_table)." AND schemaname='public';"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }}); + my $count = $anvil->Database->query({uuid => $uuid, query => $query, source => $THIS_FILE, line => __LINE__})->[0]->[0]; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { count => $count }}); + + if (not $count) + { + # Table doesn't exist yet, skip it. + next; + } + # Get a list of all records. my $queries = []; - my $query = "SELECT ".$uuid_column." FROM ".$child_table.";"; + $query = "SELECT ".$uuid_column." FROM ".$child_table.";"; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }}); my $results = $anvil->Database->query({uuid => $uuid, query => $query, source => $THIS_FILE, line => __LINE__}); - my $count = @{$results}; + $count = @{$results}; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { results => $results, count => $count, diff --git a/Anvil/Tools/Network.pm b/Anvil/Tools/Network.pm index 98853fc9..9620ee97 100644 --- a/Anvil/Tools/Network.pm +++ b/Anvil/Tools/Network.pm @@ -1060,9 +1060,13 @@ sub find_matches my $first = defined $parameter->{first} ? $parameter->{first} : ""; my $second = defined $parameter->{second} ? $parameter->{second} : ""; + my $source = defined $parameter->{source} ? $parameter->{source} : $THIS_FILE; + my $line = defined $parameter->{line} ? $parameter->{line} : __LINE__; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { first => $first, second => $second, + source => $source, + line => $line, }}); if (not $first) @@ -1072,7 +1076,11 @@ sub find_matches } elsif (ref($anvil->data->{network}{$first}) ne "HASH") { - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "error_0106", variables => { key => "first -> network::".$first }}); + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "error_0106", variables => { + key => "first -> network::".$first, + source => $source, + line => $line, + }}); return(""); } if (not $second) @@ -1082,7 +1090,11 @@ sub find_matches } elsif (ref($anvil->data->{network}{$second}) ne "HASH") { - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "error_0106", variables => { key => "second -> network::".$second }}); + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "error_0106", variables => { + key => "second -> network::".$second, + source => $source, + line => $line, + }}); return(""); } @@ -1221,6 +1233,8 @@ sub find_target_ip debug => $debug, first => $short_host_name, second => $target_host_name, + source => $THIS_FILE, + line => __LINE__, }); if ($match) { diff --git a/Anvil/Tools/ScanCore.pm b/Anvil/Tools/ScanCore.pm index 1fe867b4..c003f49c 100644 --- a/Anvil/Tools/ScanCore.pm +++ b/Anvil/Tools/ScanCore.pm @@ -2404,6 +2404,8 @@ LIMIT 1;"; debug => $debug, first => $anvil->Get->host_uuid, second => $host_uuid, + source => $THIS_FILE, + line => __LINE__, }); my $matched_ips = keys %{$match}; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { matched_ips => $matched_ips }}); diff --git a/Anvil/Tools/Striker.pm b/Anvil/Tools/Striker.pm index 4795f80a..54d46a22 100644 --- a/Anvil/Tools/Striker.pm +++ b/Anvil/Tools/Striker.pm @@ -1398,6 +1398,8 @@ sub parse_all_status_json debug => 3, first => $anvil->Get->short_host_name(), second => $short_name, + source => $THIS_FILE, + line => __LINE__, }); if ($match) { diff --git a/Anvil/Tools/System.pm b/Anvil/Tools/System.pm index f4198021..07ec0fb0 100644 --- a/Anvil/Tools/System.pm +++ b/Anvil/Tools/System.pm @@ -592,6 +592,7 @@ sub check_if_configured $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "System->check_if_configured()" }}); my ($configured, $variable_uuid, $modified_date) = $anvil->Database->read_variable({ + debug => $debug, variable_name => "system::configured", variable_source_uuid => $anvil->Get->host_uuid, variable_source_table => "hosts", @@ -2667,6 +2668,8 @@ sub generate_state_json debug => $debug, first => $anvil->Get->short_host_name(), second => $short_host_name, + source => $THIS_FILE, + line => __LINE__, }); if ($match) diff --git a/share/words.xml b/share/words.xml index 485e5c96..bf3e9147 100644 --- a/share/words.xml +++ b/share/words.xml @@ -163,7 +163,7 @@ Failed to generate an RSA public key for the user: [#!variable!user!#]. The outp The file: [#!variable!file!#] wasn't found. The parameter get_company_from_oui->mac must be a valid MAC address or be in the format 'xx:xx:xx'. Received: [#!variable!mac!#]. The file: [#!variable!file!#] was not found. - find_matches() was given the hash key: [#!variable!key!#], but it does not reference a hash. Are any IPs associated with this target?]]> + find_matches() was given the hash key: [#!variable!key!#], but it does not reference a hash. Are any IPs associated with this target? The caller was: [#!variable!source!#:#!variable!line!#].]]> Failed to reconnect after reconfiguring the network. Will reboot in hopes of coming up cleanly. The 'recipient_level': [#!variable!recipient_level!#] is invalid. It should be '0', '1', '2', or '3'. The 'notification_alert_level': [#!variable!notification_alert_level!#] is invalid. It should be '0', '1', '2', or '3'. @@ -503,6 +503,7 @@ The output, if any, was; Failed to load the database file: [#!variable!file!#]. Deleting it so it's not considered in the next load attempt. Failed to read the kernel release on the host: [#!variable!target!#]. The return code was: [#!variable!return_code!#] (expected '0') and the release output, if any, was: [#!variable!output!#]. The program: [#!variable!program!#] is using: [#!variable!ram_used!#] (#!variable!ram_used_bytes!# Bytes). This is probably caused by a memory leak, so we will now exit so that systemctl can restart us. If this is happening repeatedly, please contact support. + This is not a Striker host. @@ -2457,6 +2458,57 @@ Are you sure that you want to delete the server: [#!variable!server_name!#]? [Ty Preparing to manage DR for a server. UUID Column counts for: [history.#!variable!table!#]: Counting entries for each unique: [#!variable!column!#] in the table [#!variable!table!#]. Please be patient. + Marking this host as configured. + This host is already marked as configured. + Marking this host as configured. + This host is already marked as configured. + This host is marked as unconfigured. + This host is marked as configured. + This database is marked as inactive. + This database is marked as active. + Marking this database as active. + This database is already marked as active. + Marking this database as inactive. + This database is already marked as inactive. + +Available options; + +--age-out-database + + This purches older records to reduce the size of the database. + +--check-configured + + This checks to see if the host is marked as configured or not. + +--check-database + + This checks to see if the host's database is marked as active or not. + +--database-active + + This marks the host's database as active. + +--database-inactive + + This marks the host's database as inactive. + +--mark-configured + + This marks the host as being configured. + +--mark-unconfigured + + This marks the host as being unconfigured. + +--resync-database + + Force a resync of the databases. + + I was asked to resync, but there is only one database available so no sense proceeding. + I was asked to resync. Calling the resync now. + Aging out data to thin down the database(s). + Prior to resync, we will check to see if any scan agent schemas need to be loaded. Saved the mail server information successfully! diff --git a/tools/anvil-daemon b/tools/anvil-daemon index edac8a39..0c10f6c6 100755 --- a/tools/anvil-daemon +++ b/tools/anvil-daemon @@ -625,6 +625,8 @@ sub handle_periodic_tasks # down our database. if ($host_type eq "striker") { + ### NOTE: Database shutdown logic is disabled. Too flaky. +=cut if ($anvil->data->{sys}{database}{connections} > 1) { # Make sure that all active databases are in the host's table. If they're @@ -689,7 +691,8 @@ sub handle_periodic_tasks } } } - +=cut + # If we're the active database, dump our database out and rsync it to our peers. my $peers = keys %{$anvil->data->{database}}; my $connections = $anvil->data->{sys}{database}{connections}; @@ -768,6 +771,10 @@ sub handle_periodic_tasks # Archive old data $anvil->Database->archive_database(); + ### TODO: This is here only to handle the period of time where we disabled postgres + ### on boot. This should be removed sometime after 2022-08-01 + $anvil->System->enable_daemon({daemon => $anvil->data->{sys}{daemon}{postgresql}}); + # Record a job, don't call it directly. It takes too long to run. my ($job_uuid) = $anvil->Database->insert_or_update_jobs({ file => $THIS_FILE, @@ -838,6 +845,8 @@ FROM states WHERE state_name LIKE 'db_in_use::".$host_uuid."::%' +AND + state_host_uuid = ".$anvil->Database->quote($anvil->Get->host_uuid)." ;"; $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0124", variables => { query => $query }}); my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); diff --git a/tools/anvil-manage-host b/tools/anvil-manage-host new file mode 100755 index 00000000..ddc964db --- /dev/null +++ b/tools/anvil-manage-host @@ -0,0 +1,306 @@ +#!/usr/bin/perl +# +# This tool provides a way to perform actions on a host that normally are handled by other processes, like +# marking a system as configure, etc. This will likely grow constantly over time. +# +# Supported switches; +# --mark-configured, --mark-unconfigured +# - Set / unset the 'system::configured' flag for the host. +# --database-active, --database-inactive +# - On Striker, mark the local database as active / inactive +# + +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}/; +} + +my $anvil = Anvil::Tools->new(); + +# Read switches +$anvil->data->{switches}{'age-out-database'} = ""; +$anvil->data->{switches}{'check-configured'} = ""; +$anvil->data->{switches}{'check-database'} = ""; +$anvil->data->{switches}{'database-active'} = ""; +$anvil->data->{switches}{'database-inactive'} = ""; +$anvil->data->{switches}{'mark-configured'} = ""; +$anvil->data->{switches}{'mark-unconfigured'} = ""; +$anvil->data->{switches}{'resync-database'} = ""; +$anvil->Get->switches; +$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0115", variables => { program => $THIS_FILE }}); +$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + 'switches::age-out-database' => $anvil->data->{switches}{'age-out-database'}, + 'switches::check-configured' => $anvil->data->{switches}{'check-configured'}, + 'switches::check-database' => $anvil->data->{switches}{'check-database'}, + 'switches::database-active' => $anvil->data->{switches}{'database-active'}, + 'switches::database-inactive' => $anvil->data->{switches}{'database-inactive'}, + 'switches::mark-configured' => $anvil->data->{switches}{'mark-configured'}, + 'switches::mark-unconfigured' => $anvil->data->{switches}{'mark-unconfigured'}, + 'switches::resync-database' => $anvil->data->{switches}{'resync-database'}, +}}); + +$anvil->Database->connect({all => 1}); +$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132"}); +if (not $anvil->data->{sys}{database}{connections}) +{ + # No databases, we can't do anything. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 0, priority => "err", key => "error_0077"}); + $anvil->nice_exit({exit_code => 1}); +} + +if (($anvil->data->{switches}{'mark-configured'}) or ($anvil->data->{switches}{'mark-unconfigured'}) or ($anvil->data->{switches}{'check-configured'})) +{ + update_config($anvil); +} +elsif (($anvil->data->{switches}{'database-active'}) or ($anvil->data->{switches}{'database-inactive'}) or ($anvil->data->{switches}{'check-database'})) +{ + update_database($anvil); +} +elsif ($anvil->data->{switches}{'age-out-database'}) +{ + age_out_data($anvil); +} +elsif ($anvil->data->{switches}{'resync-database'}) +{ + resync_database($anvil); +} +else +{ + # Show the options. + print $anvil->Words->string({key => "message_0282"})."\n"; +} + +$anvil->nice_exit({exit_code => 0}); + + +############################################################################################################# +# Functions # +############################################################################################################# + +sub age_out_data +{ + my ($anvil) = @_; + + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "message_0285"}); + $anvil->Database->_age_out_data({debug => 2}); + + return(0); +} + +sub resync_database +{ + my ($anvil) = @_; + + if ($anvil->data->{sys}{database}{connections} == 1) + { + # No reason to proceed. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "message_0283"}); + return(0); + } + + # Before we reconnect, make sure all scan agent tables are loaded. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "message_0286"}); + $anvil->ScanCore->_scan_directory({directory => $anvil->data->{path}{directories}{scan_agents}}); + my $tables = ""; + foreach my $agent_name (sort {$a cmp $b} keys %{$anvil->data->{scancore}{agent}}) + { + my $agent_path = $anvil->data->{scancore}{agent}{$agent_name}; + my $agent_words = $agent_path.".xml"; + my $schema_file = $agent_path.".sql"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + agent_name => $agent_name, + agent_path => $agent_path, + agent_words => $agent_words, + schema_file => $schema_file, + }}); + + if (-e $schema_file) + { + # See that it's loaded. + $tables = $anvil->Database->get_tables_from_schema({schema_file => $schema_file}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { tables => $tables }}); + foreach my $table (@{$tables}) + { + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { table => $table }}); + } + $anvil->Database->check_agent_data({ + agent => $agent_name, + tables => $tables, + }); + } + } + + # Disconnect and reconnect. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "message_0284"}); + $anvil->data->{sys}{database}{resync_needed} = 1; + $anvil->Database->resync_databases({debug => 2}); + + return(0); +} + +sub update_database +{ + my ($anvil) = @_; + + # Are we a striker? + my $host_type = $anvil->Get->host_type(); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { host_type => $host_type }}); + if ($host_type ne "striker") + { + # Nope. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "error_0358"}); + $anvil->nice_exit({exit_code => 1}); + } + + my $host_uuid = $anvil->Get->host_uuid(); + my $variable_name = "database::".$host_uuid."::active"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + host_uuid => $host_uuid, + variable_name => $variable_name, + }}); + + + # Read if it's active or inactive yet. + my ($active_value, undef, undef) = $anvil->Database->read_variable({variable_name => "database::".$host_uuid."::active"}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { active_value => $active_value }}); + if ($anvil->data->{switches}{'check-database'}) + { + if ($active_value) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "message_0277"}); + } + else + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "message_0276"}); + } + return(0); + } + + # Are we enabling or disabling the database? + if ($active_value) + { + if ($anvil->data->{switches}{'database-active'}) + { + # Already active. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "message_0279"}); + } + else + { + # Mark inactive + my $variable_uuid = $anvil->Database->insert_or_update_variables({ + variable_name => $variable_name, + variable_value => "0", + variable_default => "0", + variable_description => "striker_0294", + variable_section => "database", + variable_source_uuid => "NULL", + variable_source_table => "", + }); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { variable_uuid => $variable_uuid }}); + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "message_0280"}); + } + } + else + { + if ($anvil->data->{switches}{'database-inactive'}) + { + # Already inactive + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "message_0281"}); + } + else + { + # Mark active + my $variable_uuid = $anvil->Database->insert_or_update_variables({ + variable_name => $variable_name, + variable_value => "1", + variable_default => "0", + variable_description => "striker_0294", + variable_section => "database", + variable_source_uuid => "NULL", + variable_source_table => "", + }); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { variable_uuid => $variable_uuid }}); + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "message_0278"}); + } + } + + return(0); +} + +sub update_config +{ + my ($anvil) = @_; + + # Check if it's already configured. + my $configured = $anvil->System->check_if_configured({debug => 2}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { configured => $configured }}); + + if ($anvil->data->{switches}{'check-configured'}) + { + if ($configured) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "message_0275"}); + } + else + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "message_0274"}); + } + return(0); + } + + if ($configured) + { + if ($anvil->data->{switches}{'mark-configured'}) + { + # Nothing to do. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "message_0271"}); + } + else + { + # Mark UN configures. + my $variable_uuid = $anvil->Database->insert_or_update_variables({ + variable_name => "system::configured", + variable_value => 0, + variable_default => "", + variable_description => "striker_0048", + variable_section => "system", + variable_source_uuid => $anvil->Get->host_uuid, + variable_source_table => "hosts", + }); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { variable_uuid => $variable_uuid }}); + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "message_0272"}); + } + } + else + { + if ($anvil->data->{switches}{'mark-unconfigured'}) + { + # Nothing to do. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "message_0273"}); + } + else + { + # Mark configures. + my $variable_uuid = $anvil->Database->insert_or_update_variables({ + variable_name => "system::configured", + variable_value => 1, + variable_default => "", + variable_description => "striker_0048", + variable_section => "system", + variable_source_uuid => $anvil->Get->host_uuid, + variable_source_table => "hosts", + }); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { variable_uuid => $variable_uuid }}); + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "message_0270"}); + } + } + + + return(0); +} diff --git a/tools/anvil-provision-server b/tools/anvil-provision-server index 54c79d1e..275bc711 100755 --- a/tools/anvil-provision-server +++ b/tools/anvil-provision-server @@ -953,6 +953,8 @@ sub get_sn_details my $match = $anvil->Network->find_matches({ first => $anvil->data->{job}{node1_short_host_name}, second => $anvil->data->{job}{node2_short_host_name}, + source => $THIS_FILE, + line => __LINE__, }); my $node1_short_host_name = $anvil->data->{job}{node1_short_host_name}; diff --git a/tools/anvil-rename-server b/tools/anvil-rename-server index de253398..37238b8f 100755 --- a/tools/anvil-rename-server +++ b/tools/anvil-rename-server @@ -970,6 +970,8 @@ sub gather_server_data debug => 2, first => $local_drbd_node_name, second => $host_name, + source => $THIS_FILE, + line => __LINE__, }); my $access = 0; diff --git a/tools/striker-initialize-host b/tools/striker-initialize-host index 6c66a4f3..b7c982bc 100755 --- a/tools/striker-initialize-host +++ b/tools/striker-initialize-host @@ -181,6 +181,8 @@ sub add_databases debug => 3, first => $local_host, second => $target, + source => $THIS_FILE, + line => __LINE__, }); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { match => $match }}); @@ -290,6 +292,8 @@ sub add_databases my ($match) = $anvil->Network->find_matches({ first => $target, second => $uuid, + source => $THIS_FILE, + line => __LINE__, }); my $keys = keys %{$match}; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { diff --git a/tools/striker-manage-install-target b/tools/striker-manage-install-target index cbf97873..a6880169 100755 --- a/tools/striker-manage-install-target +++ b/tools/striker-manage-install-target @@ -1241,6 +1241,8 @@ ORDER BY debug => 2, first => $local_short_host_name, second => $short_host_name, + source => $THIS_FILE, + line => __LINE__, }); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { match => $match }}); if (ref($match) eq "HASH") diff --git a/tools/striker-prep-database b/tools/striker-prep-database index dfa949c0..169b6246 100755 --- a/tools/striker-prep-database +++ b/tools/striker-prep-database @@ -237,9 +237,8 @@ if ($local_uuid) # Started the daemon. $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0059"}); - ### NOTE: We no longer enable postgres on boot. When the first call is made to - ### Database->connect on a striker, and no databases are available, it will - ### start up the local daemon then. + # Enable the daemon. + $anvil->System->enable_daemon({debug => 2, daemon => $anvil->data->{sys}{daemon}{postgresql}}); } else {