server-retire-solaris

server_retire_solaris
supporting script is retire_support_solaris

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


 * 1)    Author:     Chad Crider        #
 * 2)    Date Started:    2/22/2010        #
 * 3)    Purpose:    Master script to    #
 * 4)            automate or assist in    #
 * 5)            as much of the        #
 * 6)            retirement process as    #
 * 7)            possible.        #
 * 8)    Version:    1.0            #
 * 1)            possible.        #
 * 2)    Version:    1.0            #

export PATH="/usr/sbin:/usr/ccs/bin:/usr/bin:/usr/lib:$PATH:/etc:/usr/platform/$(/bin/uname -m)/sbin:/usr/tools/bin:/usr/bin:~/.bin:/usr/sfw/bin/:/usr/local/ bin"

ask_fqdn { LOCAL="y" FQHOST=`cat /etc/hosts | grep -v "#" | grep "$(hostname)\." | awk '{print $2}'` clear echo "You are currently running this script on `echo $FQHOST | tr '[:lower:]' '[:upper:]'`" echo "" echo -e "Is this the host that's being retired? [y/n] \c " read answer
 * 1) Get the FQDN from the user

if -z $answer ; then echo "Please answer with either y or n"       sleep 1 clear ask_fqdn fi }

ask_fqdn
 * 1) Inital call of ask_fqdn

get_fqdn { if [ "$answer" = "n" ]; then LOCAL="n" echo "" echo "*******************************************************" echo "* Please note that certain menu items can ONLY be run *" echo "* Directly on the host being retired.                *" echo "*******************************************************" echo "" echo "Please enter FQDN of host to be retired:" read FQHOST fi
 * 1) Get the FQDN from the user

if -z $FQHOST ; then echo "Please enter a FQDN" sleep 1 clear get_fqdn fi }

get_fqdn
 * 1) Inital call of get_fqdn

export FQHOST SHOST=`echo $FQHOST | tr "." " " | awk '{print $1}'` export SHOST DOMAIN=`echo $FQHOST | tr "." " " | awk '{print $2"."$3"."$4}'`
 * 1) Pull info from Hostedit

URL="" wget -q -O /tmp/$FQHOST $URL

grep "Machine not in host database" /tmp/$FQHOST > /dev/null && { echo "Unable to download the required info from HostEdit, exiting script."; echo "Please check spelling and connectivity and re-run the script."; exit 1; }
 * 1) Make sure we got the info from hostedit by seeing if /tmp/$FQHOST contains the error string

if tail -1 | sed -e :a -e 's/<[^>]*>//g;/" export EMAIL="$EMAIL" }
 * 1) Get user's USERID, construct EMAIL, and export it
 * 1) Sanitize the user's input to ensure 7 characters, all lowercase

get_user_id
 * 1) Call initial get_user_id

export FIXSENDMAIL="y" /net/cursor/scripts/retire_support_solaris export FIXSENDMAIL="n"
 * 1) Make sure sendmail is configured properly for the emails to send out

retire_notification_cr { if $EUID -ne 0 ; then echo "This step must be run as root" 1>&2 exit 1 fi
 * 1) Function to generate content for UNIX NOTIFICATION CR
 * 1) Check to see if the user is root

