diff --git a/datamover/dist/datamover.start b/datamover/dist/datamover.start index 9d65f3845eda4fdd7fd50e9d5c9144cd4d71941a..19a6b0c2cef51edb42fbf0cb74448e807979d299 100755 --- a/datamover/dist/datamover.start +++ b/datamover/dist/datamover.start @@ -1,12 +1,47 @@ #! /bin/sh +awkBin() +{ + # We need a awk that accepts variable assignments with '-v' + case `uname -s` in + "SunOS") + echo "nawk" + return + ;; + esac + # default + echo "awk" +} + +isPIDRunning() +{ + if [ "$1" = "" ]; then + return 0 + fi + # This will have a return value of 0 on BSDish systems + isBSD="`ps aux > /dev/null 2>&1; echo $?`" + AWK=`awkBin` + if [ "$isBSD" = "0" ]; then + if [ "`ps aux | $AWK -v PID=$1 '{if ($2==PID) {print "FOUND"}}'`" = "FOUND" ]; then + return 0 + else + return 1 + fi + else + if [ "`ps -ef | $AWK -v PID=$1 '{if ($2==PID) {print "FOUND"}}'`" = "FOUND" ]; then + return 0 + else + return 1 + fi + fi +} + if [ -f datamover.pid ]; then PID=`cat datamover.pid` - if [ "$PID" != "" ]; then - if [ `ps -ef |grep $PID |grep -v grep|wc -l` = 1 ] ; then - kill $PID - echo "Already running - killing PID $PID and restarting" - fi + isPIDRunning $PID + if [ $? -eq 0 ]; then + kill $PID + echo "Already running - killing PID $PID and restarting" fi rm datamover.pid fi