From 560d60c7e85d06a906921ad9aa9df59e9cf5fd9b Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Fri, 12 May 2023 22:28:14 -0400 Subject: [PATCH] fix(tools): get server screenshots every minute and punt to strikers WIP --- tools/anvil-daemon | 62 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/tools/anvil-daemon b/tools/anvil-daemon index faf573d4..f62717da 100755 --- a/tools/anvil-daemon +++ b/tools/anvil-daemon @@ -553,7 +553,11 @@ sub handle_periodic_tasks # Check if anything is needed to be done in /mnt/shared. check_incoming($anvil); - + + # Get a screenshot from every server (cluster resource) + # running on localhost and punt them to all strikers. + get_server_screenshot($anvil); + # Check for stale db_in_use states. check_db_in_use_states($anvil); } @@ -1815,3 +1819,59 @@ sub update_state_file return(0); } + +sub get_server_screenshot +{ + my $anvil = shift; + my $parameters = shift; + my $debug = $parameters->{debug} // 3; + + my $query = "SELECT host_uuid FROM hosts WHERE host_type = 'striker';"; + my $results = $anvil->Database->query({ query => $query, source => $THIS_FILE, line => __LINE__ }); + my $count = @{$results}; + + my $striker_uuid_csv; + + return (1) if ($count == 0); + + $striker_uuid_csv = $results->[0]->[0]; + + foreach my $row ( @{$results}[1 .. $#{$results}] ) + { + my $host_uuid = $row->[0]; + + $striker_uuid_csv = "$striker_uuid_csv,$host_uuid"; + } + + my ($rcode) = $anvil->Server->find(); + + return (1) if ($rcode != 0); + + my $server_list_on_local = $anvil->data->{server}{location}; + my $server_name_csv = join(", ", map { $anvil->Database->quote($_) } keys %{$server_list_on_local}); + + $query = "SELECT server_uuid FROM servers WHERE server_name IN (".$server_name_csv.") ORDER BY server_name;"; + $results = $anvil->Database->query({ query => $query, source => $THIS_FILE, line => __LINE__ }); + $count = @{$results}; + + return (1) if ($count == 0); + + foreach my $row ( @{$results} ) + { + my $server_uuid = $row->[0]; + + my ($syscall_output, $syscall_rcode) = $anvil->System->call({ + debug => $debug, + line => __LINE__, + shell_call => $anvil->data->{path}{exe}{'anvil-get-server-screenshot'}." --server-uuid '$server_uuid' --request-host-uuid '$striker_uuid_csv'", + source => $THIS_FILE, + }); + + $anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => $debug, list => { + syscall_output => $syscall_output, + syscall_rcode => $syscall_rcode, + }}); + } + + return (0); +} \ No newline at end of file