set DAYS Sat Sun Mon Tue Wed Thu Fri Sat set MONTHS Dec Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec DAY=$((`date +%e`)) MONTH=$((`date +%m` +1)) YEAR=`date +%Y` NDAY=`date +%u` if [ $MONTH -eq "13" ] then MONTH=1 set `cal $MONTH $YEAR` shift $(($# - 1)) DAY=$1 fi TMONTH=${MONTHS[MONTH]}
 * 1) Calculate the Anticipated retirement date

business_group=`cat /tmp/$FQHOST | sed -e :a -e 's/<[^>]*>//g;/ esac

/usr/platform/`uname -m`/sbin/prtdiag -v > /tmp/prtdiag.out
 * 1) Find answers

echo " The purpose of this CR is to document Unix server retirement requests and notify the Capacity Planning team when a server is being retired. Please fill in  the following information and assign this CR to Craig Storm.

Current Business Area of server being retired: $SUPPORT

Anticipated retirement date: $MONTH/$DAY/$YEAR

Hostname of server being retired: $FQHOST

OS: `uname`

OS Version: `uname -r`

Server Model: `cat /tmp/prtdiag.out | head -1 | awk '{print $6,$7,$8}'`

Number of CPUs: `/usr/sbin/psrinfo -p 2>/dev/null || psrinfo -v | grep MHz | awk '{print $6}' | wc -l 2>/dev/null`

CPU MHz (Run MHz): `psrinfo -v | grep MHz | awk '{print $6}' | uniq`

Amount of Memory: `cat /tmp/prtdiag.out | grep "Memory size:" | awk '{print $3}'`

Size and number of internal disks: `echo | format | grep SUN.*G | awk '{print $3}' | wc -l` Total `echo | format | grep SUN.*G | awk '{print $3}' | uniq -c`

Number of HBA ports: `cat /tmp/prtdiag.out | grep lpfc | wc -l`

Number of Network Interface ports: `ifconfig -a | grep -v ^lo | grep "^.*: " | wc -l`

If this server is clustered and is being redeployed as a standalone server, list the VCS license key:

`if [ -e /etc/llthosts ]; then /opt/VRTS/bin/vxlicrep | /usr/sfw/bin/ggrep -B 1 "  Product Name = VERITAS Cluster Server" | awk '{print $4}' | head -1 fi`

Has this server already been assigned for redeployment: Yes ____ No _x_

If yes, please identify the: Business area: Project name: Customer name:

=
====================== If the server will be sent to salvage, please do the following:

List the Veritas License Keys to be reclaimed:

1. Make sure the server is powered down. 2. Make sure that non-SAN disk drives have been removed and follow the disk drive destruction process to properly dispose of them. 3. Make sure that the server has been tagged for removal. 4. Remove the server from the rack or shelve and take it to the designated salvage area in the data center. 5. Make sure that the server has been physically moved to salvage. "; echo "Press ENTER to return to the menu or CTRL-C to exit" read junk }

retire_esm_cr {
 * 1) Function to Generate content for ESM Server Remove CR

echo " ESM-Server(s) Remove Profile This profile is used to request the removal of all ESM monitoring on any designated Server packages and/or Node Up/Down monitoring.

This request is for ESM Smarts & NetIQ removal and if a server has multiple business area monitoring packages (ie: GUTS, GBIP, MQSERIES, GUTS, or ISG) this request will also remove NetIQ packages.

If this request is only to remove NetIQ packages, please list below:

=
============ Required Information =========================

What Zone is server in - 1

Platform (Windows or UNIX) - UNIX

Physical Server(s) name (FQDN) - `echo $FQHOST | tr '[:lower:]' '[:upper:]'`

Server Physical IP address(s) to be Removed - `nslookup $FQHOST | grep Address | tail -1 | awk '{print $2}'`

Is this server clustered (Yes/No) - For a clustered server, if it is a NT(Windows) or HPUX server, provide Cluster Name(s) and the virtual (logical) IP addresses associated with the clusters -

Remove SMARTS Node up/down monitoring - Yes / No: Yes

ALL NETIQ monitoring will be removed - Yes/ No: Yes

Please list all packages to be removed: ALL "; echo "Press ENTER to return to the menu or CTRL-C to exit" read junk }

retire_dcremove_cr { clear echo -e " Please select the server's disposition: 1) Redeploy 2) Trade-in 3) Salvage 4) Rebuild 5) 22/6 Cage q) Go back to menu
 * 1) Function to Generate content for DCREMOVE CR

Selection: \c " read choice

case "$choice" in 1 ) DISPOSITION=REDEPLOY;; 2 ) DISPOSITION=TRADE-IN;; 3 ) DISPOSITION=SALVAGE;; 4 ) DISPOSITION=REBUILD echo "Enter server name" read SERVER ;; 5 ) DISPOSITION="22/6 CAGE"   SPECIAL="Please place this server in the 22/6 Cage"    ;; q ) display_menu esac

business_group=`cat /tmp/$FQHOST | sed -e :a -e 's/<[^>]*>//g;/ esac

    
 * 1) Fill in contact info - NAME and PHONE


 * 1) Get Serial Number

if $LOCAL = "y" ; then SERIAL=`cat /system.serial.number` else SERIAL=`nawk 'c-->b;$b~s{if(b)for(c=b+1;c>1;c--)print r[(NR-c+a)%b];print;             c=a}b{r[NR%b]=$b}' b=0 a=1 s="Serial Number " /tmp/$FQHOST | tail -1 | sed -e :a -e 's/<[^>]*>//g;/</N;//ba'` fi

echo "

Please answer as many of the following questions as possible:

Choose one of the following: (Note: UPPER CASE)
 * Reminder* Please indicate Value Cycle in Custom Field One.

$SUPPORT

Thanks.

PLEASE DO NOT COMBINE CHANGES FOR 22/5 AND 141/2 ON SAME REQUEST. (EXAMPLE: DCREMOVE FOR 2 SERVERS AT 22/5 AND 1 SERVER AT 141/2 ON SAME CR)  REQUEST WILL  BE NOT BE ACCEPTED.

Removal Process: The Platform group must power off all devices associated with the removal before facilities can complete this request.

Please complete all line items or the request will be returned to Requestor:

Process the cable removal for the following:

1. Device Name: $FQHOST

