113 lines
3.5 KiB
Bash
113 lines
3.5 KiB
Bash
#!/bin/bash
|
|
|
|
bin=`dirname "$0"`
|
|
bin=`cd "$bin"; pwd`
|
|
source $bin/ps-functions
|
|
|
|
# Process the parameters
|
|
declare -i numOfArgs=$#
|
|
let numOfArgs++
|
|
PFOPT=false
|
|
while [ $numOfArgs -ne $OPTIND ]; do
|
|
|
|
getopts "hop" optKey
|
|
if [ "$optKey" == "?" ]; then
|
|
optKey="h"
|
|
fi
|
|
|
|
case $optKey in
|
|
h) echo -en "\nUsage of ${0##*/}:\n\n"
|
|
echo -en "Start the Secondo Monitors on the current node.\n\n"
|
|
echo -en " -h Print this message and exit. \n\n"
|
|
echo -en " -o Start a mini Secondo based on Own configuration \n"
|
|
echo -en " $HOME/.parasecrc \n\n"
|
|
echo -en " -p Profile the Monitors by Valgrind.\n\n"
|
|
exit 0;;
|
|
o)
|
|
if [ ! -f "$HOME/.parasecrc" ]; then
|
|
echo -e "The local parallel secondo configuration $HOME/.parasecrc doesn't exist." >&2
|
|
exit -1;
|
|
else
|
|
source $HOME/.parasecrc
|
|
fi
|
|
;;
|
|
p)
|
|
PFOPT=true
|
|
;;
|
|
esac
|
|
done
|
|
|
|
MSCNT=0 #Monitor Screen Counter
|
|
declare -i SMCNT=0 #Started Secondo Monitor Counter
|
|
declare -a MSECARR=($(echo $PARALLEL_SECONDO | tr ':' ' '))
|
|
for MINISEC in ${MSECARR[*]}; do
|
|
MINISEC="${MINISEC}/${PARALLEL_SECONDO_DATASERVER_NAME}/${PARALLEL_SECONDO_MINI_NAME}"
|
|
CONFFILE="${MINISEC}/bin/SecondoConfig.ini"
|
|
SCRNAME="secmon${MSCNT}"
|
|
let MSCNT++
|
|
if [ ! -f $CONFFILE ]; then
|
|
echo "Error! The Secondo Configure File $CONFFILE doesn't exist. "
|
|
continue
|
|
fi
|
|
|
|
# Create a temporal file to record the configuration file path
|
|
# In case another user also trying to use this configuration to start up Monitors
|
|
# The file will be deleted after the monitor is shutdown,
|
|
# and the relative REGISTER file of SecondoMonitor also will be deleted.
|
|
# File's name is SECMON_$secPort, records $HOSTNAME:$SCRNAME
|
|
LFNAME="/tmp/SECMON_$(get_secPort $CONFFILE)"
|
|
if [ -f $LFNAME ]; then
|
|
SMUSER=$(cat $LFNAME)
|
|
SMUSER=${SMUSER%:*}
|
|
echo -en "Error! A Secondo Monitor is started up by $SMUSER \nbased on $CONFFILE \nstop it first.\n\n" >&2
|
|
continue
|
|
fi
|
|
|
|
#Check whether the port is free
|
|
PORTNUM=$(get_secPort "$CONFFILE")
|
|
isFree=$(isPortAvailable "$PORTNUM")
|
|
|
|
if [ ! $isFree ]; then
|
|
echo -en "Error! The Secondo Monitor in ${MINISEC} start FAIL!\n" >&2
|
|
echo -en "The listening port $PORTNUM in $CONFFILE is busy.\n\n" >&2
|
|
continue
|
|
fi
|
|
|
|
sin=$(screen -ls | grep "$SCRNAME" | grep Detached | wc -l)
|
|
if [ $sin -gt 0 ]; then
|
|
echo "Error! Screen session with name $SCRNAME already exists"
|
|
continue
|
|
fi
|
|
|
|
screen -dmS $SCRNAME
|
|
sid_TTY=$(get_scrID ${SCRNAME})
|
|
if [ "$sid_TTY" != "" ]; then
|
|
exec_scr_commands ${sid_TTY} "cd \$HOME"
|
|
if [ "$SECONDO_PLATFORM" = "mac_osx" ]; then
|
|
exec_scr_commands ${sid_TTY} "source .profile"
|
|
fi
|
|
if [ $PFOPT = false ]; then
|
|
exec_scr_commands ${sid_TTY} "export SECONDO_CONFIG=${CONFFILE}" "cd ${MINISEC}/bin" "./collectFlobServer &" "./SecondoMonitor -s"
|
|
else
|
|
exec_scr_commands ${sid_TTY} "export SECONDO_CONFIG=${CONFFILE}" "cd ${MINISEC}/bin" "./collectFlobServer &" "valgrind --tool=callgrind --dump-instr=yes --trace-jump=yes --trace-children=yes SecondoMoni
|
|
tor -s"
|
|
fi
|
|
|
|
echo "$USER:$SCRNAME@$sid_TTY" > "$LFNAME"
|
|
let SMCNT++
|
|
# not check whether the monistor is correctly started, as it always need several seconds to finish the whole operation.
|
|
else
|
|
echo "Error! Screen $SCRNAME start up fail"
|
|
fi
|
|
done
|
|
|
|
LIP=$(get_localIP)
|
|
if [ ${SMCNT} -le 0 -o ${SMCNT} -ne ${MSCNT} ]; then
|
|
echo "ERROR! $LIP Start up ${SMCNT} Secondo Monitor Screens, expect ${MSCNT} Monitors." >&2
|
|
exit -1
|
|
else
|
|
echo "The Secondo Monitor on $LIP is started"
|
|
fi
|
|
|
|
exit 0
|