#/bin/bash if [ -z "$1" ]; then echo "Missing Server Configuration File" exit 1 fi if [ "$1" == "--help" ]; then echo "usage: " echo "remoteMonitors " echo " can be start, stop, or check" echo "start starts the monitors" echo "stop stops running monitors" echo "check shows status of monitors" echo echo "each line within the config file has to be in format" echo " [ []]" echo echo " : one of MASTER or WORKER , lines starting with another token are ignored" echo " : a nice name for the server used by SecondoREPLAY" echo " : the host name at that the monitor should run" echo " : the port for the monitors, overwrites the setting in SecondoConfig.ini" echo " : number of cores, used by SecondoREPLAY only" echo " : configuration file to use, must be exist on server side" echo " : overwrite the database directory specified in the configuration file" echo " if not used, but later arguments should be set, use a dollar sign " echo " as place holder" echo " if not used, but later arguments should be set, use a dollar sign " echo " as place holder" echo " : user which performs the command on the remote machine" exit fi if [ -z "$2" ]; then echo "start, stop, or check as second parameter missing " exit 1; fi config=$1 action=$2 if [ $action != start ]; then if [ $action != stop ]; then if [ $action != check ]; then echo "invalid action" echo allowed are start, stop, and check exit 1 fi fi fi function startLine { if [ -z "$1" ]; then # empty line return fi kind=$1 if [ "$kind" != "MASTER" ]; then if [ "$kind" != "WORKER" ]; then return fi fi if [ -z "$6" ]; then # at least 6 arguments are required echo "invalid format in line" $* return fi server=$3 port=$4 config=$6 if [ -n "$7" ]; then if [ "$7" != "$" ]; then home="-d $7" fi fi if [ -n "$8" ]; then user="$8@" fi script=runMonitortemp.sh echo 'cd $HOME/secondo/bin' >$script echo 'source $HOME/.secondorc' >> $script echo export SECONDO_CONFIG=$config >>$script echo 'if [ ! -e $SECONDO_CONFIG ]; then' >>$script echo ' echo configuration file $SECONDO_CONFIG not found an server ' $server >>$script echo ' exit' >>$script echo 'fi' >>$script if [ -z "$port" ]; then echo 'port=$(grep ^SecondoPort ${SECONDO_CONFIG} | sed -e "s@SecondoPort=@@g" | sed -e "s@\s@@g")' >>$script else echo port=$port >>$script fi echo 'if [ -z "$TMPDIR" ]; then' >>$script echo ' export TMPDIR=/tmp' >>$script echo 'fi' >>$script echo 'tmpfile="$TMPDIR/SM_${port}.lck"' >>$script echo 'if [ -e $tmpfile ]; then' >>$script echo 'echo "SecondoMonitor already running on port ${port}"' >>$script echo 'exit 1' >>$script echo 'fi' >>$script echo "nohup ./SecondoMonitor -s $home -p $port -c $config >SecondoMonitor.log "'2>&1 &' >>$script echo 'pid=$!' >>$script echo 'echo $pid >$tmpfile' >>$script echo 'w=$(ps -p $pid | wc -l )' >>$script echo 'if [ "$w" == "2" ]; then' >>$script echo ' echo Monitor is running now at port $port' >>$script echo 'else' >>$script echo ' echo Could not start Monitor on port $port' >> $script echo ' rm $tmpfile' >>$script echo 'fi' >> $script echo Try to start monitor on server $server ssh $user$server 'bash -s' <$script rm $script } function stopLine { if [ -z "$1" ]; then # empty line return fi kind=$1 if [ "$kind" != "MASTER" ]; then if [ "$kind" != "WORKER" ]; then return fi fi if [ -z "$6" ]; then # at least 6 arguments are required echo "invalid format in line" $* return fi server=$3 port=$4 config=$6 if [ -n "$7" ]; then if [ "$7" != "$" ]; then home="-d $7" fi fi if [ -n "$8" ]; then user="$8@" fi script=stopMonitortemp.sh echo 'cd $HOME/secondo/bin' >$script echo export SECONDO_CONFIG=$config >>$script echo 'if [ ! -e $SECONDO_CONFIG ]; then' >>$script echo ' echo configuration file $SECONDO_CONFIG not found an server ' $server >>$script echo ' exit' >>$script echo 'fi' >>$script if [ -z "$port" ]; then echo 'port=$(grep ^SecondoPort ${SECONDO_CONFIG} | sed -e "s@SecondoPort=@@g" | sed -e "s@\s@@g")' >>$script else echo port=$port >>$script fi echo 'if [ -z "$TMPDIR" ]; then' >>$script echo ' export TMPDIR=/tmp' >>$script echo 'fi' >>$script echo 'tmpfile="$TMPDIR/SM_${port}.lck"' >>$script echo 'if [ ! -e $tmpfile ]; then' >>$script echo 'echo "SecondoMonitor not running on port ${port}"' >>$script echo 'exit 1' >>$script echo 'fi' >>$script echo 'pid=$(cat $tmpfile)' >>$script echo 'gid=$(ps -p $pid -o pgid | sed -e "s@[a-zA-Z]@@g" )' >>$script echo 'gid=$(echo $gid | sed -e "s@\s@@g")' >>$script echo 'if [ -n "$gid" ]; then' >>$script echo 'kill -9 -$gid' >>$script echo 'fi' >>$script echo 'rm $tmpfile' >>$script echo Try to stop monitor on server $server ssh $user$server 'bash -s' <$script rm $script } function checkLine { if [ -z "$1" ]; then # empty line return fi kind=$1 if [ "$kind" != "MASTER" ]; then if [ "$kind" != "WORKER" ]; then return fi fi if [ -z "$6" ]; then # at least 6 arguments are required echo "invalid format in line" $* return fi server=$3 port=$4 config=$6 if [ -n "$7" ]; then if [ "$7" != "$" ]; then home="-d $7" fi fi if [ -n "$8" ]; then user="$8@" fi script=checkMonitortemp.sh echo 'cd $HOME/secondo/bin' >$script echo export SECONDO_CONFIG=$config >>$script echo 'if [ ! -e $SECONDO_CONFIG ]; then' >>$script echo ' echo configuration file $SECONDO_CONFIG not found on server ' $server >>$script echo ' exit' >>$script echo 'fi' >>$script if [ -z "$port" ]; then echo 'port=$(grep ^SecondoPort ${SECONDO_CONFIG} | sed -e "s@SecondoPort=@@g" | sed -e "s@\s@@g")' >>$script else echo port=$port >>$script fi echo 'if [ -z "$TMPDIR" ]; then' >>$script echo ' export TMPDIR=/tmp' >>$script echo 'fi' >>$script echo 'tmpfile="$TMPDIR/SM_${port}.lck"' >>$script echo 'if [ ! -e $tmpfile ]; then' >>$script echo 'echo "SecondoMonitor not running on port ${port} at " ' $server >>$script echo 'exit 1' >>$script echo 'fi' >>$script echo 'pid=$(cat $tmpfile)' >>$script echo 'x=$(ps -p $pid | wc -l)' >>$script echo 'if [ "$x" == "2" ]; then ' >>$script echo ' echo Monitor is running on port $port at ' $server >> $script echo "else " >>$script echo " echo Monitor should run but is not active, delete runnning marker" >> $script echo ' rm $tmpfile' >>$script echo "fi" >>$script echo Try to check monitor on server $server ssh $user$server 'bash -s' <$script rm $script } if [ $action == start ]; then while read line; do startLine $line ;done <$1 else if [ $action == stop ]; then while read line; do stopLine $line ;done <$1 else while read line; do checkLine $line ;done <$1 fi fi