#!/usr/bin/perl require 5.002; use strict; use sigtrap; ################################################################ # prox_livetst # # restarts the proxy either when it's not running or # something wrong is happening with the proxy ################################################################ $ENV{PATH} = "$ENV{PATH}:/usr/bin:/bin"; my ($hostname, $res, $res1, $res2, $res3); `/bin/touch /tmp/timestamp`; # for checking chomp($hostname = `/bin/hostname`); chomp($res1 = `/bin/ps -A | /bin/grep prox\$ | /usr/bin/wc -l`); sleep(5); chomp($res2 = `/bin/ps -A | /bin/grep prox\$ | /usr/bin/wc -l`); sleep(5); chomp($res3 = `/bin/ps -A | /bin/grep prox\$ | /usr/bin/wc -l`); $res = $res1 + $res2 + $res3; # restart it if anything is wrong if ($res == 0) { print "$hostname : prox is dead, restarting the proxy\n"; open filename, '>> /home/princeton_codeen/exitlog'; my $now = localtime time; print filename "$now prox restarted by prox_livetst\n"; close filename; # start again `./prox_start < /dev/null >& /dev/null`; } else { print "$hostname: prox is live: num = $res \n"; # check getbig chomp($res = `/bin/ps -A | /bin/grep getbig\$ | /usr/bin/wc -l`); if ($res == 0) { print "$hostname : getbig is dead\n"; `./getbig_start < /dev/null >& /dev/null`; } }