Masato Taruishi
taru****@users*****
2004年 10月 13日 (水) 20:12:47 JST
=================================================================== RCS file: ultrapossum/module/failover/nfs.monitor,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ultrapossum/module/failover/nfs.monitor 2004/10/13 11:00:07 1.4 +++ ultrapossum/module/failover/nfs.monitor 2004/10/13 11:12:46 1.5 @@ -43,6 +43,10 @@ fi fi -sudo $MODULEDIR/failover/statuscpy 2>&1 | logger -p user.err & +$backup = "$NFSDIR/$RPLDIR/backup/slurpd.status"; +$pidfile = "$FAILOVER_STATUSCPY_PIDFILE"; +$status = "$SLURPDRPLDIR/replica/slurpd.status"; + +sudo $MODULEDIR/failover/statuscpy $status $backup $pidfile 2>&1 | logger -p user.err & exit 0 =================================================================== RCS file: ultrapossum/module/failover/statuscpy,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ultrapossum/module/failover/statuscpy 2004/10/12 09:43:26 1.3 +++ ultrapossum/module/failover/statuscpy 2004/10/13 11:12:46 1.4 @@ -1,4 +1,4 @@ -#!/usr/bin/env perl +#!/usr/bin/env bash # # Copyright (c) 2004 VA Linux Systems Japan, K.K # @@ -16,104 +16,21 @@ # # -use POSIX; -use UltraPossum::Conf; +# statuscpy <from> <to> <pidfile> -my $cf = UltraPossum::Conf->new; +set -e -$backup = "$cf->{NFSDIR}/$cf->{RPLDIR}/backup/slurpd.status"; -$lock = "$cf->{SLURPDRPLDIR}/replica/slurpd.status.lock"; -$pidfile = "$cf->{FAILOVER_STATUSCPY_PIDFILE}"; +if test "x$3" = "x"; then + echo "Usage: $0 <from> <to> <pidfile>" 1>&2 + exit 1 +fi -$status = "$cf->{SLURPDRPLDIR}/replica/slurpd.status"; +trap "/bin/rm -f $3" 0 -$pid = getpid(); +echo $$ > $3 -open(PID, ">$pidfile"); -print PID $pid, "\n"; -close(PID); +/bin/cat $1 > $2.$$ +/bin/mv $2.$$ $2 -#system("logger -p user.err 'starting statuscpy'"); +/bin/rm -f $3 -RETRY: - -#print "1\n"; -#system("logger -p user.err 'statuscpy 1 '"); - -if (!open(BACKUP, ">$backup.tmp")) { - print "Can't open $backup.tmp\n"; - sleep(1); - goto RETRY; -} - -#print "2\n"; - -#system("logger -p user.err 'statuscpy 2 '"); - -if (!open(LOCK, "<$lock")) { - print "Can't open $lock\n"; - close(BACKUP); - sleep(1); - goto RETRY; -} - -#print "3\n"; -#system("logger -p user.err 'statuscpy 3 '"); - -#eval{ flock(LOCK, 1); }; -#if ($@){ -# print "Can't get lock\n"; -# close(BACKUP); -# close(LOCK); -# sleep(1); -# goto RETRY; -#} - -#print "4\n"; -#system("logger -p user.err 'statuscpy 4 '"); - -if (!open(STATUS, "<$status")) { - print "Can't open $status\n"; - close(BACKUP); - close(LOCK); - sleep(1); - goto RETRY; -} - -#print "5\n"; -#system("logger -p user.err 'statuscpy 5 '"); - -$oldhandle = select(BACKUP); -$| =1; -select($oldhandle); - -while(<STATUS>) { - if (!print(BACKUP $_)) { - print "Can't write $backup.tmp\n"; - close(BACKUP); - close(LOCK); - close(STATUS); - sleep(1); - goto RETRY; - } -} - -#system("logger -p user.err 'statuscpy 6 '"); - -close(STATUS); -close(LOCK); - -if (!rename("$backup.tmp", $backup)) { - print "Can't rename $backup\n"; - close(BACKUP); - sleep(1); - goto RETRY; -} - -#system("logger -p user.err 'statuscpy 7 '"); - -unlink($pidfile); - -#system("logger -p user.err 'statuscpy ended'"); - -exit(0);