* Fixed several bugs related to tracking server boots, migrations and shut downs in the anvil database. The 'ocf:alteeve:server' now has (mostly?) safe integration with the Anvil! database. This was mostly done by updating Servers->boot_virsh(), ->shutdown_virsh() and ->migrate_server().

* Updates servers -> server_host_uuid to drop the 'NOT NULL' constraint.
* Created the new Get->server_uuid_from_name() that does what it says on the tin. Fixed a bug in ->host_uuid_from_name() where the host name was being returned instead of the UUID.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 4 years ago
parent be88be6d30
commit 33101f969a
  1. 26
      Anvil/Tools/Cluster.pm
  2. 6
      Anvil/Tools/Database.pm
  3. 97
      Anvil/Tools/Get.pm
  4. 199
      Anvil/Tools/Server.pm
  5. 4
      notes
  6. 11
      ocf/alteeve/server
  7. 3
      share/words.xml
  8. 64
      tools/test.pl

@ -16,6 +16,7 @@ my $THIS_FILE = "Cluster.pm";
### Methods;
# boot_server
# check_node_status
# get_anvil_uuid
# get_peers
# migrate_server
# parse_cib
@ -305,7 +306,7 @@ sub get_anvil_uuid
my $parameter = shift;
my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Cluster->check_node_status()" }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Cluster->get_anvil_uuid()" }});
my $host_uuid = defined $parameter->{host_uuid} ? $parameter->{host_uuid} : $anvil->Get->host_uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
@ -340,6 +341,7 @@ sub get_anvil_uuid
}
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { member_anvil_uuid => $member_anvil_uuid }});
return($member_anvil_uuid);
}
@ -1204,15 +1206,15 @@ sub parse_cib
{
$anvil->Database->get_servers({debug => $debug});
my $anvil_uuid = $anvil->Cluster->get_anvil_uuid({debug => $debug});
my $server_uuid = "";
foreach my $this_server_uuid (keys %{$anvil->data->{servers}{server_uuid}})
{
if (($server eq $anvil->data->{servers}{server_uuid}{$server_uuid}{server_name}) &&
($anvil_uuid eq $anvil->data->{servers}{server_uuid}{$server_uuid}{server_anvil_uuid}))
{
# Found it.
$server_uuid = $this_server_uuid;
if ($anvil->data->{servers}{server_uuid}{$server_uuid}{server_state} eq "migrating")
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { anvil_uuid => $anvil_uuid }});
my $server_uuid = $anvil->Get->server_uuid_from_name({
debug => $debug,
server_name => $server,
anvil_uuid => $anvil_uuid,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { server_uuid => $server_uuid }});
if (($server_uuid) && (exists $anvil->data->{servers}{server_uuid}{$server_uuid}) && ($anvil->data->{servers}{server_uuid}{$server_uuid}{server_state} eq "migrating"))
{
# We need to clean up a stale migration state. It may
# not actually be 'running', but if not, scan-server
@ -1239,10 +1241,6 @@ sub parse_cib
server_boot_time => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_boot_time},
});
}
last;
}
}
}
}

@ -3627,7 +3627,7 @@ FROM
my $server_user_stop = $row->[3];
my $server_start_after_server_uuid = defined $row->[4] ? $row->[4] : 'NULL';
my $server_start_delay = $row->[5];
my $server_host_uuid = $row->[6];
my $server_host_uuid = defined $row->[6] ? $row->[6] : 'NULL';
my $server_state = $row->[7];
my $server_live_migration = $row->[8];
my $server_pre_migration_file_uuid = defined $row->[9] ? $row->[9] : 'NULL';
@ -9348,7 +9348,7 @@ sub insert_or_update_servers
my $server_user_stop = defined $parameter->{server_user_stop} ? $parameter->{server_user_stop} : "FALSE";
my $server_start_after_server_uuid = defined $parameter->{server_start_after_server_uuid} ? $parameter->{server_start_after_server_uuid} : "NULL";
my $server_start_delay = defined $parameter->{server_start_delay} ? $parameter->{server_start_delay} : 30;
my $server_host_uuid = defined $parameter->{server_host_uuid} ? $parameter->{server_host_uuid} : "";
my $server_host_uuid = defined $parameter->{server_host_uuid} ? $parameter->{server_host_uuid} : "NULL";
my $server_state = defined $parameter->{server_state} ? $parameter->{server_state} : "";
my $server_live_migration = defined $parameter->{server_live_migration} ? $parameter->{server_live_migration} : "TRUE";
my $server_pre_migration_file_uuid = defined $parameter->{server_pre_migration_file_uuid} ? $parameter->{server_pre_migration_file_uuid} : "NULL";
@ -9562,7 +9562,7 @@ WHERE
my $old_server_user_stop = $row->[2];
my $old_server_start_after_server_uuid = defined $row->[3] ? $row->[3] : 'NULL';
my $old_server_start_delay = $row->[4];
my $old_server_host_uuid = $row->[5];
my $old_server_host_uuid = defined $row->[5] ? $row->[5] : 'NULL';
my $old_server_state = $row->[6];
my $old_server_live_migration = $row->[7];
my $old_server_pre_migration_file_uuid = defined $row->[8] ? $row->[8] : 'NULL';

