@ -18,17 +18,6 @@ if (($running_directory =~ /^\./) && ($ENV{PWD}))
my $anvil = Anvil::Tools->new();
$anvil->Get->switches;
$anvil->Database->connect;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132"});
if (not $anvil->data->{sys}{database}{connections})
{
# No databases, exit.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, priority => "err", key => "error_0003"});
$anvil->nice_exit({exit_code => 1});
}
sub system_call
{
my $parameters = shift;
@ -67,13 +56,74 @@ sub insert_server_screenshot
});
}
$anvil->Get->switches;
$anvil->Database->connect;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132"});
if (not $anvil->data->{sys}{database}{connections})
{
# No databases, exit.
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, priority => "err", key => "error_0003"});
$anvil->nice_exit({exit_code => 1});
}
# Try to get a job UUID if not given.
if (not $anvil->data->{switches}{'job-uuid'})
{
$anvil->data->{switches}{'job-uuid'} = $anvil->Job->get_job_uuid({ program => $THIS_FILE });
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => 2, list => {
"switches::job-uuid" => $anvil->data->{switches}{'job-uuid'}
} });
}
# Handle this script as a job when job UUID is provided.
if ($anvil->data->{switches}{'job-uuid'})
{
$anvil->Job->clear();
$anvil->Job->get_job_details();
$anvil->Job->update_progress({
progress => 1,
job_picked_up_by => $$,
job_picked_up_at => time,
message => "message_0263"
});
foreach my $line (split/\n/, $anvil->data->{jobs}{job_data})
{
if ($line =~ /server-uuid=(.*?)$/)
{
$anvil->data->{switches}{'server-uuid'} = $1;
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => 2, list => {
'switches::server-uuid' => $anvil->data->{switches}{'server-uuid'}
} });
}
if ($line =~ /stdout=(.*?)$/)
{
$anvil->data->{switches}{'stdout'} = $1;
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => 2, list => {
'switches::stdout' => $anvil->data->{switches}{'stdout'}
} });
}
}
}
my $server_uuid = $anvil->data->{switches}{'server-uuid'};
my $is_stdout = $anvil->data->{switches}{'stdout'};
my $job_uuid = $anvil->data->{switches}{'job-uuid'};
$anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => 2, list => {
server_uuid => $server_uuid,
is_stdout => $is_stdout,
job_uuid => $job_uuid
} });
if ($server_uuid)
{
my $encoded_image = get_server_screenshot({ server_uuid => $server_uuid });
if (defined $encoded_image)
{
if ($is_stdout)
{
print($encoded_image);
@ -85,4 +135,15 @@ if ($server_uuid)
encoded_image => $encoded_image
});
}
$anvil->Job->update_progress({ progress => 100, message => "message_0264" });
}
else
{
$anvil->Job->update_progress({ progress => 100, message => "message_0265" });
}
}
else
{
$anvil->Job->update_progress({ progress => 100, message => "message_0266" });
}