* Added a version file and Tools->_anvil_version() which reports the version in it.

* Added Get->anvil_version() to check the local or remote Anvil! version.
* Added a check in Database->connect() to see if a database server's Anvil! version matches the local version. If the versions don't match, the database is not used.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 7 years ago
parent 2170c00add
commit f72d8e0f70
  1. 29
      Anvil/Tools.pm
  2. 27
      Anvil/Tools/Database.pm
  3. 75
      Anvil/Tools/Get.pm
  4. 1
      anvil.version
  5. 1
      share/words.xml

@ -24,6 +24,7 @@ my $THIS_FILE = "Tools.pm";
# environment
# nice_exit
# _add_hash_reference
# _anvil_version
# _hostname
# _make_hash_reference
# _set_defaults
@ -129,6 +130,7 @@ sub new
HOST => {
# This is the host's UUID. It should never be manually set.
UUID => "",
ANVIL_VERSION => "",
},
};
@ -193,6 +195,9 @@ sub new
# Read in any command line switches.
$anvil->Get->switches;
# Read in the local Anvil! version.
# Set passed parameters if needed.
if (ref($parameter) eq "HASH")
{
@ -505,6 +510,23 @@ sub _add_hash_reference
}
}
=head2 _anvil_version
=cut
sub _anvil_version
{
my $self = shift;
my $anvil = $self;
if ($anvil->{HOST}{ANVIL_VERSION} eq "")
{
# Try to read the local Anvil! version.
$anvil->{HOST}{ANVIL_VERSION} = $anvil->Get->anvil_version();
}
return($anvil->{HOST}{ANVIL_VERSION});
}
=head2 _hostname
This returns the (full) hostname for the machine this is running on.
@ -512,8 +534,8 @@ This returns the (full) hostname for the machine this is running on.
=cut
sub _hostname
{
my $self = shift;
my $anvil = $self;
my $self = shift;
my $anvil = $self;
my $hostname = "";
if ($ENV{HOSTNAME})
@ -698,12 +720,13 @@ sub _set_paths
# Executables
$anvil->data->{path} = {
configs => {
'anvil.conf' => "/etc/anvil/anvil.conf",
'anvil.version' => "/etc/anvil/anvil.version",
'firewalld.conf' => "/etc/firewalld/firewalld.conf",
'journald_anvil' => "/etc/systemd/journald.conf.d/anvil.conf",
'pg_hba.conf' => "/var/lib/pgsql/data/pg_hba.conf",
'postgresql.conf' => "/var/lib/pgsql/data/postgresql.conf",
ssh_config => "/etc/ssh/ssh_config",
'anvil.conf' => "/etc/anvil/anvil.conf",
},
data => {
group => "/etc/group",

@ -751,6 +751,31 @@ sub connect
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "sys::read_db_id" => $anvil->data->{sys}{read_db_id} }});
}
# If this isn't a local database, read the target's Anvil! version (if available) and make
# sure it matches ours. If it doesn't, skip this database.
if (not $is_local)
{
my $remote_version = $anvil->Get->anvil_version({
target => $host,
password => $password,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
remote_version => $remote_version,
"anvil->_anvil_version" => $anvil->_anvil_version,
}});
if ($remote_version ne $anvil->_anvil_version)
{
# Version doesn't match,
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0145", variables => {
host => $host,
local_version => $anvil->_anvil_version,
target_version => $remote_version,
}});
next;
}
}
# Connect!
my $dbh = "";
### NOTE: The Database->write() method, when passed an array, will automatically disable
@ -853,6 +878,8 @@ sub connect
if ($count < 1)
{
### TODO: Create a version file/flag and don't sync with peers unless
### they are the same version. Back-port this to v2.
# Need to load the database.
$anvil->Database->initialize({id => $id, sql_file => $anvil->data->{path}{sql}{'anvil.sql'}});
}

@ -13,6 +13,7 @@ our $VERSION = "3.0.0";
my $THIS_FILE = "Get.pm";
### Methods;
# anvil_version
# cgi
# date_and_time
# host_uuid
@ -86,6 +87,80 @@ sub parent
# Public methods #
#############################################################################################################
=head2 anvil_version
This reads to C<< VERSION >> file of a local or remote machine. If the version file isn't found, C<< 0 >> is returned.
Parameters;
=head3 password (optional)
This is the password to use when connecting to a remote machine. If not set, but C<< target >> is, an attempt to connect without a password will be made.
=head3 port (optional)
This is the TCP port to use when connecting to a remote machine. If not set, but C<< target >> is, C<< 22 >> will be used.
=head3 target (optional)
This is the IP or host name of the machine to read the version of. If this is not set, the local system's version is checked.
=cut
sub anvil_version
{
my $self = shift;
my $parameter = shift;
my $anvil = $self->parent;
my $debug = $parameter->{debug} ? $parameter->{debug} : 2;
my $password = $parameter->{password} ? $parameter->{password} : "";
my $port = $parameter->{port} ? $parameter->{port} : "";
my $target = $parameter->{target} ? $parameter->{target} : "";
my $version = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
password => $anvil->Log->secure ? $password : "--",
port => $port,
target => $target,
}});
# Is this a local call or a remote call?
if (($target) && ($target ne "local") && ($target ne $anvil->_hostname) && ($target ne $anvil->_short_hostname))
{
# Remote call.
my $shell_call = "
if [ -e ".$anvil->data->{path}{exe}{'anvil.version'}." ];
then
cat ".$anvil->data->{path}{exe}{'anvil.version'}.";
else
echo 0;
fi;
";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { shell_call => $shell_call }});
$version = $anvil->System->remote_call({
shell_call => $shell_call,
target => $target,
port => $port,
password => $password,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { version => $version }});
}
else
{
# Local.
$version = $anvil->Storage->read_file({file => $anvil->data->{path}{exe}{'anvil.version'}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { version => $version }});
# Did we actually read a version?
if ($version eq "!!error!!")
{
$version = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 1, list => { version => $version }});
}
}
return($version);
}
=head2 cgi
This reads in the CGI variables passed in by a form or URL.

@ -215,6 +215,7 @@ The database connection error was:
<key name="log_0142"><![CDATA[[ Error ] - The system call: [#!variable!system_call!#] will fail because the program: [#!variable!program!#] isn't executable.]]></key>
<key name="log_0143">Failed to find a local ID, no databases are stored on this machine.</key>
<key name="log_0144">PostgreSQL server is not installed, unable to proceed.</key>
<key name="log_0145"><![CDATA[[ Warning ] - Unable to use the database on the host: [#!variable!host!#]. The local Anvil! version is: [#!variable!local_version!#], and the target host's is: [#!variable!target_version!#]. If you are upgrading, we will resync and use it once the host and our version is again the same.]]></key>
<!-- Test words. Do NOT change unless you update 't/Words.t' or tests will needlessly fail. -->
<key name="t_0000">Test</key>

Loading…
Cancel
Save