@ -30,6 +30,7 @@ my $THIS_FILE = "Get.pm";
# host_uuid
# md5sum
# os_type
# server_uuid_from_name
# switches
# trusted_hosts
# uptime
@ -105,7 +106,7 @@ sub parent
=head2 anvil_name_from_uuid
This takes a Anvil! UUID and returns the Anvil! name (as recorded in the C<< anvils >> table). If the entry is not found, an empty string is returned.
This takes a Anvil! UUID and returns the Anvil! name (as recorded in the C<< anvils >> table). If the entry is not found, an empty string is returned. If there is a problem, C<< !!error!! >> will be returned.
Parameters;
@ -126,6 +127,12 @@ sub anvil_name_from_uuid
my $anvil_uuid = defined $parameter->{anvil_uuid} ? $parameter->{anvil_uuid} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { anvil_uuid => $anvil_uuid }});
if (not $anvil_uuid)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Get->anvil_name_from_uuid()", parameter => "server_name" }});
return("!!error!!");
}
my $query = "
SELECT
anvil_name
@ -916,6 +923,7 @@ sub host_uuid_from_name
if (exists $anvil->data->{sys}{hosts}{by_name}{$host_name})
{
$host_uuid = $anvil->data->{sys}{hosts}{by_name}{$host_name};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { host_uuid => $host_uuid }});
}
else
{
@ -932,14 +940,14 @@ sub host_uuid_from_name
if ($host_name eq $this_host_name)
{
# Found it.
$host_uuid = $this_host_name;
$host_uuid = $this_host_uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { host_uuid => $host_uuid }});
last;
}
elsif ($short_host_name eq $this_short_host_name)
{
# This is probably it, but we'll keep looping to be sure.
$host_uuid = $this_host_name;
$host_uuid = $this_host_uuid;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { host_uuid => $host_uuid }});
}
}
@ -1324,6 +1332,89 @@ sub os_type
}
=head2 server_uuid_from_name
This takes a server name and returns the server's uuid (as recorded in the C<< servers >> table). If the entry is not found, an empty string is returned. If there is a problem, C<< !!error!! >> will be returned.
Parameters;
=head3 anvil_uuid (optional)
If defined, only servers associated with the referenced Anvil! will be searched. This can help prevent situations where the same server name was used on different Anvil! systems.
=head3 server_name (required)
This is the C<< servers >> -> C<< server_name >> to translate into the server UUID.
=cut
sub server_uuid_from_name
{
my $self = shift;
my $parameter = shift;
my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Get->server_uuid_from_name()" }});
my $server_uuid = "";
my $anvil_uuid = defined $parameter->{anvil_uuid} ? $parameter->{anvil_uuid} : "";
my $server_name = defined $parameter->{server_name} ? $parameter->{server_name} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
anvil_uuid => $anvil_uuid,
server_name => $server_name,
}});
if (not $server_name)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Get->server_uuid_from_name()", parameter => "server_name" }});
return("!!error!!");
}
if ($anvil_uuid)
{
# Make sure the Anvil! UUID is valid.
my $anvil_name = $anvil->Get->anvil_name_from_uuid({anvil_uuid => $anvil_uuid});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { anvil_name => $anvil_name }});
if ((not $anvil_name) or ($anvil_name eq "!!error!!"))
{
# Invalid anvil_uuid
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "error_0162", variables => { anvil_uuid => $anvil_uuid }});
return("!!error!!");
}
}
my $query = "
SELECT
server_uuid
FROM
servers
WHERE
server_name = ".$anvil->Database->quote($server_name)." ";
if ($anvil_uuid)
{
$query .= "
AND
server_anvil_uuid = ".$anvil->Database->quote($anvil_uuid)." ";
}
$query .= "
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
my $count = @{$results};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
results => $results,
count => $count,
}});
if ($count == 1)
{
# Found it
$server_name = defined $results->[0]->[0] ? $results->[0]->[0] : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { server_name => $server_name }});
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { server_name => $server_name }});
return($server_name);
}
=head2 short_host_name
This returns the short host name for the machine this is running on. That is to say, the host name up to the first C<< . >>.