2. Which Data Center location (22/5, 141/2) `cat /tmp/$FQHOST | sed -e :a -e 's/<[^>]*>//g;/b;$b~s{if(b)for(c=b+1;c>1;c--)print r[(NR-c+a)%b];print;c=a}b{r[NR%b]=$b}' b=0 a=1 s="Floor/Room" /tmp/$FQHOST | tail -1 | sed -e :a -e 's/<[^>]*>//g;/</N;//ba'`

6. Special information important to this request: $SPECIAL

7. IP Address(s) to be removed: `nslookup $FQHOST | grep Address | tail -1 | awk '{print $2}'`

8. Final Disposition of Equipment: (choose one): Rebuild (Must enter new server name here)

$DISPOSITION $SERVER

-ALL QUESTIONS BELOW TO BE COMPLETED BY FACILITIES-

1. Please enter specific device location using new Grid pattern (in 22/5, use Column):

2. Cable type Being Removed (Ethernet, Rib, Terminal server, Fiber, Etc.):

3. Total number of cables being removed:

4. Cable Label Information for cables to be removed:

Ethernet     Switch __________ Slot _______  Port _______

Rib             Switch __________  Slot _______  Port _______

Terminal server  Name __________    Port _______

Fiber        Name __________    Port _______

Hub         Name __________    Port _______

Modem Phone Number: ___________

5. Number of power circuits to be removed.

6. Circuit ID(s)

7. 5. Special information important to this request:

- "; echo "Press ENTER to return to the menu or CTRL-C to exit" read junk }

ts_instructions { clear echo "1) Locate the correct term server using HostEdit Private" echo "2) SSH to the TS as  using current  password" echo "3) su over to root using the current  root password" echo "4) Run the following command - vi /etc/portslave/pslave.conf" echo "5) Search for $SHOST and change it to say retired" echo "6) Save changes and close the file" echo "" echo "7) Then run the following command to save your changes to the" echo "  term server and update the menu:" echo "   if [ -e /bin/runconf ]; then runconf;saveconf; else signal_ras hup;saveconf;fi" echo "" echo "Press ENTER to return to the menu or CTRL-C to exit" read junk }
 * 1) Function to display the term server instructions

display_menu { clear if -e /tmp/done1 ; then DONE1="DONE"; fi if  -e /tmp/done2 ; then DONE2="DONE"; fi if  -e /tmp/done3 ; then DONE3="DONE"; fi if  -e /tmp/done4 ; then DONE4="DONE"; fi if  -e /tmp/done5partial ; then DONE5="PARTIAL"; fi if  -e /tmp/done5 ; then DONE5="DONE"; fi if  -e /tmp/done6 ; then DONE6="DONE"; fi if  -e /tmp/done7 ; then DONE7="DONE"; fi if  -e /tmp/done8 ; then DONE8="DONE"; fi
 * 1) Function to Display the menu
 * 1) Check for "done" steps and LOCAL status

if $LOCAL = "n" ; then DONE3="DISABLED"; fi if  $LOCAL = "n" ; then DONE5="DISABLED"; fi if  $LOCAL = "n" ; then DONE9="DISABLED"; fi
 * 1) Check for disabled steps

