bowei_99 has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I have a script that needs to be running continuously as a service on a cluster, so it can failover to another node if need be. The cluster software is working fine, but the cron part is a little iffy.

Specifically, when I launch it using perl script.pl, the script

I tried detach=>1, per problem with Schedule::Cron, but that didn't work - it still kept calling the subroutine multiple times. I know this for sure because I got multiple emails to that effect. The desired effect, as in the cron definition in the code below, is to have it launch the subroutine once and only once every minute.

Anybody ran into this before? I'm open to using something other than Schedule::Cron, assuming it will work on a clustered failover system, so normal unix cron won't work. This is my code: ...

use Schedule::Cron; #Variable declarations my $rootdir = "/testdir"; # Initialize and run the cron job. Note that this is continuous by na +ture. my $cron = new Schedule::Cron(\&dispatcher, ); #$cron->add_entry("0 15 * * * *", $cron->add_entry("0-59 * * * * *", {'subroutine' => \&GetStats, } ); $cron->run(detach=>1, pid_file=>"$rootdir/$0.pid"); ################################################ # Subroutines to be called sub dispatcher { print "ID: ",shift,"\n"; print "Args: ","@_","\n"; }

Replies are listed 'Best First'.
Re: Schedule::Cron job starts, but never stops
by jkeenan1 (Deacon) on Jun 10, 2006 at 02:06 UTC
    bowei_99 wrote:

    The desired effect, as in the cron definition in the code below, is to have it launch the subroutine once and only once every minute.

    ...

    $cron->add_entry("0-59 * * * * *", {'subroutine' => \&GetStats, } );

    The CPAN documentation for Schedule::Cron says that the first argument is minutes and that seconds is only an optional, sixth argument. If I understand this correctly, shouldn't it be:

    $cron->add_entry( "1 * * * *", {'subroutine' => \&GetStats} );

    Also, does this pass use strict; use warnings;?

    Jim Keenan
Re: Schedule::Cron job starts, but never stops
by graff (Chancellor) on Jun 10, 2006 at 14:57 UTC
    I'm having trouble figuring out what you're asking for exactly -- probably because I've never done anything involving a clustered failover system.

    Is it a problem with keeping exactly one instance of a service running, or just with checking at one-minute intervals (not multiple times per second) that the service is running?

    If the latter, I would expect that there's a simple way of probing from outside the cluster to check that the service is running, and this could just be a plain old cron job (or if you really want a perl script running 24/7, it could just be:  while(1){ checkservice(); sleep 60 } (and write the "checkservice" sub to do whatever needs to be done).

    If you want some sort of failover on the checking as well, have the primary check routine write something to a specific file on shared disk, and have some other machine check the modification date on that file at regular intervals. If both of these machines outside the cluster go down, you probably don't need a script or log file to tell you that there's a bigger problem...

    Sorry if I have completely misunderstood the question.