@ -157,6 +157,57 @@ sub boot_virsh
server => $server,
host => $anvil->data->{server}{location}{$server}{host},
}});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "sys::database::connections" => $anvil->data->{sys}{database}{connections} }});
if ($anvil->data->{sys}{database}{connections})
{
my $anvil_uuid = $anvil->Cluster->get_anvil_uuid({debug => $debug});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { anvil_uuid => $anvil_uuid }});
my $server_uuid = $anvil->Get->server_uuid_from_name({
debug => $debug,
server_name => $server,
anvil_uuid => $anvil_uuid,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { server_uuid => $server_uuid }});
if (($server_uuid) && ($server_uuid ne "!!error!!"))
{
$anvil->Database->get_servers({debug => $debug});
if (exists $anvil->data->{servers}{server_uuid}{$server_uuid})
{
my $old_state = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_state};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { old_state => $old_state }});
if ($old_state ne "in shutdown")
{
# Update it.
my $runtime = $anvil->Server->get_runtime({
debug => 2,
server => $server,
});
my $query = "
UPDATE
servers
SET
server_state = 'running',
server_host_uuid = ".$anvil->Database->quote($anvil->Get->host_uuid).", ";
if ($runtime =~ /^\d+$/)
{
my $boot_time = time - $runtime;
$query .= "
server_boot_time = ".$anvil->Database->quote($boot_time).", ";
}
$query .= "
modified_date = ".$anvil->Database->quote($anvil->data->{sys}{database}{timestamp})."
WHERE
server_uuid = ".$anvil->Database->quote($server_uuid)."
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__});
}
}
}
}
}
if ($wait)
@ -769,32 +820,23 @@ sub migrate_virsh
if ($anvil->data->{servers}{server_uuid}{$server_uuid}{server_state} ne "migrating")
{
$old_server_state = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_state};
$anvil->Database->insert_or_update_servers({
debug => $debug,
server_uuid => $server_uuid,
server_name => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_name},
server_anvil_uuid => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_anvil_uuid},
server_user_stop => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_user_stop},
server_start_after_server_uuid => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_start_after_server_uuid},
server_start_delay => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_start_delay},
server_host_uuid => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_host_uuid},
server_state => "migrating",
server_live_migration => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_live_migration},
server_pre_migration_file_uuid => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_pre_migration_file_uuid},
server_pre_migration_arguments => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_pre_migration_arguments},
server_post_migration_file_uuid => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_post_migration_file_uuid},
server_post_migration_arguments => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_post_migration_arguments},
server_ram_in_use => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_ram_in_use},
server_configured_ram => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_configured_ram},
server_updated_by_user => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_updated_by_user},
server_boot_time => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_boot_time},
});
my $query = "
UPDATE
servers
SET
server_state = 'migrating',
modified_date = ".$anvil->Database->quote($anvil->data->{sys}{database}{timestamp})."
WHERE
server_uuid = ".$anvil->Database->quote($server_uuid)."
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__});
}
}
# The virsh command switches host names to IPs and needs to have both the source and target IPs in
# the known_hosts file to work.
my $live_migrate = not $anvil->data->{servers}{server_uuid}{$server_uuid}{server_live_migration} ? "" : "--live";
my $live_migrate = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_live_migration} ? "--live" : "";
my $target_ip = $anvil->Convert->host_name_to_ip({debug => $debug, host_name => $target});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
target_ip => $target_ip,
@ -837,6 +879,7 @@ sub migrate_virsh
if ($anvil->data->{sys}{database}{connections})
{
$anvil->Database->get_servers({debug => 2});
$anvil->Database->refresh_timestamp({debug => $debug});
}
if ($return_code)
{
@ -851,26 +894,17 @@ sub migrate_virsh
# Revert the migrating state.
if (($server_uuid) && ($anvil->data->{sys}{database}{connections}))
{
$anvil->Database->insert_or_update_servers({
debug => $debug,
server_uuid => $server_uuid,
server_name => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_name},
server_anvil_uuid => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_anvil_uuid},
server_user_stop => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_user_stop},
server_start_after_server_uuid => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_start_after_server_uuid},
server_start_delay => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_start_delay},
server_host_uuid => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_host_uuid},
server_state => $old_server_state,
server_live_migration => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_live_migration},
server_pre_migration_file_uuid => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_pre_migration_file_uuid},
server_pre_migration_arguments => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_pre_migration_arguments},
server_post_migration_file_uuid => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_post_migration_file_uuid},
server_post_migration_arguments => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_post_migration_arguments},
server_ram_in_use => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_ram_in_use},
server_configured_ram => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_configured_ram},
server_updated_by_user => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_updated_by_user},
server_boot_time => $anvil->data->{servers}{server_uuid}{$server_uuid}{server_boot_time},
});
my $query = "
UPDATE
servers
SET
server_state = ".$anvil->Database->quote($old_server_state).",
modified_date = ".$anvil->Database->quote($anvil->data->{sys}{database}{timestamp})."
WHERE
server_uuid = ".$anvil->Database->quote($server_uuid)."
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__});
}
}
else
@ -881,7 +915,7 @@ sub migrate_virsh
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { success => $success }});
# Revert the server state and update the server host.
my $server_host_uuid = $anvil->Get->host_uuid_from_name({host_name => $target});
my $server_host_uuid = $anvil->Get->host_uuid_from_name({debug => $debug, host_name => $target});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { server_host_uuid => $server_host_uuid }});
if (not $server_host_uuid)
{
@ -892,6 +926,18 @@ sub migrate_virsh
}
if (($server_uuid) && ($anvil->data->{sys}{database}{connections}))
{
my $query = "
UPDATE
servers
SET
server_state = ".$anvil->Database->quote($old_server_state).",
server_host_uuid = ".$anvil->Database->quote($server_host_uuid).",
modified_date = ".$anvil->Database->quote($anvil->data->{sys}{database}{timestamp})."
WHERE
server_uuid = ".$anvil->Database->quote($server_uuid)."
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__});
$anvil->Database->insert_or_update_servers({
debug => $debug,
server_uuid => $server_uuid,
@ -1539,6 +1585,7 @@ sub shutdown_virsh
my $force = defined $parameter->{force} ? $parameter->{force} : 0;
my $wait = defined $parameter->{'wait'} ? $parameter->{'wait'} : 0;
my $success = 0;
my $server_uuid = "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
force => $force,
server => $server,
@ -1644,6 +1691,44 @@ sub shutdown_virsh
# Shut it down.
if ($shutdown)
{
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "sys::database::connections" => $anvil->data->{sys}{database}{connections} }});
if ($anvil->data->{sys}{database}{connections})
{
my $anvil_uuid = $anvil->Cluster->get_anvil_uuid({debug => $debug});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { anvil_uuid => $anvil_uuid }});
$server_uuid = $anvil->Get->server_uuid_from_name({
debug => $debug,
server_name => $server,
anvil_uuid => $anvil_uuid,
});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { server_uuid => $server_uuid }});
if (($server_uuid) && ($server_uuid ne "!!error!!"))
{
$anvil->Database->get_servers({debug => $debug});
if (exists $anvil->data->{servers}{server_uuid}{$server_uuid})
{
my $old_state = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_state};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { old_state => $old_state }});
if ($old_state ne "in shutdown")
{
# Update it.
my $query = "
UPDATE
servers
SET
server_state = 'in shutdown',
modified_date = ".$anvil->Database->quote($anvil->data->{sys}{database}{timestamp})."
WHERE
server_uuid = ".$anvil->Database->quote($server_uuid)."
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__});
}
}
}
}
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "log_0520", variables => { server => $server }});
my ($output, $return_code) = $anvil->System->call({
debug => $debug,
@ -1693,6 +1778,36 @@ sub shutdown_virsh
# Success!
$success = 1;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0426", variables => { server => $server }});
# Mark it as stopped now. (if we have a server_uuid, we have a database connection)
if ($server_uuid)
{
$anvil->Database->get_servers({debug => $debug});
if (exists $anvil->data->{servers}{server_uuid}{$server_uuid})
{
my $old_state = $anvil->data->{servers}{server_uuid}{$server_uuid}{server_state};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { old_state => $old_state }});
if ($old_state ne "shut off")
{
# Update it.
$anvil->Database->refresh_timestamp({debug => $debug});
my $query = "
UPDATE
servers
SET
server_state = 'shut off',
server_boot_time = 0,
server_host_uuid = NULL,
modified_date = ".$anvil->Database->quote($anvil->data->{sys}{database}{timestamp})."
WHERE
server_uuid = ".$anvil->Database->quote($server_uuid)."
;";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }});
$anvil->Database->write({query => $query, source => $THIS_FILE, line => __LINE__});
}
}
}
}
if (($stop_waiting) && (time > $stop_waiting))

