#!/bin/ksh
# This script removes the cluster and cluster setup
# we use the entries in /etc/cluster/rhosts to determine the nodename, which
# should be the same as the hostname.
# in AN61, the hostname = PHA_nodename = CAA_nodename = node1 / node2
# The script should also work if the nodenames are different than node1 / node2
# (although not tested)
# but it does require that hostname = nodename.
function restart_clcomd {
let CLCOMDOK=0
let TRIES=0
stopsrc -s clcomd
sleep 5
startsrc -s clcomd
sleep 20
# MODIFIED 2013.04.02, karlmi: Now we restart clcomd again after clearing
# /etc/cluster/rhosts. clrsh will not work, so don't test it.
# while [[ $CLCOMDOK -eq 0 ]]
# do
# typeset OUTPUT
# OUTPUT=$(clrsh $NODE1 hostname 2>/dev/null)
# print "clrsh $NODE1 hostname is $OUTPUT" >> $LOG
# if [[ $OUTPUT = $NODE1 ]]; then
# typeset OUTPUT
# OUTPUT=$(clrsh $NODE2 hostname 2>/dev/null)
# print "clrsh $NODE2 hostname is $OUTPUT" >> $LOG
# if [[ $OUTPUT = $NODE2 ]]; then
# let CLCOMDOK=1
# fi
# fi
# let TRIES=TRIES+1
# if [[ $TRIES -gt 6 ]]; then
# return 1
# fi
# if [[ $CLCOMDOK -eq 0 ]]; then
# sleep 10
# fi
# done
return 0
}
# MODIFIED 2013.03.12, karlmi: stop_cluster no longer used
function stop_cluster {
print "Bringing nodes offline" | tee -a $LOG
print "clmgr offline cl" | tee -a $LOG
OUTPUT=$(clmgr offline cl WHEN=now MANAGE=offline)
rc=$?
print $OUTPUT >> $LOG
if [[ $rc -gt 2 ]]; then
print "Failed to cleanly stop cluster services. Make sure cluster services are stopped on both nodes then execute this script again. Ask your instructor for help if you need it." | tee -a $LOG
exit 1
fi
}
function remove_cluster {
# Restore the original httpd.conf back to /usr/IBMIHS/conf
#sed "s/^ServerName .*/ServerName node1/" /usr/IBMIHS/conf/httpd.conf > /classfiles/httpd.conf
#mv /classfiles/httpd.conf /usr/IBMIHS/conf/.
#clrsh $NODE2 'sed "s/^ServerName .*/ServerName node2/" /usr/IBMIHS/conf/httpd.conf > /classfiles/httpd.conf'
#clrsh $NODE2 cp /classfiles/httpd.conf /usr/IBMIHS/conf/.
print "Deleting the cluster" | tee -a $LOG
print "clmgr -f delete cluster ALL 2>&1" | tee -a $LOG
clmgr -f delete cluster ALL 2>&1 >> $LOG
# # Restart clcomd
restart_clcomd
# Verify the cluster is removed
print "Verify cluster is removed from $NODE2" | tee -a $LOG
print "clrsh $NODE2 /usr/es/sbin/cluster/utilities/cltopinfo 2>&1" | tee -a $LOG
OUTPUT=$(clrsh $NODE2 /usr/es/sbin/cluster/utilities/cltopinfo 2>&1)
rc=$?
print $OUTPUT | tee -a $LOG
if [[ $rc -eq 255 ]]; then
# The PHA cluster is removed from $NODE2
print "PHA cluster is removed from $NODE2" | tee -a $LOG
else
# Try to remove it
print "Trying to remove the PHA cluster from $NODE2" | tee -a $LOG
print "/usr/es/sbin/cluster/utilities/clrmclstr 2>&1" | tee -a $LOG
/usr/es/sbin/cluster/utilities/clrmclstr 2>&1 | tee -a $LOG
fi
print "Verify cluster is removed from $NODE1" | tee -a $LOG
print "/usr/es/sbin/cluster/utilities/cltopinfo 2>&1" | tee -a $LOG
OUTPUT=$(/usr/es/sbin/cluster/utilities/cltopinfo 2>&1)
rc=$?
print $OUTPUT | tee -a $LOG
if [[ $rc -eq 255 ]]; then
# The PHA cluster is removed from node1
print "PHA cluster is removed from $NODE1" | tee -a $LOG
else
# Try to remove it
print "Trying to remove the PHA cluster from $NODE1" | tee -a $LOG
print "/usr/es/sbin/cluster/utilities/clrmclstr 2>&1" | tee -a $LOG
/usr/es/sbin/cluster/utilities/clrmclstr 2>&1 | tee -a $LOG
fi
print "Verify CAA cluster is removed" | tee -a $LOG
print "/usr/sbin/lscluster -c 2>&1" | tee -a $LOG
OUTPUT=$(/usr/sbin/lscluster -c 2>&1)
rc=$?
print $OUTPUT | tee -a $LOG
if [[ $rc -eq 255 ]] || [[ $OUTPUT = "Cluster services are not active." ]]; then
# The CAA cluster is removed from node1
print "The CAA cluster is removed from $NODE1" | tee -a $LOG
else
# Try to remove it
print "Trying to remove the CAA cluster" | tee -a $LOG
print "/usr/sbin/rmcluster -fn $CLUSTER 2>&1" | tee -a $LOG
CAA_FORCE_ENABLED=1 /usr/sbin/rmcluster -fn $CLUSTER 2>&1 | tee -a $LOG
print "Verify CAA cluster is removed" | tee -a $LOG
print "/usr/sbin/lscluster -c 2>&1" | tee -a $LOG
OUTPUT=
OUTPUT=$(/usr/sbin/lscluster -c 2>&1)
rc=$?
print $OUTPUT | tee -a $LOG
if [[ $rc -eq 255 ]] || [[ $OUTPUT = "Cluster services are not active." ]]; then
# The CAA cluster is removed from node1
print "The CAA cluster is removed from $NODE1" | tee -a $LOG
else
print "There are problems removing the CAA cluster. Ask the instructor for assistance" | tee -a $LOG
let RC=RC+1
fi
fi
# Make sure the CAA cluster is removed from node2
print "Verify the CAA cluster is removed from $NODE2" | tee -a $LOG
print "clrsh $NODE2 /usr/sbin/lscluster -c 2>&1" | tee -a $LOG
OUTPUT=
OUTPUT=$(clrsh $NODE2 '/usr/sbin/lscluster -c 2>&1')
rc=$?
print $OUTPUT | tee -a $LOG
if [[ $rc -eq 255 ]] || [[ $OUTPUT = "Cluster services are not active." ]]; then
# The CAA cluster is removed from node2
print "The CAA cluster is removed from $NODE2" | tee -a $LOG
else
# Try to remove it
print "Trying to remove the CAA cluster" | tee -a $LOG
print "clrsh $NODE2 /usr/sbin/rmcluster -fn $CLUSTER 2>&1" | tee -a $LOG
clrsh $NODE2 'CAA_FORCE_ENABLED=1 /usr/sbin/rmcluster -fn $CLUSTER 2>&1' | tee -a $LOG
print "Verify CAA cluster is removed" | tee -a $LOG
print "clrsh $NODE2 /usr/sbin/lscluster -c 2>&1" | tee -a $LOG
OUTPUT=
OUTPUT=$(clrsh $NODE2 '/usr/sbin/lscluster -c 2>&1')
rc=$?
print $OUTPUT | tee -a $LOG
if [[ $rc -eq 255 ]] || [[ $OUTPUT = "Cluster services are not active." ]]; then
# The CAA cluster is removed from node2
print "The CAA cluster is removed from $NODE2" | tee -a $LOG
else
print "There are problems removing the CAA cluster. Ask the instructor for assistance" | tee -a $LOG
let RC=RC+1
fi
fi
# Make sure the repository disk definition is removed on node1
print "Make sure the repository disk definition is removed on $NODE1" | tee -a $LOG
print "/usr/sbin/lspv | grep caa 2>&1" | tee -a $LOG
OUTPUT=$(/usr/sbin/lspv | grep caa 2>&1)
rc=$?
print $OUTPUT | tee -a $LOG
if [[ $rc -ne 0 ]]; then
# The repository definition is removed from node1
print "The repository disk definition is removed from $NODE1" | tee -a $LOG
else
print "Attempting to cleanup the repository disk on $NODE1" | tee -a $LOG
print "/usr/sbin/clusterconf -fu 2>&1" | tee -a $LOG
/usr/sbin/clusterconf -fu 2>&1 | tee -a $LOG
print "Make sure the repository disk definition is removed on $NODE1" | tee -a $LOG
print "/usr/sbin/lspv | grep caa 2>&1" | tee -a $LOG
OUTPUT=$(/usr/sbin/lspv | grep caa 2>&1)
rc=$?
print $OUTPUT | tee -a $LOG
if [[ $rc -eq 0 ]]; then
print "There are problems removing the CAA cluster. Ask the instructor for assistance" | tee -a $LOG
let RC=RC+1
fi
fi
# Make sure the repository disk definition is removed on node2
print "Make sure the repository disk definition is removed on $NODE2" | tee -a $LOG
print "clrsh $NODE2 /usr/sbin/lspv | grep caa 2>&1" | tee -a $LOG
OUTPUT=$(clrsh $NODE2 /usr/sbin/lspv | grep caa 2>&1)
rc=$?
print $OUTPUT | tee -a $LOG
if [[ $rc -ne 0 ]]; then
# The repository definition is removed from node2
print "The repository disk definition is removed from $NODE2" | tee -a $LOG
else
print "Attempting to cleanup the repository disk on $NODE2" | tee -a $LOG
print "clrsh $NODE2 /usr/sbin/clusterconf -fu 2>&1" | tee -a $LOG
clrsh $NODE2 /usr/sbin/clusterconf -fu 2>&1 | tee -a $LOG
print "Make sure the repository disk definition is removed on $NODE2" | tee -a $LOG
print "clrsh $NODE2 /usr/sbin/lspv | grep caa 2>&1" | tee -a $LOG
OUTPUT=$(clrsh $NODE2 /usr/sbin/lspv | grep caa 2>&1)
rc=$?
print $OUTPUT | tee -a $LOG
if [[ $rc -eq 0 ]]; then
print "There are problems removing the CAA cluster. Ask the instructor for assistance" | tee -a $LOG
let RC=RC+1
fi
fi
} # end of remove_cluster
function cleanup_storage {
# Remove the httpvg volume group
# a. varyoff on node1
# b. exportvg on node1
# c. varyoff on node2
# d. exportvg on node2
VGS=$(/usr/sbin/lsvg -o)
OUTPUT=$(print $VGS | grep "httpvg")
rc=$?
if [[ $rc -eq 0 ]]; then
print "Varying off httpvg on $NODE1" | tee -a $LOG
umount /usr/HTTPServer/htdocs/en_US 2>&1 | tee -a $LOG
varyoffvg httpvg
fi
print "Exporting httpvg on $NODE1" | tee -a $LOG
OUTPUT=$(exportvg httpvg)
rc=$?
if [[ $rc -ne 0 ]]; then
print "Problem exporting httpvg on $NODE1. Verify httpvg is no longer defined in lspv output. If it is, alert your instructor" | tee -a $LOG
fi
VGS=
VGS=$(clrsh $NODE2 /usr/sbin/lsvg -o)
OUTPUT=$(print $VGS | grep "httpvg")
rc=$?
if [[ $rc -eq 0 ]]; then
print "Varying off httpvg on $NODE2" | tee -a $LOG
OUTPUT=$(clrsh $NODE2 "/usr/sbin/umount /usr/HTTPServer/htdocs/en_US 2>&1")
rc=$?
print $OUTPUT | tee -a $LOG
OUTPUT=$(clrsh $NODE2 "/usr/sbin/varyoffvg httpvg 2>&1")
rc=$?
print $OUTPUT | tee -a $LOG
fi
print "Exporting httpvg on $NODE2" | tee -a $LOG
OUTPUT=$(clrsh $NODE2 "/usr/sbin/exportvg httpvg 2>&1")
rc=$?
print $OUTPUT | tee -a $LOG
if [[ $rc -ne 0 ]]; then
print "Problem exporting httpvg on $NODE2. Verify httpvg is no longer defined in lspv output. If it is, alert your instructor" | tee -a $LOG
fi
rmdev -dl hdisk2
cfgmgr
clrsh $NODE2 rmdev -dl hdisk2
clrsh $NODE2 cfgmgr
} # end cleanup_storage
function cleanup_network {
# Make sure the persistent alias is gone
OUTPUT=$(clrsh $NODE2 netstat -i | grep node2admin | awk '{print $1}')
if [[ $OUTPUT = "en"* ]]; then
IF=$OUTPUT
OUTPUT=$(clrsh $NODE2 ifconfig $IF -alias node2admin)
fi
typeset OUTPUT
typeset IF
OUTPUT=$(netstat -i | grep node1admin | awk '{print $1}')
if [[ $OUTPUT = "en"* ]]; then
IF=$OUTPUT
OUTPUT=$(ifconfig $IF -alias node1admin)
fi
#
# Remove configuration on en1 and en2 on node1 and node2
#
print "Removing configuration on en1 and en2 on $NODE2" | tee -a $LOG
clrsh $NODE2 'chdev -l en1 -a state="detach"'
clrsh $NODE2 'chdev -l en2 -a state="detach"'
print "Removing configuration on en1 and en2 on $NODE1" | tee -a $LOG
chdev -l en1 -a state='detach'
chdev -l en2 -a state='detach'
#
# Remove IP entries from /etc/hosts on Node2
#
print "Removing IP entries from /etc/hosts on $NODE2" | tee -a $LOG
clrsh $NODE2 "cat /etc/hosts | grep -v ^1[79]2 >/tmp/hosts"
clrsh $NODE2 'print "172.16.3.3 node3admin" >>/tmp/hosts'
clrsh $NODE2 "cp /tmp/hosts /etc/hosts 2>&1" | tee -a $LOG
#
# Remove IP entries from /etc/hosts on Node1
#
print "Removing IP entries from /etc/hosts on $NODE1" | tee -a $LOG
cat /etc/hosts | grep -v ^1[79]2 >/tmp/hosts
print "172.16.3.3 node3admin" >>/tmp/hosts
cp /tmp/hosts /etc/hosts 2>&1 | tee -a $LOG
rm /tmp/hosts
clrsh $NODE2 rm /tmp/hosts
# Empty /etc/cluster/rhosts
print "Emptying /etc/cluster/rhosts" | tee -a $LOG
>/etc/cluster/rhosts
clrsh node2 ">/etc/cluster/rhosts"
}
# MAIN
NODE1=node1
NODE2=node2
CLUSTER=pha_cluster
LOG=/tmp/EX2_prescript.log
RC=0
date=`date`
print "Executing EX2_prescript on $date" >$LOG
# Make sure we're executing on node1
HOSTNAME=$(hostname | grep node1)
if [[ $HOSTNAME = "" ]]; then
print "Execute this script on $NODE1. Exiting." | tee -a $LOG
exit 1
fi
# Stop cluster services on all nodes
# MODIFIED 2013.03.12, karlmi: no longer needed for 712
# stop_cluster
# Remove the cluster
remove_cluster
# Clean up storage
cleanup_storage
# Clean up network
cleanup_network
# restart clcomd after clearing network
# Restart clcomd
restart_clcomd
if [[ $RC -gt 0 ]]; then
print "There may have been problems removing the cluster completely. Continue with the lab exercise and complete the verification steps. Ask for the instructor's help if needed." | tee -a $LOG
else
print "The prescript for Exercise2 has completed successfully."
fi
# This script removes the cluster and cluster setup
# we use the entries in /etc/cluster/rhosts to determine the nodename, which
# should be the same as the hostname.
# in AN61, the hostname = PHA_nodename = CAA_nodename = node1 / node2
# The script should also work if the nodenames are different than node1 / node2
# (although not tested)
# but it does require that hostname = nodename.
function restart_clcomd {
let CLCOMDOK=0
let TRIES=0
stopsrc -s clcomd
sleep 5
startsrc -s clcomd
sleep 20
# MODIFIED 2013.04.02, karlmi: Now we restart clcomd again after clearing
# /etc/cluster/rhosts. clrsh will not work, so don't test it.
# while [[ $CLCOMDOK -eq 0 ]]
# do
# typeset OUTPUT
# OUTPUT=$(clrsh $NODE1 hostname 2>/dev/null)
# print "clrsh $NODE1 hostname is $OUTPUT" >> $LOG
# if [[ $OUTPUT = $NODE1 ]]; then
# typeset OUTPUT
# OUTPUT=$(clrsh $NODE2 hostname 2>/dev/null)
# print "clrsh $NODE2 hostname is $OUTPUT" >> $LOG
# if [[ $OUTPUT = $NODE2 ]]; then
# let CLCOMDOK=1
# fi
# fi
# let TRIES=TRIES+1
# if [[ $TRIES -gt 6 ]]; then
# return 1
# fi
# if [[ $CLCOMDOK -eq 0 ]]; then
# sleep 10
# fi
# done
return 0
}
# MODIFIED 2013.03.12, karlmi: stop_cluster no longer used
function stop_cluster {
print "Bringing nodes offline" | tee -a $LOG
print "clmgr offline cl" | tee -a $LOG
OUTPUT=$(clmgr offline cl WHEN=now MANAGE=offline)
rc=$?
print $OUTPUT >> $LOG
if [[ $rc -gt 2 ]]; then
print "Failed to cleanly stop cluster services. Make sure cluster services are stopped on both nodes then execute this script again. Ask your instructor for help if you need it." | tee -a $LOG
exit 1
fi
}
function remove_cluster {
# Restore the original httpd.conf back to /usr/IBMIHS/conf
#sed "s/^ServerName .*/ServerName node1/" /usr/IBMIHS/conf/httpd.conf > /classfiles/httpd.conf
#mv /classfiles/httpd.conf /usr/IBMIHS/conf/.
#clrsh $NODE2 'sed "s/^ServerName .*/ServerName node2/" /usr/IBMIHS/conf/httpd.conf > /classfiles/httpd.conf'
#clrsh $NODE2 cp /classfiles/httpd.conf /usr/IBMIHS/conf/.
print "Deleting the cluster" | tee -a $LOG
print "clmgr -f delete cluster ALL 2>&1" | tee -a $LOG
clmgr -f delete cluster ALL 2>&1 >> $LOG
# # Restart clcomd
restart_clcomd
# Verify the cluster is removed
print "Verify cluster is removed from $NODE2" | tee -a $LOG
print "clrsh $NODE2 /usr/es/sbin/cluster/utilities/cltopinfo 2>&1" | tee -a $LOG
OUTPUT=$(clrsh $NODE2 /usr/es/sbin/cluster/utilities/cltopinfo 2>&1)
rc=$?
print $OUTPUT | tee -a $LOG
if [[ $rc -eq 255 ]]; then
# The PHA cluster is removed from $NODE2
print "PHA cluster is removed from $NODE2" | tee -a $LOG
else
# Try to remove it
print "Trying to remove the PHA cluster from $NODE2" | tee -a $LOG
print "/usr/es/sbin/cluster/utilities/clrmclstr 2>&1" | tee -a $LOG
/usr/es/sbin/cluster/utilities/clrmclstr 2>&1 | tee -a $LOG
fi
print "Verify cluster is removed from $NODE1" | tee -a $LOG
print "/usr/es/sbin/cluster/utilities/cltopinfo 2>&1" | tee -a $LOG
OUTPUT=$(/usr/es/sbin/cluster/utilities/cltopinfo 2>&1)
rc=$?
print $OUTPUT | tee -a $LOG
if [[ $rc -eq 255 ]]; then
# The PHA cluster is removed from node1
print "PHA cluster is removed from $NODE1" | tee -a $LOG
else
# Try to remove it
print "Trying to remove the PHA cluster from $NODE1" | tee -a $LOG
print "/usr/es/sbin/cluster/utilities/clrmclstr 2>&1" | tee -a $LOG
/usr/es/sbin/cluster/utilities/clrmclstr 2>&1 | tee -a $LOG
fi
print "Verify CAA cluster is removed" | tee -a $LOG
print "/usr/sbin/lscluster -c 2>&1" | tee -a $LOG
OUTPUT=$(/usr/sbin/lscluster -c 2>&1)
rc=$?
print $OUTPUT | tee -a $LOG
if [[ $rc -eq 255 ]] || [[ $OUTPUT = "Cluster services are not active." ]]; then
# The CAA cluster is removed from node1
print "The CAA cluster is removed from $NODE1" | tee -a $LOG
else
# Try to remove it
print "Trying to remove the CAA cluster" | tee -a $LOG
print "/usr/sbin/rmcluster -fn $CLUSTER 2>&1" | tee -a $LOG
CAA_FORCE_ENABLED=1 /usr/sbin/rmcluster -fn $CLUSTER 2>&1 | tee -a $LOG
print "Verify CAA cluster is removed" | tee -a $LOG
print "/usr/sbin/lscluster -c 2>&1" | tee -a $LOG
OUTPUT=
OUTPUT=$(/usr/sbin/lscluster -c 2>&1)
rc=$?
print $OUTPUT | tee -a $LOG
if [[ $rc -eq 255 ]] || [[ $OUTPUT = "Cluster services are not active." ]]; then
# The CAA cluster is removed from node1
print "The CAA cluster is removed from $NODE1" | tee -a $LOG
else
print "There are problems removing the CAA cluster. Ask the instructor for assistance" | tee -a $LOG
let RC=RC+1
fi
fi
# Make sure the CAA cluster is removed from node2
print "Verify the CAA cluster is removed from $NODE2" | tee -a $LOG
print "clrsh $NODE2 /usr/sbin/lscluster -c 2>&1" | tee -a $LOG
OUTPUT=
OUTPUT=$(clrsh $NODE2 '/usr/sbin/lscluster -c 2>&1')
rc=$?
print $OUTPUT | tee -a $LOG
if [[ $rc -eq 255 ]] || [[ $OUTPUT = "Cluster services are not active." ]]; then
# The CAA cluster is removed from node2
print "The CAA cluster is removed from $NODE2" | tee -a $LOG
else
# Try to remove it
print "Trying to remove the CAA cluster" | tee -a $LOG
print "clrsh $NODE2 /usr/sbin/rmcluster -fn $CLUSTER 2>&1" | tee -a $LOG
clrsh $NODE2 'CAA_FORCE_ENABLED=1 /usr/sbin/rmcluster -fn $CLUSTER 2>&1' | tee -a $LOG
print "Verify CAA cluster is removed" | tee -a $LOG
print "clrsh $NODE2 /usr/sbin/lscluster -c 2>&1" | tee -a $LOG
OUTPUT=
OUTPUT=$(clrsh $NODE2 '/usr/sbin/lscluster -c 2>&1')
rc=$?
print $OUTPUT | tee -a $LOG
if [[ $rc -eq 255 ]] || [[ $OUTPUT = "Cluster services are not active." ]]; then
# The CAA cluster is removed from node2
print "The CAA cluster is removed from $NODE2" | tee -a $LOG
else
print "There are problems removing the CAA cluster. Ask the instructor for assistance" | tee -a $LOG
let RC=RC+1
fi
fi
# Make sure the repository disk definition is removed on node1
print "Make sure the repository disk definition is removed on $NODE1" | tee -a $LOG
print "/usr/sbin/lspv | grep caa 2>&1" | tee -a $LOG
OUTPUT=$(/usr/sbin/lspv | grep caa 2>&1)
rc=$?
print $OUTPUT | tee -a $LOG
if [[ $rc -ne 0 ]]; then
# The repository definition is removed from node1
print "The repository disk definition is removed from $NODE1" | tee -a $LOG
else
print "Attempting to cleanup the repository disk on $NODE1" | tee -a $LOG
print "/usr/sbin/clusterconf -fu 2>&1" | tee -a $LOG
/usr/sbin/clusterconf -fu 2>&1 | tee -a $LOG
print "Make sure the repository disk definition is removed on $NODE1" | tee -a $LOG
print "/usr/sbin/lspv | grep caa 2>&1" | tee -a $LOG
OUTPUT=$(/usr/sbin/lspv | grep caa 2>&1)
rc=$?
print $OUTPUT | tee -a $LOG
if [[ $rc -eq 0 ]]; then
print "There are problems removing the CAA cluster. Ask the instructor for assistance" | tee -a $LOG
let RC=RC+1
fi
fi
# Make sure the repository disk definition is removed on node2
print "Make sure the repository disk definition is removed on $NODE2" | tee -a $LOG
print "clrsh $NODE2 /usr/sbin/lspv | grep caa 2>&1" | tee -a $LOG
OUTPUT=$(clrsh $NODE2 /usr/sbin/lspv | grep caa 2>&1)
rc=$?
print $OUTPUT | tee -a $LOG
if [[ $rc -ne 0 ]]; then
# The repository definition is removed from node2
print "The repository disk definition is removed from $NODE2" | tee -a $LOG
else
print "Attempting to cleanup the repository disk on $NODE2" | tee -a $LOG
print "clrsh $NODE2 /usr/sbin/clusterconf -fu 2>&1" | tee -a $LOG
clrsh $NODE2 /usr/sbin/clusterconf -fu 2>&1 | tee -a $LOG
print "Make sure the repository disk definition is removed on $NODE2" | tee -a $LOG
print "clrsh $NODE2 /usr/sbin/lspv | grep caa 2>&1" | tee -a $LOG
OUTPUT=$(clrsh $NODE2 /usr/sbin/lspv | grep caa 2>&1)
rc=$?
print $OUTPUT | tee -a $LOG
if [[ $rc -eq 0 ]]; then
print "There are problems removing the CAA cluster. Ask the instructor for assistance" | tee -a $LOG
let RC=RC+1
fi
fi
} # end of remove_cluster
function cleanup_storage {
# Remove the httpvg volume group
# a. varyoff on node1
# b. exportvg on node1
# c. varyoff on node2
# d. exportvg on node2
VGS=$(/usr/sbin/lsvg -o)
OUTPUT=$(print $VGS | grep "httpvg")
rc=$?
if [[ $rc -eq 0 ]]; then
print "Varying off httpvg on $NODE1" | tee -a $LOG
umount /usr/HTTPServer/htdocs/en_US 2>&1 | tee -a $LOG
varyoffvg httpvg
fi
print "Exporting httpvg on $NODE1" | tee -a $LOG
OUTPUT=$(exportvg httpvg)
rc=$?
if [[ $rc -ne 0 ]]; then
print "Problem exporting httpvg on $NODE1. Verify httpvg is no longer defined in lspv output. If it is, alert your instructor" | tee -a $LOG
fi
VGS=
VGS=$(clrsh $NODE2 /usr/sbin/lsvg -o)
OUTPUT=$(print $VGS | grep "httpvg")
rc=$?
if [[ $rc -eq 0 ]]; then
print "Varying off httpvg on $NODE2" | tee -a $LOG
OUTPUT=$(clrsh $NODE2 "/usr/sbin/umount /usr/HTTPServer/htdocs/en_US 2>&1")
rc=$?
print $OUTPUT | tee -a $LOG
OUTPUT=$(clrsh $NODE2 "/usr/sbin/varyoffvg httpvg 2>&1")
rc=$?
print $OUTPUT | tee -a $LOG
fi
print "Exporting httpvg on $NODE2" | tee -a $LOG
OUTPUT=$(clrsh $NODE2 "/usr/sbin/exportvg httpvg 2>&1")
rc=$?
print $OUTPUT | tee -a $LOG
if [[ $rc -ne 0 ]]; then
print "Problem exporting httpvg on $NODE2. Verify httpvg is no longer defined in lspv output. If it is, alert your instructor" | tee -a $LOG
fi
rmdev -dl hdisk2
cfgmgr
clrsh $NODE2 rmdev -dl hdisk2
clrsh $NODE2 cfgmgr
} # end cleanup_storage
function cleanup_network {
# Make sure the persistent alias is gone
OUTPUT=$(clrsh $NODE2 netstat -i | grep node2admin | awk '{print $1}')
if [[ $OUTPUT = "en"* ]]; then
IF=$OUTPUT
OUTPUT=$(clrsh $NODE2 ifconfig $IF -alias node2admin)
fi
typeset OUTPUT
typeset IF
OUTPUT=$(netstat -i | grep node1admin | awk '{print $1}')
if [[ $OUTPUT = "en"* ]]; then
IF=$OUTPUT
OUTPUT=$(ifconfig $IF -alias node1admin)
fi
#
# Remove configuration on en1 and en2 on node1 and node2
#
print "Removing configuration on en1 and en2 on $NODE2" | tee -a $LOG
clrsh $NODE2 'chdev -l en1 -a state="detach"'
clrsh $NODE2 'chdev -l en2 -a state="detach"'
print "Removing configuration on en1 and en2 on $NODE1" | tee -a $LOG
chdev -l en1 -a state='detach'
chdev -l en2 -a state='detach'
#
# Remove IP entries from /etc/hosts on Node2
#
print "Removing IP entries from /etc/hosts on $NODE2" | tee -a $LOG
clrsh $NODE2 "cat /etc/hosts | grep -v ^1[79]2 >/tmp/hosts"
clrsh $NODE2 'print "172.16.3.3 node3admin" >>/tmp/hosts'
clrsh $NODE2 "cp /tmp/hosts /etc/hosts 2>&1" | tee -a $LOG
#
# Remove IP entries from /etc/hosts on Node1
#
print "Removing IP entries from /etc/hosts on $NODE1" | tee -a $LOG
cat /etc/hosts | grep -v ^1[79]2 >/tmp/hosts
print "172.16.3.3 node3admin" >>/tmp/hosts
cp /tmp/hosts /etc/hosts 2>&1 | tee -a $LOG
rm /tmp/hosts
clrsh $NODE2 rm /tmp/hosts
# Empty /etc/cluster/rhosts
print "Emptying /etc/cluster/rhosts" | tee -a $LOG
>/etc/cluster/rhosts
clrsh node2 ">/etc/cluster/rhosts"
}
# MAIN
NODE1=node1
NODE2=node2
CLUSTER=pha_cluster
LOG=/tmp/EX2_prescript.log
RC=0
date=`date`
print "Executing EX2_prescript on $date" >$LOG
# Make sure we're executing on node1
HOSTNAME=$(hostname | grep node1)
if [[ $HOSTNAME = "" ]]; then
print "Execute this script on $NODE1. Exiting." | tee -a $LOG
exit 1
fi
# Stop cluster services on all nodes
# MODIFIED 2013.03.12, karlmi: no longer needed for 712
# stop_cluster
# Remove the cluster
remove_cluster
# Clean up storage
cleanup_storage
# Clean up network
cleanup_network
# restart clcomd after clearing network
# Restart clcomd
restart_clcomd
if [[ $RC -gt 0 ]]; then
print "There may have been problems removing the cluster completely. Continue with the lab exercise and complete the verification steps. Ask for the instructor's help if needed." | tee -a $LOG
else
print "The prescript for Exercise2 has completed successfully."
fi