382 lines
9.4 KiB
Plaintext
382 lines
9.4 KiB
Plaintext
#/bin/bash
|
|
|
|
if [ -z "$1" ]; then
|
|
echo "Missing Server Configuration File"
|
|
exit 1
|
|
fi
|
|
|
|
if [ "$1" == "--help" ]; then
|
|
echo "usage: "
|
|
echo "remoteMonitors <Configfile> <action>"
|
|
echo "<action> can be start, stop, or check"
|
|
echo "start starts the monitors"
|
|
echo "stop stops running monitors"
|
|
echo "check shows status of monitors"
|
|
echo "update updates secondo on remote server via CVS"
|
|
echo "createHomes creates secondo database directories on remote computers"
|
|
echo "copycfg copies configuration files to remote computers"
|
|
echo
|
|
echo "each line within the config file has to be in format"
|
|
echo "<server> <config> [<bin> [<home> [<port> [<user>]]]]"
|
|
echo ""
|
|
echo "<server> : the host name at that the monitor should run"
|
|
echo "<bin> : the bin directory of the Secondo to be started"
|
|
echo "<config> : configuration file to use, must be exist on server side"
|
|
echo "<home> : 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 "<port> : overwrite the monitor port specified in the configuration file"
|
|
echo " if not used, but later arguments should be set, use a dollar sign "
|
|
echo " as place holder"
|
|
echo "<user> : user which performs the command on the remote machine"
|
|
exit
|
|
fi
|
|
|
|
if [ -z "$2" ]; then
|
|
echo "second parameter missing "
|
|
exit 1;
|
|
fi
|
|
|
|
config=$1
|
|
action=$2
|
|
|
|
if [ $action != start ]; then
|
|
if [ $action != stop ]; then
|
|
if [ $action != check ]; then
|
|
if [ $action != update ]; then
|
|
if [ $action != createHomes ]; then
|
|
if [ $action != copycfg ]; then
|
|
echo "invalid action"
|
|
echo allowed are start, stop, update, and check
|
|
exit 1
|
|
fi
|
|
fi
|
|
fi
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
function createHomesLine {
|
|
if [ -z "$1" ]; then # empty line
|
|
return
|
|
fi
|
|
server=$1
|
|
home=$4
|
|
if [ -z "$home" ]; then
|
|
echo "no home specified for server $server"
|
|
return
|
|
fi
|
|
if [ -n "$6" ]; then
|
|
user="$6@"
|
|
fi
|
|
ssh "$user$server mkdir -p $home"
|
|
}
|
|
|
|
|
|
function copyConfigLine {
|
|
|
|
if [ -z "$1" ]; then # empty line
|
|
return
|
|
fi
|
|
server=$1
|
|
cfg=$2
|
|
bin=$3
|
|
if [ -z "$bin" ]; then
|
|
echo "no bin directory specified for server $server"
|
|
return
|
|
fi
|
|
if [ -n "$6" ]; then
|
|
user="$6@"
|
|
fi
|
|
scp $cfg $user$server:$bin
|
|
}
|
|
|
|
|
|
|
|
# global variable holding server values
|
|
# to avoid multiple update on a single server
|
|
usedServers=""
|
|
|
|
function updateLine {
|
|
if [ -z "$1" ]; then # empty line
|
|
return
|
|
fi
|
|
|
|
server=$1
|
|
if [ -n "$6" ]; then
|
|
user="$6@"
|
|
fi
|
|
|
|
secBin=$3;
|
|
|
|
|
|
|
|
# check whether server was already updatet
|
|
if [[ $usedServers == *"$server"* ]]; then
|
|
echo "Server $server already processed"
|
|
return
|
|
fi
|
|
echo "update server $server"
|
|
|
|
usedServers="$usedServers $server"
|
|
|
|
|
|
if [ -z "$3" ]; then
|
|
remotedir=$(ssh "$user$server" 'source $HOME/.bashrc; echo $SECONDO_BUILD_DIR')
|
|
else
|
|
remotedir=$3
|
|
fi
|
|
|
|
echo "remote SECONDO_BUILD_DIR= $remotedir"
|
|
|
|
if [ -z "$remotedir" ]; then
|
|
echo "cannot determine SECONDO_BUILD_DIR on server $server"
|
|
return
|
|
fi
|
|
|
|
# copy current makefile.algebras to remote server
|
|
scp $SECONDO_BUILD_DIR/makefile.algebras $user$server:$remotedir/
|
|
|
|
script=UpdateMonitortemp.sh
|
|
echo 'source $HOME/.bashrc' >$script
|
|
echo "cd $remotedir" >>$script
|
|
echo 'cvs update -PdA' >>$script
|
|
echo 'make' >> $script
|
|
echo >>$script
|
|
ssh $user$server 'bash -s' <$script
|
|
rm $script
|
|
echo "Server $server processed"
|
|
return
|
|
}
|
|
|
|
|
|
|
|
function startLine {
|
|
|
|
if [ -z "$1" ]; then # empty line
|
|
return
|
|
fi
|
|
if [ -z "$2" ]; then # empty line
|
|
echo "invalid format in line" $*
|
|
return
|
|
fi
|
|
|
|
server=$1
|
|
config=$2
|
|
|
|
if [ -n "$4" ]; then
|
|
if [ "$4" != "$" ]; then
|
|
home="-d $4"
|
|
fi
|
|
fi
|
|
|
|
if [ -n "$5" ]; then
|
|
if [ "$5" != "$" ]; then
|
|
port="-p $5"
|
|
fi
|
|
fi
|
|
|
|
if [ -n "$6" ]; then
|
|
user="$6@"
|
|
fi
|
|
|
|
script=runMonitortemp.sh
|
|
|
|
|
|
if [ -z "$3" ]; then
|
|
echo 'cd $HOME/secondo/bin' >$script
|
|
else
|
|
echo cd $3 >$script
|
|
fi
|
|
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=$5" >>$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 $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
|
|
if [ -z "$2" ]; then # at least server and config are required
|
|
echo "invalid format in line" $*
|
|
return
|
|
fi
|
|
|
|
server=$1
|
|
config=$2
|
|
|
|
if [ -n "$4" ]; then
|
|
if [ "$4" != "$" ]; then
|
|
home="$-d $4"
|
|
fi
|
|
fi
|
|
|
|
if [ -n "$5" ]; then
|
|
if [ "$5" != "$" ]; then
|
|
port="-p $5"
|
|
fi
|
|
fi
|
|
|
|
if [ -n "$6" ]; then
|
|
user="$6@"
|
|
fi
|
|
|
|
script=stopMonitortemp.sh
|
|
if [ -z "$3" ]; then
|
|
echo 'cd $HOME/secondo/bin' >$script
|
|
else
|
|
echo cd $3 >$script
|
|
fi
|
|
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=$5" >>$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
|
|
if [ -z "$2" ]; then # at least server and config are required
|
|
echo "invalid format in line" $*
|
|
return
|
|
fi
|
|
|
|
server=$1
|
|
config=$2
|
|
|
|
if [ -n "$4" ]; then
|
|
if [ "$4" != "$" ]; then
|
|
home="-d $4"
|
|
fi
|
|
fi
|
|
|
|
if [ -n "$5" ]; then
|
|
if [ "$5" != "$" ]; then
|
|
port="-p $5"
|
|
fi
|
|
fi
|
|
if [ -n "$6" ]; then
|
|
user="$6@"
|
|
fi
|
|
|
|
script=checkMonitortemp.sh
|
|
if [ -z "$3" ]; then
|
|
echo 'cd $HOME/secondo/bin' >$script
|
|
else
|
|
echo cd $3 >$script
|
|
fi
|
|
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=$5" >>$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 copyConfigLine $line; startLine $line ;done <$1
|
|
else if [ $action == stop ]; then
|
|
while read line; do stopLine $line ;done <$1
|
|
else if [ $action == check ]; then
|
|
while read line; do checkLine $line ;done <$1
|
|
else if [ $action == update ]; then
|
|
while read line; do updateLine $line ;done <$1
|
|
else if [ $action == copycfg ]; then
|
|
while read line; do copyConfigLine $line ;done <$1
|
|
else if [ $action == createHomes ]; then
|
|
while read line; do createHomesLine $line ;done <$1
|
|
else
|
|
echo "unknown command"
|
|
fi
|
|
fi
|
|
fi
|
|
fi
|
|
fi
|
|
fi
|