#!/bin/bash if [[ "$1" == "-version" || "$1" == "-v" || "$1" == "--version" ]] ; then echo "DABC version 1.9" exit 0 fi if [[ "$1" == "" || "$1" == "?" || "$1" == "-help" || "$1" == "-h" || "$1" == "/?" ]] ; then echo "Usage: dabc_run filename.xml [run|start|stop|copy|test|kill|dellog] [-node N] [-v|-verbose]" echo " filename.xml - xml file with application(s) configuration " echo "Run options: " echo " start - only start application [default]" echo " run - start, initialize and run application" echo " test - test content of xml file, check if login on specified node" echo " is allowed, test if run directory exists" echo " stop - stop running application, emulates Ctrl-C" echo " kill - kill running application, using kill command" echo " getlog - copy all individual logfiles to current node (be aware of different log file names)" echo " dellog - delete log files" echo " copycfg - distribute config files over the nodes" echo "Other options: " echo " -node N - perform operation only for specified node" echo " -from NUM - launch from (including) NUM node" echo " -to NUM - launch up to (including) NUM node" echo " -verbose - provide output of all commands, applied by script" echo " -parallel N - launch dabc application from N parallel scripts" exit 0 fi XMLFILE=$1 shift if [ ! -f $XMLFILE ] ; then echo "file $XMLFILE not exists"; exit 1; fi VERBOSE=false RUNMODE=start SELECTNODE=-1 MAXNODE=-1 MINNODE=0 PARALLEL=-1 SILENT=0 NUMARGS=0 while [[ "x$1" != "x" ]] ; do if [[ "$1" == "-v" || "$1" == "-verbose" || "$1" == "--verbose" ]] ; then VERBOSE=true elif [[ "$1" == "-multi" || "$1" == "-parallel" ]] ; then PARALLEL=$2 shift if [[ "x$PARALLEL" == "x" ]] ; then PARALLEL=0; fi elif [[ "$1" == "-node" ]] ; then MINNODE=$2 MAXNODE=$2 shift elif [[ "$1" == "-from" || "$1" == "-min" ]] ; then MINNODE=$2 shift elif [[ "$1" == "-to" || "$1" == "-max" ]] ; then MAXNODE=$2 shift elif [[ "$1" == "-silent" ]] ; then SILENT=1 else RUNMODE=$1 fi shift NUMARGS=$((NUMARGS+1)) done if [[ "$RUNMODE" != "run" && "$RUNMODE" != "start" && "$RUNMODE" != "stop" && "$RUNMODE" != "test" && "$RUNMODE" != "copycfg" && "$RUNMODE" != "kill" && "$RUNMODE" != "getlog" && "$RUNMODE" != "dellog" && "$RUNMODE" != "" ]] ; then echo Wrong running mode = $RUNMODE selected, using test RUNMODE=test fi curdir=`pwd` if [[ "x$DABCSYS" == "x" ]] ; then DABCSYS=$curdir; echo DABCSYS not specified, use current dir $DABCSYS; fi if [[ -f $DABCSYS/bin/dabc_xml ]] ; then dabc_xml=$DABCSYS/bin/dabc_xml else dabc_xml=`which dabc_xml` fi if [[ ! -f $dabc_xml ]] ; then echo Cannot find dabc_xml executable; exit 1; fi if [[ -f $DABCSYS/bin/dabc_exe ]] ; then dabc_exe=$DABCSYS/bin/dabc_exe else dabc_exe=`which dabc_exe` fi if [[ ! -f $dabc_exe ]] ; then echo Cannot find dabc_exe executable; exit 1; fi if (( $MINNODE > $MAXNODE || $PARALLEL >=0 )) ; then numnodes=`$dabc_xml $XMLFILE -number` retval=$? if [ $retval -ne 0 ]; then echo Cannot identify number of nodes in $XMLFILE - ret = $retval syntax error? exit $retval fi if [[ "x$numnodes" == "x" || "$numnodes" == "0" ]] then echo "Internal error in dabc_run - cannot identify numnodes in $XMLFILE" exit 1 fi # if no addition arguments specified and xml file contains single node, run as it was before if [[ "$RUNMODE" == "" && "$NUMARGS" == "0" ]] then $dabc_exe $XMLFILE retval=$? exit $retval fi if (( $MAXNODE < 0 )) ; then MAXNODE=$(($numnodes-1)); fi if (( $MAXNODE >= $numnodes )) ; then echo "Wrong max node id $MAXNODE specified" exit 1 fi if (( $MINNODE > $MAXNODE )) ; then echo "Wrong min node id $MINNODE specified" exit 1 fi if (( $PARALLEL == 0 )) ; then if (( $numnodes > 100 )) ; then PARALLEL=8; else PARALLEL=4; fi elif (( $PARALLEL >= $numnodes/4 )) ; then $PARALLEL = $numnodes/4 fi if (( $numnodes < 4 )) ; then PARALLEL=-1; fi fi if (( $SILENT!=1 )) ; then echo "Shell script to run dabc application" if (( $MINNODE == $MAXNODE )) ; then selstr=" node:$MAXNODE"; else selstr=" nodes:[$MINNODE..$MAXNODE]"; fi echo "Run mode:$RUNMODE $selstr verbose:$VERBOSE" fi ################################################################ # populate run.sh script for parallel execution (when specified) ################################################################ if (( $PARALLEL > 0 )) ; then LAST=$((MINNODE-1)) for (( cnt=0; cnt