Heartbeat : wrapper pour exécution conditionnelle en crontab
Boris HUISGEN July 1, 2013
Ce script est utile pour lancer un script en crontab uniquement sur un node déclaré actif par Pacemaker. Bref, une exécution conditionnelle «safe».
root@cluster-www1:~# vim /usr/local/bin/cronrun.pl
#!/usr/bin/perl
#
# This script is a wrapper for executing a cron only if a node is active.
#
# Boris HUISGEN <bhuisgen@hbis.fr>
#
my $resource="res_Filesystem_1"; # resource name to check if active
#
# script
#
if ($#ARGV+1 < 2) {
print "Usage: cronrun.pl <CMD> [<ARG1> ...]\n";
exit;
}
my $check = `crm_mon -1 | grep -q -e '$resource.*$HOSTNAME'`;
if ($? == 0) {
my @cmd = @ARGV;
open(CMD, "@cmd |") || die "Error: failed to execute command.";
while (<CMD>) {
print $_;
}
}
Reste donc à modifier la crontab pour exécuter les scripts au travers de ce wrapper, comme par exemple :
0 3 * * * /usr/local/bin/cronrun.pl /bin/bash script.sh -arg1 -arg2