瀏覽代碼

fixes #89 Added which_pidof function and usage.

Added which_pidof function to hpcc_common along with its usage where
ever pidof was called.

Updated which_service to follow the same format as which_pidof using
the command on the users path before using a direct path.

Signed-off-by: Philip Schwartz <philip.schwartz@lexisnexis.com>
Philip Schwartz 14 年之前
父節點
當前提交
c78c06c942

+ 24 - 8
initfiles/bash/etc/init.d/hpcc_common.in

@@ -15,6 +15,30 @@
 
 ###<REPLACE>###
 
+which_service(){
+    SERV=`which service`
+    if [ "${SERV}" == "" ]; then
+        if [ -e "/sbin/service" ]; then
+            SERV=/sbin/service
+        elif [ -e "/usr/sbin/service" ]; then
+            SERV=/usr/sbin/service
+        fi
+    fi
+}
+
+which_pidof(){
+    PIDOF=`which pidof`
+    if [ "${PIDOF}" == "" ]; then
+        if [ -e /bin/pidof ]; then
+	    PIDOF=/bin/pidof
+	elif [ -e /sbin/pidof  ]; then
+            PIDOF=/sbin/pidof
+        elif [ -e /usr/sbin/pidof ]; then
+            PIDOF=/usr/sbin/pidof
+        fi
+    fi
+}
+
 source  ${INSTALL_DIR}/etc/init.d/lock.sh
 source  ${INSTALL_DIR}/etc/init.d/pid.sh
 source  ${INSTALL_DIR}/etc/init.d/init-functions
@@ -552,14 +576,6 @@ stop_component() {
     return ${RCSTOP}
 }
 
-which_service(){
-    if [ -e "/sbin/service" ]; then
-        SERV=/sbin/service
-    elif [ -e "/usr/sbin/service" ]; then
-        SERV=/usr/sbin/service
-    fi
-}
-
 
 #--------------------------------------------------------------------------------
 #                        Component Specific Functions                            

+ 3 - 2
initfiles/bash/etc/init.d/init-functions

@@ -59,9 +59,10 @@ pidofproc () {
             fi
         fi
     fi
-    if [ -x /bin/pidof -a ! "$specified" ]; then
+    which_pidof
+    if [ -x ${PIDOF} -a ! "$specified" ]; then
         status="0"
-        /bin/pidof -o %PPID -x $1 || status="$?"
+        ${PIDOF} -o %PPID -x $1 || status="$?"
         if [ "$status" = 1 ]; then
             return 3 # program is not running
         fi

+ 7 - 2
initfiles/bin/init_sasha

@@ -5,23 +5,28 @@ PATH_PRE=`type -path hpcc_setenv`
 source ${PATH_PRE}
 PID_NAME="$PID/`basename $PWD`.pid"
 
+INSTALL_DIR=`dirname ${PATH_PRE}`/..
+source  ${INSTALL_DIR}/etc/init.d/hpcc_common
+
 INIT_PID_NAME="$PID/init_`basename $PWD`.pid"
 echo $$ > $INIT_PID_NAME
 
 ulimit -c unlimited
 ulimit -n 8192
 
+which_pidof
+
 killed() {
 
     rm -f saserver_sentinel*.txt
-    pid=`pidof saserver`
+    pid=`${PIDOF} saserver`
     if [ -n "$pid" ]; then
         sasha server=. action=stop
         I=1
         while [ -n "$pid" ] && [ $I -lt 30 ]; do
             echo "Waiting for saserver to stop"
             sleep 2
-            pid=`pidof saserver`
+            pid=`${PIDOF} saserver`
             let I=I+1
         
         done

+ 5 - 2
initfiles/componentfiles/thor/start_backupnode.in

@@ -18,12 +18,15 @@
 
 ###<REPLACE>###
 
+source  ${INSTALL_DIR}/etc/init.d/hpcc_common
+which_pidof
+
 if [ $# -lt 1 ]; then
     echo usage: $0 thorinstance 
     exit 1
 fi
 
-pid=`pidof backupnode`
+pid=`${PIDOF} backupnode`
 if [ -n "$pid" ]; then
    echo stopping previous backupnode processes $pid
    killall backupnode
@@ -84,7 +87,7 @@ echo ------------------------------ >> $LOGFILE
 echo Waiting for backup to complete >> $LOGFILE
 
 nohup backupnode -W $DEPLOY_DIR/slaves $DEPLOY_DIR/last_backup >> $LOGFILE &
-pid=`pidof backupnode`
+pid=`${PIDOF} backupnode`
 trap "echo start_backupnode exiting, backupnode process $pid still continuing; exit 0" 2
 if [ -n "$pid" ]; then
   tail --pid $pid -f $LOGFILE 2>nul

+ 5 - 1
initfiles/componentfiles/thor/start_slave

@@ -16,6 +16,10 @@ hpcc_setenv=$7
 source ${hpcc_setenv}
 PID_NAME="$PID/${hpcc_compname}_slave.pid"
 
+INSTALL_DIR=`dirname ${hpcc_setenv}`/..
+source  ${INSTALL_DIR}/etc/init.d/hpcc_common
+which_pidof
+
 if [ $# -lt 7 ]; then
   echo usage: $0 thordeploydir slaveno logdir workingdir slaveport hpcc_compname hpcc_setenv
   exit 1
@@ -65,7 +69,7 @@ ulimit -n 8192
 
 if [ "$multislaves" != "true" ] && [ "$localthor" != "true" ]; then
     # kill stubborn slave
-    oldpid=`pidof $slaveproc`
+    oldpid=`${PIDOF} $slaveproc`
     if [ -n "$oldpid" ]; then
       # used hard kill as don't want unregistering
       echo killing pid $oldpid $slaveproc

+ 6 - 1
initfiles/componentfiles/thor/stop_thor

@@ -3,6 +3,11 @@
 ## Copyright © 2011 HPCC Systems.  All rights reserved.
 ################################################################################
 
+PATH_PRE=`type -path hpcc_setenv`
+INSTALL_DIR=`dirname ${PATH_PRE}`/..
+source  ${INSTALL_DIR}/etc/init.d/hpcc_common
+
+which_pidof
 
 if [ $# -lt 1 ]; then
     echo usage: $0 thordeploydir 
@@ -24,7 +29,7 @@ if [ "$#" -lt "2" ] || [ "$2" != "keep_sentinel" ]; then
     sleep 1
 fi
 
-while [ "`pidof thormaster_$THORMASTERPORT`" != "" ]
+while [ "`${PIDOF} thormaster_$THORMASTERPORT`" != "" ]
 do
   echo --------------------------
   echo stopping thormaster $THORMASTER