|
|
|
@ -508,6 +508,9 @@ sub handle_periodic_tasks |
|
|
|
|
# Check mail server config. |
|
|
|
|
my $problem = $anvil->Email->check_config({debug => 3}); |
|
|
|
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { problem => $problem }}); |
|
|
|
|
|
|
|
|
|
# Check if any files have been uploaded to /mnt/shared/incoming on striker |
|
|
|
|
check_incoming($anvil); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
# Now check to see if it's time to run less frequent tasks. |
|
|
|
@ -695,6 +698,77 @@ sub handle_periodic_tasks |
|
|
|
|
return(0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
# On dashboards, this checks to see if any files are in /mnt/shared/incoming and, if so, that they've been processed. |
|
|
|
|
sub check_incoming |
|
|
|
|
{ |
|
|
|
|
my ($anvil) = @_; |
|
|
|
|
|
|
|
|
|
my $system_type = $anvil->Get->host_type(); |
|
|
|
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { system_type => $system_type }}); |
|
|
|
|
if ($system_type eq "striker") |
|
|
|
|
{ |
|
|
|
|
# Look for files in /mnt/shared/incoming that are not yet in the database. |
|
|
|
|
my $directory = $anvil->data->{path}{directories}{shared}{incoming}; |
|
|
|
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { directory => $directory }}); |
|
|
|
|
|
|
|
|
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { directory => $directory }}); |
|
|
|
|
local(*DIRECTORY); |
|
|
|
|
opendir(DIRECTORY, $directory); |
|
|
|
|
while(my $file = readdir(DIRECTORY)) |
|
|
|
|
{ |
|
|
|
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { file => $file }}); |
|
|
|
|
next if $file eq "."; |
|
|
|
|
next if $file eq ".."; |
|
|
|
|
next if $file =~ /^\./; # This is files being rsync'ed still |
|
|
|
|
my $full_path = $directory."/".$file; |
|
|
|
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { full_path => $full_path }}); |
|
|
|
|
|
|
|
|
|
# Skip anything that is not a file. |
|
|
|
|
next if not -f $full_path; |
|
|
|
|
|
|
|
|
|
# Is this file already in the DB? |
|
|
|
|
my $query = "SELECT file_uuid FROM files WHERE file_name = ".$anvil->Database->quote($file).";"; |
|
|
|
|
$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__}); |
|
|
|
|
my $count = @{$results}; |
|
|
|
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
|
|
|
results => $results, |
|
|
|
|
count => $count, |
|
|
|
|
}}); |
|
|
|
|
if (not $count) |
|
|
|
|
{ |
|
|
|
|
# Add it to the database. |
|
|
|
|
my $size = (stat($full_path))[7]; |
|
|
|
|
my $say_size_human = $anvil->Convert->bytes_to_human_readable({'bytes' => $size}); |
|
|
|
|
my $say_size_comma = $anvil->Convert->add_commas({number => $size}); |
|
|
|
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
|
|
|
|
size => $size, |
|
|
|
|
say_size_human => $say_size_human, |
|
|
|
|
say_size_comma => $say_size_comma, |
|
|
|
|
}}); |
|
|
|
|
|
|
|
|
|
# Register a job to call anvil-sync-shared |
|
|
|
|
my ($job_uuid) = $anvil->Database->insert_or_update_jobs({ |
|
|
|
|
file => $THIS_FILE, |
|
|
|
|
line => __LINE__, |
|
|
|
|
job_command => $anvil->data->{path}{exe}{'anvil-sync-shared'}, |
|
|
|
|
job_data => "file=".$full_path, |
|
|
|
|
job_name => "storage::move_incoming", |
|
|
|
|
job_title => "job_0132", |
|
|
|
|
job_description => "job_0133", |
|
|
|
|
job_progress => 0, |
|
|
|
|
job_host_uuid => $anvil->data->{sys}{host_uuid}, |
|
|
|
|
}); |
|
|
|
|
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { job_uuid => $job_uuid }}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
closedir(DIRECTORY); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return(0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
# This calls striker-manage-install-target to see if the dhcpd is running or not. If it is or isn't, the config |
|
|
|
|
# variable 'install-target::enabled' is set/updated. On non-Striker hosts, this simply returns without doing |
|
|
|
|
# anything. |
|
|
|
|