#!/bin/sh # Make this the active xCAT EMS. # # CHANGE HISTORY: # # NAME: active-mn # # SYNTAX: active-mn -i -v [-m ] # # DESCRIPTION: Make this node be the active xCAT MN. # # FLAGS: # -i the nic that the virtual ip address attaches to, # for AIX, it could be en0 or en1 or ..., # for Linux, it could be eth0:1 or eth1:2 or ... # -v virtual ip address # -m netmask for the virtual ip address, # default to 255.255.255.0 # # DEPENDENCIES: # # CHANGE HISTORY: # # Date Author Vers. Description # ----------------------------------------------------------------------------- # 2011-12-08 JDW 1.0 Original # 2013-06-06 xCAT 1.1 Updated version to ship with xCAT # 2017-10-17 xCAT 2.13.8 Enhance SHAREDVG=sharedvg # For AIX, shared volumn group name DBDIR=/var/lib/pgsql # database directory SHAREDFS="/install /etc/xcat /root/.xcat" # Shared file systems USEDFM=no # if DFM is being used USENTP=no # if NTP is being used POWER775=no # Power 775 cluster USETEAL=no # if TEAL is being used USEMOUNT=yes # mounted filesystems in the file /etc/fstab CHANGEHOSTNAME=yes # set the hostname to the virtual ip address hostname RESTARTDNS=yes # if yes, will execute "makedns -n" exit_code=0 xcatdb=postgresql # support postgrel,DB2,mysql usage() { cat << EOF Usage: $PROGNAME -i -v [-m ] EOF } runcmd() { echo "Running command: $@" a=0 while true do if [ $a -eq 5 ]; then echo "$@ [Failed]" exit_code=1 return 1 elif [ $a -gt 0 ]; then sleep 3 echo "Retry $a ...... $@" fi $@ if [ $? -eq 0 ]; then echo "$@ [Passed]" return 0 else a=$[$a+1] fi done } clear_env() { NIC=$1 ifconfig $NIC 0.0.0.0 0.0.0.0 2>/dev/null } ################################################################################ PROGNAME=$(basename $0) while getopts ':fi:v:m:' opt do case "$opt" in f) FAILOVER="true" ;; i) NIC=$OPTARG ;; v) VIP=$OPTARG ;; m) MASK=$OPTARG ;; *) usage exit 1 ;; esac done # NIC is a required option if [ -z $NIC ] then echo "Error: -i is a required option" usage exit 1 fi # Virtual IP is a required option if [ -z $VIP ] then echo "Error: -v is a required option" usage exit 1 fi if [ -z $MASK ] then MASK="255.255.255.0" fi ############################################################################## # Changing IP addresses/aliases for the active mn # Use ping to check if Virtual IP is already up and running on another mn # Important to avoid configuring virtual ip on both Primary and Standby concurrently ping -c 1 -w 10 $VIP 2>&1 1>/dev/null VIP_UP=$? if [ $VIP_UP -eq 0 ] then echo "$PROGNAME: Aborted startup as virtual ip appears to be already active" exit 2 fi echo "Changing IP addreses/aliases...." if [ `uname` = "AIX" ] then runcmd "ifconfig $NIC firstalias $VIP netmask $MASK up" else # Linux runcmd "ifconfig $NIC $VIP netmask $MASK" fi # Optional, Set hostname to virtual ip hostname if [ $CHANGEHOSTNAME = "yes" ] then if [ `uname` = "AIX" ] then HOST_VIP=`host $VIP | awk -F ' ' '{print $1}'` else # Linux HOSTVIP=`getent hosts $VIP | awk -F ' ' '{print $2}'` fi runcmd "hostname ${HOST_VIP}" fi # Acquire shared storage and mount fiesystems if [ `uname` = "AIX" ] then runcmd "varyonvg $SHAREDVG" fi if [ $USEMOUNT = "yes" ] then for fs in $SHAREDFS $DBDIR do runcmd "mount $fs" done else echo "Warning: share data $SHAREDFS $DBDIR should be mounted before." fi # check if DB is matched in linux if [ `uname` = "Linux" ]; then echo "Check DB...." if [ -s /etc/xcat/cfgloc ] then xcatcfg=`cat /etc/xcat/cfgloc|cut -f 1 -d : 2>/dev/null` else # SQLsite xcatcfg=`XCATBYPASS=1 /opt/xcat/bin/lsxcatd -d | cut -f 2 -d "=" 2>/dev/null` # filter Error message from lsxcatd echo "$xcatcfg" | grep "Error" && xcatcfg="" fi if [ -n "$xcatcfg" ]; then current_db=$xcatcfg if [ $xcatcfg = "Pg" ] then current_db="postgresql" fi echo "Current database is $current_db." if [ $current_db != "$xcatdb" ] then echo "Error: current DB $current_db is not matched with $xcatdb. [Failed]" clear_env $NIC exit 1 else echo "DB is matched with $xcatdb [Passed]" fi else echo "Error: can not get current DB. [Failed]" clear_env $NIC exit 1 fi fi # Start NFS echo "Export NFS filesystems and start NFS...." if [ `uname` = "AIX" ] then runcmd "exportfs -a" runcmd "startsrc -g nfs" else runcmd "exportfs -a" runcmd "service nfs restart" fi if [ $USENTP = "yes" ] then if [ `uname` = "AIX" ] then echo "Reconfiguring NTP...." runcmd "stopsrc -s xntpd" #cp /usr/local/cfg/ntp.conf.primary /etc/ntp.conf runcmd "startsrc -s xntpd" fi fi ############################################################################## echo "Starting $xcatdb...." if [ `uname` = "AIX" ] then if [ $xcatdb = "DB2" ] then runcmd "su - xcatdb -c \"db2start\"" elif [ $DATABASE = "mysql" ] then runcmd "startsrc -g mysql" fi else # Linux if [ $xcatdb != "SQLite" ] then runcmd "service $xcatdb start" if [ $? -eq 0 ] then XCATBYPASS=1 tabdump site >/dev/null if [ $? -ne 0 ] then echo "Error: cannot connect $xcatdb [Failed], exit...." clear_env $NIC exit 1 fi else echo "Error: service $xcatdb start [Failed], exit...." clear_env $NIC exit 1 fi fi fi echo "Starting xCAT...." if [ `uname` = "AIX" ] then runcmd "/opt/xcat/sbin/restartxcatd" else # Linux runcmd "service xcatd restart" if [ $? -ne 0 ] then echo "Error: failed to restart xcatd. exiting...." clear_env $NIC exit 1 else tabdump site >/dev/null if [ $? -ne 0 ] then echo "Error: failed to restart xcatd. exiting...." clear_env $NIC exit 1 fi fi fi #echo "Start xCAT on the Service Nodes...." #xdsh service -t 30 "/opt/xcat/sbin/restartxcatd" if [ $USEDFM = "yes" ] then echo "Starting Hardware Server...." if [ `uname` = "AIX" ] then runcmd "startsrc -s hdwr_svr" else # Linux runcmd "service hdwr_svr start" fi # Create hardware connections definitions runcmd "mkhwconn frame -t 2>&1 1>/dev/null" runcmd "mkhwconn frame -t -T fnm 2>&1 1>/dev/null" runcmd "mkhwconn cec -t" fi if [ POWER775 = "yes" ] then echo "Starting CNM daemon...." runcmd "chnwm -a" fi if [ USETEAL = "yes" ] then echo "Starting Teal...." if [ `uname` = "AIX" ] then runcmd "startsrc -s teal" else # Linux runcmd "service teal start" fi fi ############################################################################## #Re-make dns if [ $RESTARTDNS = "yes" ] then runcmd "makedns -n" fi # Re-make DHCP definitions echo "Making upto date DHCP configuration file...." runcmd "makedhcp -n" runcmd "makedhcp -a" #echo "Starting DHCP...." #Not necessary, makedhcp will take care of this #startsrc -s dhcpcd # Define Remote console definitions.... # Make Console Server definitions runcmd "makeconservercf" #echo "Starting Console Server...." #not necessary, makeconservercf will start conserver #startsrc -s conserver # Restore latest version of NIM database # Required only if failing over from other EMS if [ `uname` = "AIX" ] then DATE=$(date '+%Y-%m-%y-%T') NIM_BACKUP="/tmp/nim-backup.${DATE}" echo "Backing up NIM, just in case to ${NIM_BACKUP}...." runcmd "/usr/lpp/bos.sysmgt/nim/methods/m_backup_db ${NIM_BACKUP}" runcmd "nim -o unconfig master" echo "Restoring NIM database from shared backup...." # Find latest backup NIM_BACKUP=$(find /install/nim-backup | sort | tail -1) if [ -f "${NIM_BACKUP}" ] then runcmd "/usr/lpp/bos.sysmgt/nim/methods/m_restore_db ${NIM_BACKUP}" else echo "WARNING: No NIM backup file found!!" fi echo "Starting NIM...." runcmd "startsrc -s nimesis" fi ############################################################################## # Add CRON job entries for backup #echo "Adding Cron entries for backup...." #./cronEdit -a ./cron-root echo "" echo "" if [ $exit_code -eq 0 ]; then echo "This machine is set to active management node successfully, enjoy..." else echo "This machine is set to active management node, but some service failed..." fi exit $exit_code