perl process loop isn't running


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting perl process loop isn't running
# 1  
Old 09-01-2009
perl process loop isn't running

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.

Code:
#!/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;
}

# 2  
Old 09-01-2009
The reason you don't get a log file in /var/log/ is that Log::Log4perl::easy_init will only send messages to stdout/stderr, both of which are redirect to /tmp/awsd in daemonize(). Check that file for any error messages.

The $SIG{INT} construct tells the script what to do should it receive a SIGINT (usually via kill -2 <pid>). It will set the exit variable, which is checked by the loop, which then will exit.
# 3  
Old 09-01-2009
Quote:
Originally Posted by pludi
The reason you don't get a log file in /var/log/ is that Log::Log4perl::easy_init will only send messages to stdout/stderr, both of which are redirect to /tmp/awsd in daemonize(). Check that file for any error messages.

The $SIG{INT} construct tells the script what to do should it receive a SIGINT (usually via kill -2 <pid>). It will set the exit variable, which is checked by the loop, which then will exit.
I'm not finding any /tmp/awsd directory currently.

I have a terminal output text file I saved back in June that does show the /tmp/awsd but now the directory shows totally different files

right now the /tmp has
.ICE-unix/ queue-log s3-bash/ .webmin/ .X11-unix/

and in june the /tmp was
awsd php-www.log queue-log s3-bash

---------- Post updated at 01:18 PM ---------- Previous update was at 01:17 PM ----------

So aside from the logs is there something that can be done to execute the process from the cmd line, do I need the pid in order to do that? Any help is really appreciated.

Last edited by kwick6; 09-01-2009 at 12:06 PM..
# 4  
Old 09-01-2009
I might recommend a minor rewrite of the sub daemonize function to include some reporting (as well as identifying the correct files that can't be written to...).
Change this around such that:
Code:
   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 /tmp/awsd: $!";
   open STDERR, '>>/tmp/awsd' or die "Can't write to /tmp/awsd: $!";
   defined(my $pid = fork)   or die "Can't fork: $!";
#   exit if $pid;
   if ($pid)
   {
      print "stuff that is relevant to the process is output to screen"
      exit
   }
   setsid                    or die "Can't start a new session: $!";
   umask 0;

This will let you know what it sees BEFORE you exit - it might help you to debug.

You might want to read up on the perl module "Log::Log4perl" - it might have some information that would make this more clear.
# 5  
Old 09-01-2009
The /tmp/aswd file was probably deleted when you rebooted, since most Linux distributions will clean up /tmp on boot.

To start the daemon: /path/to/aws-daemon
To stop the daemon:
Code:
$ ps -ef | grep aws-daemon # Note the PID
$ kill -2 <pid of aws-daemon>

Generally, when a daemon has to be restarted, it isn't necessary to reboot the whole server (as opposed to some services in Windows)
# 6  
Old 09-01-2009
Quote:
Originally Posted by pludi
The /tmp/aswd file was probably deleted when you rebooted, since most Linux distributions will clean up /tmp on boot.

To start the daemon: /path/to/aws-daemon
To stop the daemon:
Code:
$ ps -ef | grep aws-daemon # Note the PID
$ kill -2 <pid of aws-daemon>

Generally, when a daemon has to be restarted, it isn't necessary to reboot the whole server (as opposed to some services in Windows)
It gave an error:

Can't locate Platform.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl .) at /path/to/aws-daemon line 9.
BEGIN failed--compilation aborted at /path/to/aws-daemon line 9.
# 7  
Old 09-01-2009
It appears that you are missing a perl module or two...
Quote:
Can't locate Platform.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.8.8 /usr/local/share/perl/5.8.8 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl .) at /path/to/aws-daemon line 9.
Code:
line 9#    use Platform;
line 10#   use Platform::Queue;
line 11#   use Platform::Video;

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Command to get exact tomcat process I am running ignoring other java process

Team, I have multiple batchjobs running in VM, if I do ps -ef |grep java or tomcat I am getting multiple process list. How do I get my exact tomcat process running and that is unique? via shell script? (4 Replies)
Discussion started by: Ghanshyam Ratho
4 Replies

2. UNIX for Advanced & Expert Users

Process remians in Running state causing other similar process to sleep and results to system hang

Hi Experts, I am facing one problem here which is one process always stuck in running state which causes the other similar process to sleep state . This causes my system in hanged state. On doing cat /proc/<pid>wchan showing the "__init_begin" in the output. Can you please help me here... (6 Replies)
Discussion started by: naveeng
6 Replies

3. BSD

Process remians in Running state causing other similar process to sleep and results to system hang

Hi Experts, I am facing one problem here which is one process always stuck in running state which causes the other similar process to sleep state . This causes my system in hanged state. On doing cat /proc/<pid>wchan showing the "__init_begin" in the output. Can you please help me here... (0 Replies)
Discussion started by: naveeng
0 Replies

4. Shell Programming and Scripting

Bash Question: HowTo Exit Script with User Input While Process is Running Mid-Loop?

Hi, I have written a script that allows me to repetitively play a music file $N times, which is specified through user input. However, if I want to exit the script before it has finished looping $N times, if I use CTRL+c, I have to CTRL+c however many times are left in order to complete the loop.... (9 Replies)
Discussion started by: hilltop_yodeler
9 Replies

5. Linux

X Window isn't running

X Window isn't working. When I ran startx I got an error message as shown in file attachment xwndow.png Accordingly, I removed /tmp/.X0-lock as reflecting in the attchment. Then again I ran the command and 2 more commands (shown in the attachment xwndow1.png) but they failed too. Any... (2 Replies)
Discussion started by: ravisingh
2 Replies

6. Shell Programming and Scripting

loop when process running

Hi Gurus, Could you please help me to create a shell script that will be started by a cron job once every night at 24.00 h (that should bee easy:)) The shell script should control every 30 seconds the name of a process, and when the process doesn't run anymore it should execute a few further... (12 Replies)
Discussion started by: blackwire
12 Replies

7. Shell Programming and Scripting

script to monitor process running on server and posting a mail if any process is dead

Hello all, I would be happy if any one could help me with a shell script that would determine all the processes running on a Unix server and post a mail if any of the process is not running or aborted. Thanks in advance Regards, pradeep kulkarni. :mad: (13 Replies)
Discussion started by: pradeepmacha
13 Replies

8. Shell Programming and Scripting

infinite loop to check process is running

Hi, I got a simple script working to check if a process is running and then email if it is not running anymore. My scenario is that I need to make sure the process is always running so instead of running the below script via cron I think it is better to a have a looping script to check... (12 Replies)
Discussion started by: yabai
12 Replies

9. UNIX for Dummies Questions & Answers

perl scripting for checking if a process is running

Hi All, I am new to perl and have been trying to write a short script to check a process.Though i havent reached to the stage where i can match the output. I am trying to pass a variable x with value /opt/RGw/csbp-base/CSBP_BAT.01.00.05/csbp_BAT.01.00.05.jar and then pass another variable... (2 Replies)
Discussion started by: pistachio
2 Replies

10. Shell Programming and Scripting

perl problem - why isn't 'die' being called?

last week i started learning perl, so have limited skill and knowledge. why isn't 'die' being called and the script exiting before the 'directory created' line? if (! -d "$logdir") { system "mkdir -p $logdir" || die print "\nERROR: release log directory creation failed - $logdir: $!\n";... (4 Replies)
Discussion started by: mjays
4 Replies
Login or Register to Ask a Question