#!/bin/sh # Copyrights : CNRS # Author : Oleg Lodygensky # Acknowledgment : XtremWeb-HEP is based on XtremWeb 1.8.0 by inria : http://www.xtremweb.net/ # Web : http://www.xtremweb-hep.org # # This file is part of XtremWeb-HEP. # # XtremWeb-HEP is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # XtremWeb-HEP is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with XtremWeb-HEP. If not, see . # # # # # File : xtremweb.ganglia # # Purpose : This starts.stop xtremweb ganglia daemon # # Params : [start | stop | restart] # # chkconfig: 345 99 99 # description: XWHEP DesktopGrid monitoring element PERLSCRIPTNAME="xtremweb.gmond.pl" ###################################################### # This starts xtremweb part as daemon # return : 0 on success # 3 if already running ###################################################### start () { if [ ! -f $PIFILE ] ; then echo "$PROG is already running" return fi if [ -f $LOGFILE ]; then mv -f $LOGFILE $LOGBAKFILE fi touch $LOGFILE chown $XWUSER $LOGFILE # # Try to determine SU usage... # SU="" MINUS="" su -l $XWUSER -c exit > /dev/null 2>& 1 if ( [ $? -eq 0 ] ); then SU="su - -l $XWUSER" else su $XWUSER -c exit - > /dev/null 2>&1 if ( [ $? -eq 0 ] ); then SU="su - $XWUSER" MINUS=" -" else echo "Can't determine SU usage :(" return $ERRUSER fi fi echo "`date` [`uname -n` $PROG] INFO : starting $PROG" >> $LOGFILE # # Try to determine default shell for user $XWUSER # USHELL="unknown" # $SU "ps -o '%c'" | grep -E "^bash|^sh|^ksh|^zsh" # [ $? -eq 0 ] && USHELL="sh" # $SU "ps -o '%c'" | grep -E "^[t]csh" # [ $? -eq 0 ] && USHELL="csh" [ -x /bin/ksh ] && USHELL="/bin/ksh" [ -x /bin/zsh ] && USHELL="/bin/zsh" [ -x /bin/csh ] && USHELL="/bin/csh" [ -x /bin/tcsh ] && USHELL="/bin/tcsh" [ -x /bin/sh ] && USHELL="/bin/sh" [ -x /bin/bash ] && USHELL="/bin/bash" SU="$SU -s $USHELL -c" case $USHELL in "/bin/sh"|"/bin/bash"|"/bin/ksh"|"/bin/zsh" ) echo "$SU $ROOTDIR/bin/$PERLSCRIPTNAME $* >> $LOGFILE 2>&1 & $MINUS" $SU "$ROOTDIR/bin/$PERLSCRIPTNAME $* >> $LOGFILE 2>&1 & $MINUS" ;; "/bin/csh"|"/bin/tcsh" ) echo "$ROOTDIR/bin/$PERLSCRIPTNAME $* >>& $LOGFILE & $MINUS" $SU "$ROOTDIR/bin/$PERLSCRIPTNAME $* >>& $LOGFILE & $MINUS" ;; "unknown" ) echo "Can't find any shell :(" return $ERRUSER ;; esac PID=`ps auxwww | grep $PERLSCRIPTNAME | grep $XWUSER | grep -v grep | sed "s/[[:space:]][[:space:]]*/ /g" | cut -d " " -f 2` if [ "X$PID" = "X" ] ; then echo "$PROG : launch error" echo "[`date`] $PROG : launch error" >> $LOGFILE return $ERRSTATE fi [ "X$LOGGERLEVEL" = "Xdebug" ] && echo "$PID => $PIDFILE" echo $PID > $PIDFILE echo "$PROG started" } # # This stops xtremweb part # return : 0 on success # 3 if not running # stop(){ MYPID=$$ echo "`date` [`uname -n` $PROG] INFO : stopping" >> $LOGFILE if [ ! -f $PIDFILE ]; then echo "`date` [`uname -n` $PROG] ERROR : $PROG not running : can't stop ($PIDFILE not found)" >> $LOGFILE RETVAL=$ERRSTATE return $RETVAL fi # JOBSPID=`ps auxwww | grep '$PROG' | grep -v grep | grep -v stop | sed "s/[[:space:]][[:space:]]*/ /g" | cut -d " " -f 2` # for i in $JOBSPID; do # [ $i -eq $MYPID ] && continue # kill -9 $i >> $LOGFILE 2>&1 ## if [ $? -ne 0 ]; then ## echo "`date` [`uname -n` $PROG] ERROR : $PROG not running : can't stop (can't signal process)" >> $LOGFILE ## RETVAL=$ERRSTATE ## return $RETVAL ## fi # done # # process ids # PIDS="" # # parent process ids # PPIDS="" PPIDSTMP="/tmp/xw.$TMPNAME.ppids" PIDSTMP="/tmp/xw.$TMPNAME.pids" rm -f $PPIDSTMP rm -f $PIDSTMP # # retreive parent process ids # ps -fwww -u xwhep | grep $PERLSCRIPTNAME | grep -v grep | grep -v stop| while read user pid ppid cmd do rm -f $PPIDSTMP [ "X$PPIDS" = "X" ] && PPIDS=$pid && echo $PPIDS > $PPIDSTMP [ "X$ppid" = "X1" ] && continue # echo $user $pid $ppid $cmd PPIDS="$PPIDS $ppid" # echo POUET # echo $PPIDS | grep $pid echo $PPIDS | grep $pid > /dev/null [ $? -ne 0 ] && PPIDS="$PPIDS $pid" echo "$PPIDS" > $PPIDSTMP done # # retreive process ids # # PPIDS=`cat $PPIDSTMP` # echo "PPIDS=$PPIDS" ps -f -u xwhep | while read user pid ppid cmd do PP_FOUND=0 for i in `cat $PPIDSTMP` ; do if [ $i = $ppid ] ; then PP_FOUND=1 break fi done [ $PP_FOUND -eq 0 ] && continue rm -f $PIDSTMP PIDS="$PIDS $pid" echo "$PIDS" > $PIDSTMP done for i in `cat $PIDSTMP $PPIDSTMP` ; do echo "`date` [`uname -n` $PROG] INFO : kill -9 $i " >> $LOGFILE 2>&1 kill -9 $i >> $LOGFILE 2>&1 done rm -f $PPIDSTMP rm -f $PIDSTMP rm -f $LOCKFILE rm -f $PIDFILE echo "`date` [`uname -n` $PROG] INFO : stopped" >> $LOGFILE return $ERROK } ###################################################### # This restarts xtremweb part ###################################################### restart(){ stop start } ###################################################### # This retreives the status # return : always 0 ###################################################### status(){ if [ ! -f $PIFILE ] ; then echo "$PROG is running" else echo "$PROG is not running" fi } ###################################################### # Main ###################################################### # # resolve symlinks # PRG=$0 while [ -h "$PRG" ]; do ls=`ls -ld "$PRG"` link=`expr "$ls" : '^.*-> \(.*\)$' 2>/dev/null` if expr "$link" : '^/' 2> /dev/null >/dev/null; then PRG="$link" else PRG="`dirname $PRG`/$link" fi done progdir=`dirname $PRG` progname=`basename $0` # # loading default values # # force it otherwise $progname may contain S99xtremweb.ganglia (e.g. if linked from /etc/rc3.d/S99xtremweb.ganglia") PROG="xtremweb.ganglia" #PROG=$progname currentDir=`pwd` cd $progdir ROOTDIR=`pwd`/.. cd $currentDir #ROOTDIR="$progdir/.." #[ "$ROOTDIR" = "./.." ] && ROOTDIR=`pwd`/.. #[ "$ROOTDIR" = "." ] && ROOTDIR=`pwd` #[ "$ROOTDIR" = "./" ] && ROOTDIR=`pwd` . $ROOTDIR/bin/xtremwebconf.sh > /dev/null 2>&1 LOGFILE=/tmp/$PROG-$HOST.log [ "X$PROG" = "Xxtremweb.client" ] && LOGFILE=$SCRATCH/$PROG-$USER.log LOGBAKFILE=$LOGFILE.bak mv -f $LOGFILE $LOGBAKFILE touch $LOGFILE # # Parse command line parameters # case "$ACTION" in start) start $* ;; status) status exit 0 ;; stop) stop ;; restart) restart $* ;; *) echo "Usage : $0 {start | stop | restart | status}" esac # # End of file #