#!/bin/sh # # Example of NSTX system script started by the "batch watching" script, nstx # # NAME: # /usr/pppl/bin/efitdb # # PURPOSE: # start, stop, or return status of a script for loading EFIT database. # The sentry script wants a "0" returned from the "efitdb status" command. # For this program, 4 processes need to be running for things to be OK. # # USE: # efitdb restart (stops all efitdb jobs and then starts them) # efitdb status -v (returns PIDs of any running efitdb processes) # # NOTES: # # This script can be invoked with 4 parameters: start, stop, status and restart # # The /usr/pppl/bin/sentry program monitors these programs every 5 minutes # and restarts them, if necessary. # # $0 in this script is the name of the script # # MODIFICATION HISTORY: # # 4-Oct-2004 Generalized and documented by Bill Davis # Written June, 2004 by Dana Mastrovito # DIR=/usr/pppl/bin/db PGM=efitdb case "$1" in start) echo "" echo "Starting Efit Database Job: " su - nstxops -c $DIR/$PGM.cron exit 0 ;; stop) if [ "$2" ]; then echo "" echo -n "Shutting down Efit Database Jobs: " fi idlchildren=`/bin/ps -awef | /bin/fgrep $PGM | /bin/fgrep idl | /bin/awk '{print $2}'` su - nstxops -c "kill -9 ${idlchildren}" if [ "$2" ]; then echo killed ${idlchildren} fi exit 0 ;; status) idlchildren=`/bin/ps -awef | /bin/fgrep $PGM | /bin/fgrep idl | /bin/awk '{print $2}'` numproc=`echo ${idlchildren} | wc -w` if [ "$2" ]; then echo idl children ${idlchildren} fi if [ "${numproc}" -ge "4" ]; then exit 0 else exit 1 fi exit 1 ;; restart) $0 stop $2 $0 start $2 exit 0 ;; *) echo "Usage: efitdb {start|stop|restart|status}" exit 1 esac