#!/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.monitor # Author : Oleg Lodygensky # Date : Feb, 23rd 2006 # Purpose : This starts.stop xtremweb.monitor.pl # # Params : [start | stop | restart] # # chkconfig: 345 99 99 # description: XWHEP worker monitoring element # If XWHEP process takes more than 90% of memory (RAM + Swap) processes are killed ###################################################### # 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 # # 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 [ -f $LOGFILE ] && mv $LOGFILE $LOGFILE".bak" touch $LOGFILE echo "`date` [`uname -n` $PROG] INFO : starting $PROG" >> $LOGFILE chown $XWUSER $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" [ "X$LOGGERLEVEL" = "Xdebug" ] && echo "$SU $ROOTDIR/bin/xtremweb.monitor.pl >> $LOGFILE 2>&1 &" # $SU "$ROOTDIR/bin/xtremweb.gmond.pl >> /dev/null 2>&1 &" case $USHELL in "/bin/sh"|"/bin/bash"|"/bin/ksh"|"/bin/zsh" ) $SU "$ROOTDIR/bin/xtremweb.monitor.pl >> $LOGFILE 2>&1 & $MINUS" ;; "/bin/csh"|"/bin/tcsh" ) $SU "$ROOTDIR/bin/xtremweb.monitor.pl >>& $LOGFILE & $MINUS" ;; "unknown" ) echo "Can't find any shell :(" return $ERRUSER ;; esac PID=`ps auxwww | grep xtremweb.monitor.pl | 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(){ kill -9 `cat $PIDFILE` > /dev/null 2>&1 rm -f $PIDFILE echo "$PROG stopped" } ###################################################### # This restarts xtremweb part ###################################################### restart(){ stop start } ###################################################### # This retreives the status # return : always 0 ###################################################### status(){ ls -l $PIDFILE > /dev/null 2>&1 if [ $? -eq 0 ] ; 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 # PROG=$progname #ROOTDIR="$progdir/.." #[ "$ROOTDIR" = "./.." ] && ROOTDIR=`pwd`/.. currentDir=`pwd` cd $progdir ROOTDIR=`pwd`/.. cd $currentDir . $ROOTDIR/bin/xtremwebconf.sh > /dev/null 2>&1 # # 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 #