@ -278,7 +278,7 @@ CREATE TABLE servers (
server_user_stop boolean not null default FALSE, -- When set, the server was stopped by a user. The Anvil! will not start a server that has been cleanly stopped.
server_start_after_server_uuid uuid, -- This can be the server_uuid of another server. If set, this server will boot 'server_start_delay' seconds after the referenced server boots. A value of '00000000-0000-0000-0000-000000000000' will tell 'anvil-safe-start' to not boot the server at all. If a server is set not to start, any dependent servers will also stay off.
server_start_delay integer not null default 0, -- See above.
server_host_uuid uuid not null, -- This is the current hosts -> host_uuid for this server. If the server is off, this will be blank.
server_host_uuid uuid, -- This is the current hosts -> host_uuid for this server. If the server is off, this will be blank.
server_state text not null, -- This is the current state of this server, as reported by 'virsh list --all' (see: man virsh -> GENERIC COMMANDS -> --list)
server_live_migration boolean not null default TRUE, -- When false, servers will be frozen for a migration, instead of being migrated while the server is migrating. During a cold migration, the server will be unresponsive, so connections to it could time out. However, by being frozen the migration will complete faster.
server_pre_migration_file_uuid uuid, -- This is set to the files -> file_uuid of a script to run BEFORE migrating a server. If the file isn't found or can't run, the script is ignored.
@ -705,7 +705,7 @@ pcs property set stonith-enabled=true
# Create a new server resource, stopped, create the location constraint (higher == preferred), then start.
pcs resource create srv07-el6 ocf:alteeve:server name="srv07-el6" meta allow-migrate="true" target-role="stopped" op monitor interval="60" on-fail="block" stop timeout="INFINITY" migrate_to timeout="INFINITY"
pcs resource create srv07-el6 ocf:alteeve:server name="srv07-el6" meta allow-migrate="true" target-role="stopped" op monitor interval="60" start timeout="INFINITY" on-fail="block" stop timeout="INFINITY" on-fail="block" migrate_to timeout="INFINITY"
pcs constraint location srv07-el6 prefers mk-a02n01=200 mk-a02n02=100
pcs resource enable srv07-el6
- or -

@ -676,7 +676,8 @@ sub start_server
start_drbd_resource($anvil);
# Still alive? Boot!
my ($success) = $anvil->Server->boot_virsh({debug => 3, server => $server});
my ($success) = $anvil->Server->boot_virsh({debug => 2, server => $server});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { success => $success }});
if ($success)
{
# Success!
@ -982,10 +983,6 @@ sub stop_server
stop_drbd_resource($anvil);
}
### Disabled, we'll leave daemons running.
# If this was the last running server, stop the daemons.
#check_daemons($anvil, "stop");
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0324", variables => { server => $server }});
$anvil->nice_exit({exit_code => 0});
}
@ -1379,7 +1376,7 @@ sub migrate_server
# If we're still alive, we're ready to migrate.
($migrated) = $anvil->Server->migrate_virsh({
debug => 3,
debug => 2,
server => $server,
source => $source,
target => $target
@ -1434,7 +1431,7 @@ sub migrate_server
# Call the pull migation.
($migrated) = $anvil->Server->migrate_virsh({
debug => 3,
debug => 2,
server => $server,
source => $source,
target => $target

@ -234,6 +234,7 @@ The error was:
<key name="error_0159">Unable to read the stat information for the file: [#!variable!file_path!#], the file doesn't appear to exist.</key>
<key name="error_0160">The '#!variable!name!#': [#!variable!uuid!#] is not valid.</key>
<key name="error_0161">Unable to mark the server with UUID: [#!variable!uuid!#] as "deleted" because it doesn't apprear to exist in the database in the first place.</key>
<key name="error_0162">The 'anvil_uuid': [#!variable!anvil_uuid!#] in invalid.</key>
<!-- Table headers -->
<key name="header_0001">Current Network Interfaces and States</key>
@ -795,7 +796,7 @@ We will keep looking.</key>
<key name="log_0321">The server: [#!variable!server!#] is already off.</key>
<key name="log_0322">The server: [#!variable!server!#] is hung. Its state is: [#!variable!state!#]. We will force it off now.</key>
<key name="log_0323">The attempt to force-off the server: [#!variable!server!#] returned a non-zero return code: [#!variable!return_code!#]. The output, if any, was: [#!variable!output!#].</key>
<key name="log_0324">The server: [#!variable!server!#] is now off.</key>
<key name="log_0324">The server: [#!variable!server!#] is not running on this machine.</key>
<key name="log_0325">The server: [#!variable!server!#] is running, but it is in an unexpected state: [#!variable!state!#]. Human intervention is required!</key>
<key name="log_0326">The server: [#!variable!server!#] was not listed on this node, so it is not running here.</key>
<key name="log_0327">Asking the server: [#!variable!server!#] to shut down now. Please be patient.</key>

@ -23,59 +23,41 @@ $| = 1;
my $anvil = Anvil::Tools->new();
$anvil->Log->level({set => 2});
$anvil->Log->secure({set => 1});
$anvil->data->{switches}{'shutdown'} = "";
$anvil->data->{switches}{boot} = "";
$anvil->data->{switches}{server} = "";
$anvil->Get->switches;
print "Connecting to the database(s);\n";
$anvil->Database->connect({debug => 3});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, secure => 0, key => "log_0132"});
$anvil->Storage->get_file_stats({
my $host_name = "mk-a02n02";
my $host_uuid = $anvil->Get->host_uuid_from_name({
debug => 2,
file_path => "/root/test",
host_name => $host_name,
});
print "host name: [".$host_name."], host_uuid: [".$host_uuid."]\n";
my $server = "srv07-el6";
my $runtime = $anvil->Server->get_runtime({
debug => 2,
server => $server,
});
if ($runtime)
{
my $boot_time = time - $runtime;
print "Server: [".$server."] has been running for: [".$runtime."] seconds.\n";
print "- Booted at: [".$anvil->Get->date_and_time({use_time => $boot_time})."]\n";
}
else
{
print "The server: [".$server."] isn't running.\n";
}
exit;
# $anvil->Cluster->shutdown_server({
# debug => 2,
# server => "srv07-el6",
# });
# $anvil->Cluster->shutdown_server({
# debug => 2,
# server => "srv01-sql",
# });
# exit;
if (0)
my $server_name = $anvil->data->{switches}{server} ? $anvil->data->{switches}{server} : "srv07-el6";
if ($anvil->data->{switches}{boot})
{
my $xml = '';
my $problem = $anvil->Cluster->parse_crm_mon({debug => 2, xml => $xml});
if ($problem)
{
print "Problem reading or parsing the 'crm_mon' XML.\n";
}
else
{
print "crm_mon parsed.\n";
}
print "Booting: [".$server_name."]\n";
$anvil->Server->boot_virsh({
debug => 2,
server => $server_name,
});
}
if (0)
elsif ($anvil->data->{switches}{'shutdown'})
{
my $problem = $anvil->Cluster->parse_cib({debug => 2});
print "Problem: [".$problem."]\n";
print "Shutting down: [".$server_name."]\n";
$anvil->Server->shutdown_virsh({
debug => 2,
server => $server_name,
});
}
exit;

Loading…
Cancel
Save