Files
secondo/Algebras/Hadoop/clusterManagement/ps-cluster-uninstall
2026-01-23 17:03:45 +08:00

192 lines
5.5 KiB
Bash

#!/bin/bash
bin=`dirname "$0"`
bin=`cd "$bin"; pwd`
source $bin/ps-functions
# This script removes an installed parallel Secondo away from a computer cluster.
# Following environment variables must exist on nodes of the cluster.
# * PARALLEL_SECONDO_MASTER
# * PARALLEL_SECONDO_SLAVES
# * PARALLEL_SECONDO
# * PARALLEL_SECONDO_DATASERVER_NAME
# Following documents should be removed.
# * remove all data server pathes
# * remove .parasecrc file and the "source .parasecrc" line in .bashrc file from all slaves
# * remvoe ps_SDK folder in $SECONDO_BUILD_DIR
# * clean the SecondoConfig.ini file
# 0. Process the arguments.
WARNINFO="Warning !! "
ERRORINFO="ERROR !! "
PSDKLOC=$SECONDO_BUILD_DIR/bin/ps_SDK
SECCONF=$SECONDO_BUILD_DIR/bin/SecondoConfig.ini
DSLIST=$PSDKLOC/DSLIST.ui
IPLIST=$PSDKLOC/IPLIST.ui
RCFILENAME=".parasecrc"
### ----------------------------------------------------------------------------------------
# 1. Check the existence of all required environment variables
if [ "$PARALLEL_SECONDO_MASTER" = "" ]; then
echo "${ERRORINFO}No Parallel Secondo installed before."
echo "Uninstallation for Parallel Secondo Fails."
exit -1
fi
if [ ! -f $PARALLEL_SECONDO_MASTER -o ! -f $PARALLEL_SECONDO_SLAVES ]; then
echo "${ERRORINFO}Master or Slave list doesn't exist."
echo "Uninstallation for Parallel Secondo Fails."
exit -1
fi
if [ ! -d $HADOOP_HOME ]; then
echo "${ERRORINFO}Hadoop_Home is not available."
echo "Uninstallation for Parallel Secondo Fails."
exit -1
fi
if [ ! -d $PSDKLOC ]; then
echo "${WARNINFO}The installation SDK directory is deleted."
mkdir $PSDKLOC
if [ $? -ne 0 ]; then
# In case $SECONDO_BUILD_DIR doesn't exist.
echo "${ERRORINFO}Creation of SDK directory fails."
echo "Uninstallation for Parallel Secondo Fails."
exit -1
fi
fi
LIP=$(get_localIP)
MIP=$(cat $PARALLEL_SECONDO_MASTER | cut -d ':' -f1)
if [ "$LIP" != "$MIP" ]; then
echo "${ERRORINFO}The current node is not the master."
echo "Uninstallation for Parallel Secondo Fails."
exit -1
fi
# 2. Check there is no Hadoop or Secondo monitors running
JPNUM=$(jps -l | grep -v Jps | grep hadoop | wc -l)
if [ $JPNUM -gt 0 ]; then
echo "${WARNINFO}The Hadoop is running now, attempt to turn it off ... ... "
$HADOOP_HOME/bin/stop-all.sh
WTIME=5
HPON=true
while [ $WTIME -gt 0 ]; do
JPNUM=$(jps -l | grep -v Jps | grep hadoop | wc -l)
if [ $JPNUM -eq 0 ]; then
HPON=false
break
fi
let WTIME--
done
if $HPON ; then
echo "${ERRORINFO}The Hadoop cannot be turned off automatically."
echo "Uninstallation for Parallel Secondo Fails."
exit -1
fi
else
echo "No Hadoop deamons are running on this cluster."
fi
IPList=($(get_slaveIPs -m))
$bin/ps-cluster-queryMonitorStatus 2>&1 1>/dev/null
NSNUM=$? #The number of nodes without running Secondo Monitors
SMNUM=$(( ${#IPList[*]} - $NSNUM )) #The number of nodes running Secondo Monitors
if [ $SMNUM -gt 0 ]; then
echo "${WARNINFO}$SMNUM Secondo monitors are running now, attempt to turn them off ... ... "
$bin/ps-stop-AllMonitors
if [ $? -ne 0 ]; then
echo "${ERRORINFO}Secondo Monitors cannot be turned off automatically."
echo "Uninstallation for Parallel Secondo Fails."
exit -1
fi
else
echo "No Secondo monitors are running on this cluster."
fi
# 3. remove all data server pathes
cat /dev/null > $DSLIST
for DST in $(cat $PARALLEL_SECONDO_MASTER $PARALLEL_SECONDO_SLAVES | awk '!x[$0]++'); do
IPADDR=$(echo $DST | cut -d':' -f1)
DSPATH=$(echo $DST | cut -d':' -f2)
DSPATH=${DSPATH%/*}
echo "$IPADDR:$DSPATH" >> $DSLIST
done
function removeDataServer
{
IPADDR=$1
DSPATH=$2
echo "Remove Data Server: $IPADDR:$DSPATH" >&2
ssh -o LogLevel=quiet $IPADDR "rm -rf $DSPATH" 2>/dev/null &
}
aJobs=()
DBSERVERS=($(cat $DSLIST | tr '\n' ' '))
DSNUM=${#DBSERVERS[*]}
for((DSIDX=0;DSIDX<$DSNUM;))do
DServ=${DBSERVERS[$DSIDX]}
IPADDR=$(echo $DServ | cut -d':' -f1)
DSPATH=$(echo $DServ | cut -d':' -f2)
for((token=1;token<=$PS_PIPE_Width;token++));do
if [ $DSIDX -gt $DSNUM ]; then
break
fi
if [ ! "${aJobs[$token]}" ] || ! kill -0 ${aJobs[$token]} 2>/dev/null; then
removeDataServer $IPADDR $DSPATH &
aJobs[$token]=$!
let DSIDX++
break
fi
done
done
# 4. remove .parasecrc file and the "source .parasecrc" line in .bashrc file from all slaves
cat $DSLIST | cut -d':' -f 1 | awk '!x[$0]++' > $IPLIST
ANODES=($(cat $IPLIST | tr '\n' ' '))
for nodeIP in ${ANODES[*]};do
ssh -o LogLevel=quiet $nodeIP "sed $(PSEDOPT) \"s/^source [\\\$A-Z_./]*$RCFILENAME//\" \$HOME/.bashrc "
ssh -o LogLevel=quiet $nodeIP "if [ -f $RCFILENAME ]; then rm ${RCFILENAME}; fi"
echo "Remove environment setting on node $nodeIP"
done
# 5. remvoe ps_SDK folder in $SECONDO_BUILD_DIR
rm -rf $PSDKLOC
# 6. clean the SecondoConfig.ini file
# Remove all Parallel Secondo Configurations from $SECCONF
# Find the start line
declare -i ST=$(grep -n "\[ParallelSecondo\]" $SECCONF| cut -d':' -f1)
if [ $ST -gt 0 ]; then
declare -i ED=$(sed -n "$(( $ST + 1 )),$ p" $SECCONF | grep -n "^[[]" | head -1 | cut -d':' -f1)
if [ $ED -eq 0 ]; then
ED=$(wc -l $SECCONF | cut -d' ' -f1)
else
ED=$(( $ST + $ED - 1 ))
fi
sed $(PSEDOPT) "$(( $ST + 1 )),${ED}s/^\([^#]\)*//" $SECCONF
# Delete the backup file in MacOSX
if [ "$SECONDO_PLATFORM" = "mac_osx" ]; then
rm "${SECCONF}.bak"
fi
fi
echo -e "\n\n\n************************************************"
echo "Congratulations! The parallel Secondo has been correctly removed from your cluster."
echo -e "\n\n"
echo "************************************************"
exit 0