retire-san-removal-linux

retire_san_removal_linux
called by server_retire_linux

code format="bash"
 * 1) !/bin/bash

export PATH="/usr/local/bin:/usr/sbin:/usr/ccs/bin:/usr/bin:/usr/lib:$PATH:/etc:/usr/tools/bin:/usr/bin"

if $FIXSENDMAIL = "y" ; then perl -i -pe 's/^DS.*//' /etc/mail/sendmail.cf       exit fi
 * 1) Make sure sendmail is configured properly so the various emails will go out

if $REMOVENETGROUP = "y" ; then echo "Connecting to Lepton..." echo -e "Enter bind passwd: \c " stty -echo read ADMINPASS stty echo ssh $USERID@ /bin/ldapmodify -D "m" -w $ADMINPASS -c << EOF dn: cn=$NETGROUP,ou=netgroup, changetype: delete EOF touch /tmp/done6 echo "Press ENTER to return to the menu or CTRL-C to exit" read junk exit fi
 * 1) Remove LDAP Netgroup if requested from master retirement script

if ! -e /inq.linux ; then echo "/inq.linux not reachable. Please check connectivity and re-run the script." echo "" echo "Exiting." exit 1 fi
 * 1) Make sure inq is reachable

if $EUID -ne 0 ; then echo "This script must be run as root" 1>&2 exit 1 fi
 * 1) Check to see if the user is root

email_workplan_physical { echo -ne "Work Plan:\n=========\nRetirement will be done according to 7 Version 3.0\n\nEMC and DGC devices will be removed based on the following information:\nINQ output:\n`/inq.linux`\n\npvdisplay:\n`pvdisplay`\n\nThe following command will be run in order to prepare the system for GSMO to remove the SAN devices:\n\npvremove -f $i 2>/dev/null\n\nAll small PVs (< 10 MB) will be exempt from above command as they may be pointers to shared storage with another box.\n\nThe EMC Removal steps deviates slightly from  because all those steps aren't needed for a retirement, just a pvremove -f of all matching PVs. Therefore, I have developed and confirmed this process as valid for retirements only as it removes ALL SAN.\n\nVerification:\n============\nFrom  Version 3.0:\nVerify all applicable child CRs are closed.\n\nCommunication:\n=============\nOwner has submitted this request based on the Platfrom Retirement Approval From and is aware of change and the parties have agreed to the change.\n\nJustification:\n=============\nPlatfrom Retirement Approval Form has been signed by the system owner.\n\nTest/Backoff:\n============\nPerfrom a BMR and tape backup restore and re-attach devices to the SAN.\n" | mailx -s "full workplan for $SHOST" $EMAIL }
 * 1) Function to email workplan

email_workplan_vm { echo -ne "Work Plan:\n=========\nRetirement will be done according to  Version 3.0\n\nThis server is a VM and therefore the attached SAN will be removed by the GLO/ESX team. A child CR will be cut off the parent retirement CR to notifify them accordingly.\n\nVerification:\n============\nFrom  Version 3.0:\nVerify all applicable child CRs are closed.\n\nCommunication:\n=============\nOwner has submitted this request based on the Platfrom Retirement Approval From and is aware of change and the parties have agreed to the change.\n\nJustification:\n=============\nPlatfrom Retirement Approval Form has been signed by the system owner.\n\nTest/Backoff:\n============\nPerfrom a BMR and tape backup restore and re-attach devices to the SAN.\n" | mailx -s "full workplan for $SHOST" $EMAIL }
 * 1) Function to email workplan

if -e /tmp/done5partial ; then if tr "-" " " | awk '{print $1}'` != "VMware" ; then
 * 1) Check to see if SAN Removal step is partial and if so execute the steps in the from the workplan
 * 1) For physical servers

# Check to see if it's /dev/mapper or /dev/emcpower and act accordingly if grep "/dev/emcpower"` ; then echo "Forcefully removing Physical Volumes..." for i in `find /dev | grep "/dev/emcpower"`; do               pvremove -ff -y $i 2> /dev/null done fi

if grep "/dev/mapper/mpath"` ; then echo "Forcefully removing Physical Volumes..." # Scan for an exclude from pvremove any tiny PVs that may have been set up               SMALLPV=`multipath -ll | grep -B1 size=[0-9].[0-9]M | head -1 | cut -f1 -d" "` if -z $SMALLPV ; then SMALLPV="somestring"; fi                for i in `ls -1 /dev/mapper/mpath* | grep -v $SMALLPV` ; do                        pvremove -ff -y $i 2> /dev/null done fi fi mv /tmp/done5partial /tmp/done5 exit fi

echo "Stopping Key Services..." /etc/init.d/oracle stop;/etc/init.d/syslog stop; /etc/init.d/nqmdaemon stop;/etc/init.d/mysql.server stop killall httpd
 * 1) Stop Services

echo "Unmounting all extra filesystems" mount | egrep -v "/ |/usr |/proc|/home|/var |/tmp|/opt |/var/run|/dev/fd|/sys|/etc/mnttab|/usr/tools|/net/cursor|/net/guts|/net |/boot|/dev/pts" | awk '{print $1}' >> /tmp/mount.list
 * 1) Unmount all extra filesytems

for i in `mount | grep automount | grep -v "/home" | grep -v "/net" | awk -F"pid" '{print $2}' | awk -F\) '{print $1}'`; do   kill -9 $i done

COUNT=1 while $COUNT < 6 ; do                for i in `cat /tmp/mount.list`; do                        umount -f $i 2> /dev/null done #COUNT=$(($COUNT + 1)) let COUNT=COUNT+1 done mount echo "Are all extra filesystems unmounted? [y/n]" read answer if [ "$answer" = "n" ]; then echo "Please manually unmount what's left and then re-run the script." echo "Also, please report the offending filesystem(s) to Chad Crider at " echo "to be included in the script for future use." sleep 3 exit 1 fi
 * 1) Run mount again to visually verify everything removed

if tr "-" " " | awk '{print $1}'` != "VMware" ; then # Email yourself the info that goes in both CRs email_workplan_physical echo -ne "Copy the below input into the child EMC Disk Removal CR (the one you cut to GSMO)\n\n`/net/gutstools.am.lilly.com/tools/SunOS/emc/inq.linux -clariion`" | mailx -s "Child CR for $(uname -n)" $EMAIL echo "Email sent" touch /tmp/done5partial
 * 1) SAN Removal for physical servers

elif tr "-" " " | awk '{print $1}'` = "VMware" ; then # Email yourself the workplan email_workplan_vm fi exit echo "Press ENTER to return to the menu or CTRL-C to exit" read junk
 * 1) SAN Removal for virtual servers

code