#! /usr/bin/perl


###################################
# Script to shutdown servermgrd
# and DirectoryService to prevent a 
# resource leak on Tiger Server
#
# It checks the tail of the system.log
# if there are references to the
# "Potential VM" error then it restarts
# servermgrd and DirectoryServices
#
# David LeBer
# Pimedia Inc.
# February 3, 2006
###################################

$log = `tail /var/log/system.log | grep "Potential VM"`;
logthis("Checking logs");
if ($log) {
    logthis("Found that damn Pot. VM notice in the log, killing services");
    killservices();
} else {
    logthis("Everything looks good, no killing required");
}

sub killservices {
    `killall -HUP servermgrd`;
    `killall -9 DirectoryService`;
}

sub logthis() {
        `/usr/bin/logger -p local7.notice -t "PIMEDIA_PLUGLEAK" @_[0]`;
}
