Back Midas Rome Roody Rootana
  Midas DAQ System  Not logged in ELOG logo
Message ID: 451     Entry time: 02 Mar 2008
Author: Exaos Lee 
Topic: Suggestion 
Subject: Bash Script for handling an experiment code 
I rearanged the files in "examples/experiment" as the attached "mtest_exp.zip". I re-write the start/stop script as the attached "daq.sh". The script "daq.sh" can be re-used for many experiments. The user only needs to provide an script "daq_env.sh" as the following containing the settings for the experiment environment.
#!/bin/sh

[ ! "$MIDASSYS" ] && MIDASSYS=/opt/MIDAS.PSI/Version/Current
[ ! "$HTTPPORT" ] && HTTPPORT=8080
[ ! "$SRVHOST" ]  && SRVHOST=localhost
LOGGER=${MIDASSYS}/bin/mlogger

EXPPATH=/home/das/online/test
CODEPATH=${EXPPATH}/code
LOGGER=${MIDASSYS}/bin/mlogger

PROG_FE=${CODEPATH}/frontend
PROG_ANA=${CODEPATH}/analyzer

if [ ! "$MIDAS_EXPTAB" ]; then
	MIDAS_DIR=${EXPPATH}
else
	MIDAS_EXPT_NAME="test"
fi


I hope this can be helpful. Smile There seem to be some problems such as:
1. When several experiments are defined, the $LOGGER may be not the one used for this exp.
2. The "pidof" may be not in some platforms, so this script is limited.

Hope anybody can help me to improve it for general purpose. All my best!
Attachment 1: daq.sh  2 kB  | Hide | Hide all | Show all
#!/bin/sh

DAQ_SETENV=./daq_env.sh

[ -f "${DAQ_SETENV}" ] && source ${DAQ_SETENV}

### Start ....
start() 
{
    #### Running mserver
    pidmsrv=`pidof mserver`
    if [ ! "$pidmsrv" ]; then
	echo Starting mserver ...
	$MIDASSYS/bin/mserver -D -m
	pidmhttpd=`pidof mhttpd`
	[ "$pidmhttpd" ] && kill -9 $pidmhttpd
	echo Starting mhttpd ...
	$MIDASSYS/bin/mhttpd -h localhost -D -p $HTTPPORT
    fi

    #### Change work directory
    OLD_DIR=`pwd`
    cd ${EXPPATH}
    
    #### Running FE and Analyzer ...

    # Options for multi experiments running ...
    [ "$MIDAS_EXPTAB" ] && OPTIONS="-e $MIDAS_EXPT_NAME"

    $MIDASSYS/bin/odbedit ${OPTIONS} -c clean

    sleep 2

    echo Starting frontend session: ${PROG_FE} ...
    ${PROG_FE}  ${OPTIONS} -D

    echo Starting analyzer session: ${PROG_ANA} ...
    ${PROG_ANA} ${OPTIONS} -D

    sleep 1

    echo Starting logger utility: mlogger ...
    ${LOGGER} ${OPTIONS} -D

    cat <<EOF
Please point your web browser to http://localhost:$HTTPPORT
Or run: firefox http://localhost:$HTTPPORT
To look at live histograms, run: roody -Hlocalhost

EOF

    #### Resume old directory
    cd ${OLD_DIR}
}

### Stop ....
stop() 
{
    #### Kill Running sessions
    pidlog=`pidof $(basename ${LOGGER})`
    pidfe=` pidof $(basename ${PROG_FE})`
    pidana=`pidof $(basename ${PROG_ANA})`
    [ "$pidlog" ] && kill $pidlog
    [ "$pidfe"  ] && kill $pidfe
    [ "$pidana" ] && kill $pidana
}

### Status ....
status()
{
    echo "MIDAS Server (mserver): "
    pid=`pidof mserver`
    echo_status $pid

    echo "MIDAS HTTPD Server (mhttpd): "
    pid=`pidof mhttpd`
    echo_status $pid

    echo "Logger (${LOGGER}): "
    pid=`pidof $(basename ${LOGGER})`
    echo_status $pid

    echo "Frontend Code ($PROG_FE): "
    pid=`pidof $(basename ${PROG_FE})`
    echo_status $pid

    echo "Analyzer Code ($PROG_ANA): "
    pid=`pidof $(basename ${PROG_ANA})`
    echo_status $pid
}

echo_status()
{
    if [ "$1" ]; then
	echo -e "\t Running as $1."
    else
	echo -e "\t Not Running!"
    fi
}

### Usage ....
usage()
{
    echo "Usage: $0 [<start>|<stop>|<restart>|<status>]"
}

###################### Main Procedure ###########################
case "${1:-''}" in 
    "start")
	start
	;;
    "stop")
	stop
	;;
    "restart")
	stop
	start
	;;
    "status")
	status
	;;
    *)
	usage
	;;
esac

#########################  The END  #############################
Attachment 2: mtest_exp.zip  15 kB
ELOG V3.1.4-2e1708b5