grep ldap` && LDAP="Yes" || LDAP="No" if $LDAP = "No" ; then DONE6="DISABLED"; fi
 * 1) Check for LDAP

-d  && BACKUP="\n***  FOUND.  Please cut a child CR to remove backups. ***\n" || BACKUP="\n*** /usr/openv NOT FOUND.  No need to remove backups. ***"
 * 1) Check for /usr/openv

echo -e " - Retirement for `echo $FQHOST | tr '[:lower:]' '[:upper:]'` to be used in conjunction with <REMOVED> -
 * 1) Display the menu

1)$DONE1   Send Retirement Notification email to <REMOVED>    (satisfies step 2.1 of <REMOVED>)

2)$DONE2     Email yourself the latest sysreport        (retrieves info required section 2.2 step 2)

3)$DONE3   Generate content for UNIX RETIREMENT NOTIFICATION CR        *MUST BE RUN AS ROOT FROM SERVER BEING RETIRED    (retrieves info required for section 2.2 step 3)

4)$DONE4   Generate content for ESM Server Remove CR    (retrieves info required for section 2.2 step 4) $BACKUP 5)$DONE5      Process the EMC and DGC Disk Removals% *MUST BE RUN AS ROOT FROM SERVER BEING RETIRED (retreives info required for section 2.2 step 7)

v)   Verify disks removed by GSMO    (Displays inq output for 5 seconds)

6)$DONE6     LDAP found? $LDAP    Remove LDAP Netgroup    See <REMOVED> for the web app    (assists in section 2.2 step 11)

7)$DONE7     Generate content for DCREMOVE CR        (retrieves info required for section 2.2 step 14)

8)$DONE8   Remove entry from terminal server    For instructions on updating the term servers manually, press t

9)$DONE9   Perform graceful 30 seconds shutdown of host    *MUST BE RUN AS ROOT FROM SERVER BEING RETIRED    (satisfies section 2.2 step 12)

Selection [1-9,v,t,q]: \c " read choice

case "$choice" in 1 ) # Send Retirement Notification email to <REMOVED>       su $USERID -c 'echo | mailx -s "$SHOST is going down for retirement " <REMOVED>' || { echo "mailx couldn't send email, exiting."; exit 1; }        echo "Email sent"        sleep 1        touch /tmp/done1        display_menu        ;;    2 ) # Email yourself the latest sysreport sed '1,/<OL>/ d' /tmp/$FQHOST | sed -e :a -e 's/<[^>]*>//g;/</ N;//ba' > /tmp/report su $USERID -c 'mailx -s " Latest Sysreport for $SHOST" $EMAIL < /tmp/report' || { echo "mailx couldn't send email, exiting."; exit 1; } echo "Email sent" rm /tmp/report sleep 1 touch /tmp/done2 display_menu ;;   3 ) # Generate content for UNIX RETIREMENT NOTIFICATION CR        if  $LOCAL = "n" ; then                        echo "This step MUST be run from the host being retired, exiting."            sleep 2            display_menu                fi        retire_notification_cr        touch /tmp/done3        display_menu        ;;    4 ) # Generate content for ESM Server Remove CR        retire_esm_cr touch /tmp/done4 display_menu ;;   5 ) # Process the EMC and DGC Disk Removals            if  $DONE5 = "DISABLED" ; then                    echo "This step has either been disabled or MUST be run from the host being retired, exiting."                    sleep 2            display_menu                fi                echo "This step will perform changes to the system including umounting"        echo "filesystems and stopping some key services."        echo "To back out after this step has run, the server will have to be rebooted."        echo -e "Proceed? [y/n] \c "                read answer                if [ "$answer" = "y" ]; then                       /net/cursor/scripts/retire_support_solaris               display_menu                else                        display_menu                fi        ;;    v ) # Verify disks removed by running inq <REMOVED>/inq | egrep "EMC|DGC" sleep 5 display_menu ;;   6 ) # Remove LDAP Netgroup        if  $DONE6 = "DISABLED" ; then            echo "This box doesn't use LDAP.  Step disabled."            sleep 2            display_menu        fi        # Send the needed variables to the supporting script        export REMOVENETGROUP="y"        export NETGROUP="$SHOST"        /net/cursor/scripts/retire_support_solaris        export REMOVENETGROUP="n"        display_menu        ;;        7 ) # Generate content for DCREMOVE CR                retire_dcremove_cr touch /tmp/done7 echo "As root on <REMOVED>, run <REMOVED>" | mailx -s "REMINDER: Remove $SHOST from Master Sudoers" $EMAIL display_menu ;;   8 ) # Remove entry from terminal server        export REMOVE_TS="y"        /net/cursor/scripts/retire_support_solaris        display_menu        ;;    9 ) # Perform graceful 30 seconds shutdown of host if $LOCAL = "n" ; then echo "This step MUST be run from the host being retired, exiting." sleep 2 display_menu fi       echo "Shutting Down Host..." echo -e "Are you sure you want to power host down completely? [y/n] \c " read answer if [ "$answer" = "y" ]; then /usr/sbin/shutdown -g0 -i5 -y # Monitor ping to know when server is down while ping $FQHOST > /dev/null 2>&1; do sleep 7; echo "$FQHOST is still up"; done; echo "$FQHOST is down...(stopped responding to ping)" else display_menu fi       ;; q ) # Quit script       exit 0        ;;    t ) # Display instructions for updating the term servers clear ts_instructions display_menu ;;   * ) # For invalid menu choices, re-run the menu        echo "Invalid selection"        sleep 2        display_menu        ;;    esac

}

if $LOCAL = "y" ; then clear echo "Checking for SAN devices..." echo "This may take a minute depending on how much SAN there is." <REMOVED>/inq | egrep -e 'EMC|DGC' > /tmp/sanresults # Disable option 5 if the server has no SAN attached and email the non-SAN workplan ! -s /tmp/sanresults && DONE5="DISABLED" &&  ! -e /tmp/nosan  && echo -ne "Work Plan:\n=========\nRetirement will be done according to UNX-OSI-007 Version 3.0\n\nVerification:\n============\nFrom UNX-OSI-007 Version 3.0:\nVerify all applicable child CR?s 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 "Non-SAN workplan for $SHOST" $EMAIL touch /tmp/nosan fi
 * 1) Check for SAN

display_menu
 * 1) Call initial menu

code