I'm trying to figure out why the perl process we have running in a loop isn't working.
Basically its setup to read our queue from Amazon SQS with the results getting inserted into the db.
We are using EC2 for video transcoding and once the conversion takes place our web server hosted outside of Amazon has a perl process that reads SQS.
I'm not a dev but I think I can find the problem if given some suggestions on how to test. I was trying to locate the "aws-daemon" log but wasn't able to find it in /var/log. I see that first line below states to exit if theres an INT flag, but I'm not sure what that means, and if it did set that flag does it mean theres a problem that is still existing somewhere preventing this process from working.
I've rebooted the server, and launched a new ec2 instance but other than that I don't know enough on how to kill or restart a process or whether thats the way to do it. I know there is stuff sitting in the queue waiting for this process to pull it and insert it into the db. Any help would be greatly appreciated.
#!/usr/bin/perl -w
use Error qw(:try);
use MIME::Base64;
use FindBin qw($Bin);
use POSIX qw(setsid setuid);
use Config::Auto;
use Proc::Daemon;
use Log::Log4perl qw(:easy);
use Platform;
use Platform::Queue;
use Platform::Video;
use strict;
# when we get a INT signal, set the exit flag
$SIG{INT} = sub { $::exit = 1 };
# setup logging
Log::Log4perl->easy_init($TRACE);
my ($log, $conf, $video, $sqs, $queue);
$log = Log::Log4perl->get_logger('aws-daemon');
$conf = Config::Auto::parse($Bin . "/aws.conf", format => "colon");
$video = Platform->new();
$sqs = Platform::Queue->new({
aws_access_key_id => $conf->{'aws_id'},
aws_secret_access_key => $conf->{'aws_secret'} });
# fork into the background
# do this first because our process id will change
Proc::Daemon::Init;
$log->trace('calling daemonize()');
&daemonize();
# our infinite loop
while(1) {
$log->trace('running...');
exit if $::exit;
check_queues($conf, $sqs, $video);
$log->trace('sleeping for two minutes...');
sleep(120);
exit if $::exit;
$log->trace('still running...');
}
sub check_queues {
$log->trace('check_queues');
my ($conf, $sqs, $video) = @_;
try {
$video->read_result_queue();
} catch Error with {
my $ex = shift;
$log->trace('Exception in check_queues: ' . $ex);
} finally {
}
}
sub daemonize {
chdir '/' or die "Can't chdir to /: $!";
open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
open STDOUT, '>>/tmp/awsd' or die "Can't write to /dev/null: $!";
open STDERR, '>>/tmp/awsd' or die "Can't write to /dev/null: $!";
defined(my $pid = fork) or die "Can't fork: $!";
exit if $pid;
setsid or die "Can't start a new session: $!";
umask 0;
}