blob: ecb69d930a369277a22d8f6a37003fdbb0fed421 [file] [log] [blame]
#!/bin/bash
# @@@ START COPYRIGHT @@@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
# @@@ END COPYRIGHT @@@
# This script will uninstall Cloudera and all its pieces
#==============================================
#Default Values
typeset TRAF_WORKDIR="$( cd "$( dirname "$0" )" && pwd )"
typeset TRAF_DIR="$( cd "$( dirname "$0" )" && pwd )/.."
typeset MY_NODES=""
export PDSH="pdsh -R exec"
export PDSH_SSH_CMD="ssh -q -n %h"
export PDCP="pdcp -R ssh"
typeset timestamp=$(date +%F-%H-%M-%S)
typeset LOG="/var/log/trafodion/uninstall_cloudera_$timestamp.log"
sudo mkdir -p /var/log/trafodion
sudo chmod 777 /var/log/trafodion
#==============================================
function print_usage {
cat << EOF
This script will uninstall Cloudera.
Usage: $(basename $0) [options]
Options:
--help Print this message and exit.
--nodes "<node_list>" Space separated list of nodes (within quotes)
EOF
}
#==============================================
# Parse input parameters
while [[ $# -gt 0 ]]; do
case "$1" in
--nodes)
if [[ -z "$2" ]]; then
echo "***ERROR: No value passed to param $1."
print_usage
exit -1
fi
MY_NODES=$2
shift
;;
--help)
print_usage
exit -1
;;
*)
echo "***ERROR: unknown parameter '$1'"
print_usage
exit -1
esac
shift
done
if [[ $MY_NODES == "" ]]; then
echo
echo "***ERROR: Please use --nodes option to include node list"
echo "***ERROR: Exiting..."
echo
exit -1
fi
#==============================================
#Check with user if they want to preform the uninstall
echo -n "Do you want to uninstall Cloudera? (Y/N) "
read v
if [[ $v != "Y" ]] && [[ $v != "y" ]]; then
echo "***INFO: Exiting..."
exit
fi
node_count=$(echo $MY_NODES | wc -w)
linuxInstalled=$(grep -cr SUSE /proc/version)
#============================================
#Info for log file
echo "***INFO: Log file located at: /var/log/trafodion"
echo "***Log File: trafodion_cloudera_uninstall script***" >> $LOG
echo >> $LOG
#============================================
echo "***INFO: Uninstalling on nodes: $MY_NODES" | tee -a $LOG
#==============================================
#Run Cloudera uninstall script and stop all services
sudo /usr/share/cmf/uninstall-cloudera-manager.sh
#==============================================
#Run Cloudera uninstall script on all nodes.
for node in $MY_NODES
do
echo "***INFO: Uninstalling on node: $node" | tee -a $LOG
if [ $node == $HOSTNAME ]; then
if [[ "$linuxInstalled" == "1" ]]; then
./traf_cloudera_uninstall_suse | tee -a $LOG
else
./traf_cloudera_uninstall | tee -a $LOG
fi
if [ ${PIPESTATUS[0]} != "0" ]; then
echo "***ERROR: Cloudera may not be completely uninstalled on $node" | tee -a $LOG
echo "***ERROR: Review log files." | tee -a $LOG
fi
else
if [[ "$linuxInstalled" -eq "1" ]]; then
$PDCP -w $node -x $HOSTNAME traf_cloudera_uninstall_suse $HOME | tee -a $LOG
else
$PDCP -w $node -x $HOSTNAME traf_cloudera_uninstall $HOME | tee -a $LOG
fi
if [ ${PIPESTATUS[0]} != "0" ]; then
echo "***ERROR: Error copying script to $node" | tee -a $LOG
echo "***ERROR: Exiting..." | tee -a $LOG
fi
if [[ $linuxInstalled -eq "1" ]]; then
$PDSH -w $node $PDSH_SSH_CMD $HOME/traf_cloudera_uninstall_suse | tee -a $LOG
else
$PDSH -w $node $PDSH_SSH_CMD $HOME/traf_cloudera_uninstall | tee -a $LOG
fi
if [ ${PIPESTATUS[0]} != "0" ]; then
echo "***ERROR: Cloudera may not be completely uninstalled on $node" | tee -a $LOG
echo "***ERROR: Review log files." | tee -a $LOG
fi
fi
done
echo "***INFO: Cloudera Manager uninstalled." | tee -a $LOG