It is also possible to offload scheduled tasks to something like JobScheduler 
jobscheduler.sf.net .. Which may give you more flexibility (or more unnecessary 
work)

One of the strengths of approaching it this way (or with a similar product) is 
that your scheduled tasks become "application" resources, rather than OS 
resources - YMMV.

Sent from my Verizon Wireless BlackBerry Storm

-----Original Message-----
From: "Ty! Boyack" <[email protected]>

Date: Tue, 03 Mar 2009 12:51:36 
To: General Linux-HA mailing list<[email protected]>
Subject: Re: [Linux-HA] crontab failover


I have done this by running the cronjob on all hosts that COULD be 
running the service, but run it through a wrapper that just checks to 
see if the service is active at the time.  For example, below is a 
script (sadly, from linux 2.4, but it would be just a regular expression 
change away from a current kernel) that can be called as 'ismyname' and 
then given a floating hostname and then a comnand.  I have it in my 
crontab as:

00 20 * * * root /usr/local/sbin/ismyname <floating-hostname> <Command 
to run>

When this runs, checks to see if we have the hostname running on this 
host at this time, and if so, runs the command.  If we do not have the 
hostname on this host, then we are a backup server for that service and 
it exits out without running the command.

Here is my 'ismyname' script in case it's useful, but beware that it's 
several years old and begins with spelling errors -- it is far more of a 
quick tool than an example of elegant code :-)   Still, it works fine 
and is a good starting point if it helps.

-Ty!

=======================SNIP===========================

#!/usr/local/bin/perl -w

# Description:
#
# Generic wrapper for one command to run another, that
# preservs arguments in the process
#
# Check to see if we have a given network address on this host,
# and run the command only if we do have it.  This is useful
# for our high availabilty servers with floating IP's, so that
# cron jobs (for example) can be run on both primary and backup
# machines, but only do real work on the active machine.
#
# THIS IS THE LINUX 2.4 VERSION.  ifconfig parses different under
# other os's.
#
################################################################
#
# Configurables:
#

# Add /sbin to the path
$ENV{PATH}='/sbin:'.$ENV{PATH};

# End of Configurables
################################################################
#
# USE statements and associated controls
#
use strict;
use diagnostics;
use FileHandle;
STDOUT->autoflush();
# End of USE statements
################################################################
#
# Main
#

#Put any wrapper customizations in here:

my $IP;
my $HOSTNAME=shift;

if (!defined $HOSTNAME)
  {
    Useage();
  }
else
  {
    my $addr=gethostbyname($HOSTNAME);
    if (defined $addr)
      {
        my($a,$b,$c,$d)=unpack('C4', $addr);
        $IP="$a.$b.$c.$d";
      }
    else
      {
        $IP="NOIP";
      }
  }


if ($IP !~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/)
  {
    print "$HOSTNAME is not a valid host!\n\n";
    Useage();
  }

my $ifcfgline="";
open IFCONFIG, "ifconfig -a|" or die "Cannot run ifconfig\n";
while (my $line=<IFCONFIG>)
  {
    chomp $line;
    $ifcfgline.=$line;
  }
close IFCONFIG;

# Now, if we cannot find an "UP" interface with our address, bail out
if ($ifcfgline !~ /inet addr\:$IP.{1,100}UP/)
  {
    exit;
  }

# Process the arguements into a string
my $arglist="";
my $cmd=shift;
for my $arg (@ARGV)
  {
    $arglist=$arglist.quotemeta($arg)." ";
  }

#Run the desired command
exec("$cmd $arglist");

sub Useage
  {
    print "\nUseage:  ismyname <HOSTNAME> <command> [[arg] ...]\n";
    print "or       ismyname <IPADDR> <command> [[arg] ...]\n\n";
    print "This tool will check if we have the given ip address running\n";
    print "on an interface on this host, and if so, runs the given 
command.\n";
    exit;
  }

=======================SNIP===========================



Yan Seiner wrote:
> I am trying to figure out how to set up a failover system that runs apps
> from crontab.
>
> In my current setup, the server starts a cron job every 2 hours that
> reaches out to my clients and pulls data.  This must be a server-pull;
> there is no way to set it up as a client-push.  The data that's pulled
> will be replicated using rsync, coda, etc to the backup server.  (I have
> not gotten that far yet.)
>
> I'd like to set this up as a failover system.  Apache sounds easy, but how
> do I failover a cron job?
>
> Also, is it possible to have the two servers in different geographic
> locations?  Ie. to do the failover to another server, in another country?
>
> --Yan
>
>   


-- 
-===========================-
  Ty! Boyack
  NREL Unix Network Manager
  [email protected]
  (970) 491-1186
-===========================-

_______________________________________________
Linux-HA mailing list
[email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha
See also: http://linux-ha.org/ReportingProblems
_______________________________________________
Linux-HA mailing list
[email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha
See also: http://linux-ha.org/ReportingProblems

Reply via email to