lang en_US network --onboot=yes --bootproto=dhcp --device=xx:xx:xx:xx:xx:xx # xCAT url web repository #url --url http://xcat/install/rhels6.5/x86_64 %include /tmp/repos keyboard "us" zerombr #clearpart --all --initlabel clearpart --drives=sda,sdb key --skip #text cmdline part / --fstype=ext4 --size=167936 --ondisk=sda --label=ROOT part /boot/efi --fstype=efi --size=537 --ondisk=sda part /dump --fstype=ext4 --size=20480 --ondisk=sda --label=DUMP #part swap --size=4096 --ondisk=sda part /local --fstype=ext4 --size=102400 --grow --ondisk=sdb --label=LOCAL #bootloader bootloader --append="hugepages=2000 " install firewall --disabled timezone --utc "XXXXXXXXXXXXXX" skipx rootpw --iscrypted XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX #auth --useshadow --enablemd5 auth --useshadow --passalgo=sha512 selinux --disabled reboot %packages apr atk autofs bc cairo expat gcc gcc-c++ gcc-gfortran glib2 glibc glibc-devel glibc-headers gtk2 kernel-devel kernel-headers ksh libgcc libnl libnl.i686 libstdc++ libstdc++-devel libxml2-python m4 make nc net-snmp nfs-utils nscd ntp numactl openssh-server pciutils perl pkgconfig python rsh rsync ruby strace sysstat tcl tcsh tk %end %pre { echo "Running Kickstart Pre-Installation script..." export XCATDEBUGMODE="1" if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then set -x fi if grep n8r /proc/cmdline > /dev/null 2>&1; then stty crtscts fi for x in 0 1 2 3 4 5 6 7 8 do mknod /dev/vcs$x c 7 $x mknod /dev/vcsa$x c 7 $[$x+128] done chmod 644 /dev/vcs* chown root /dev/vcs* if [ -r /tmp/updates/etc/pki/tls/certs/ca-bundle.crt ]; then cp -f /tmp/updates/etc/pki/tls/certs/ca-bundle.crt /etc/pki/tls/certs/ fi #there is no boot option to set dns search domain in kickstart file, #the search domain in /etc/resolv.conf is set in the pre installation script export MANAGEDADDRESSMODE= export SEARCHDOMAIN=XXXXXXXXXXXXXXXXXXXX if [ "$MANAGEDADDRESSMODE" == "static" ]; then echo "#appended by %pre " >> /etc/resolv.conf echo "search $SEARCHDOMAIN" >> /etc/resolv.conf fi cat >/tmp/baz.py </tmp/foo.py < 0): percent = int(((count - 2) * 100)/numpack + .5) if(percent > 100): percent = 100 if(percent < 0): percent = 0 r2 = re.compile("^Installing (.*)\.") m2 = r2.search(line) if m2: newline = m2.group(1) newline = newline + " (" newline = newline + str(percent) newline = newline + "%)" # newline = newline + " [" # count = count - 2 # newline = newline + str(count) # newline = newline + "/" # newline = newline + str(numpack) # newline = newline + "]" else: newline = "prep" line = "installing " + newline if(line and post and not pre): line = "installing " + line if(not line): line = "installing prep" newSocket.send(line) break if(command[0] == "sh"): #DEBUG purposes only, wide open root priv command here. newcommand = "" for i in command[1:]: newcommand = newcommand + i + " " output = os.popen(newcommand).read() newSocket.send(output) break if(command[0] == "screendump"): newcommand = "cat /dev/vcs" for i in command[1:]: newcommand = newcommand + i output = os.popen(newcommand).read() newSocket.send(output) break newSocket.close() finally: sock.close() EOF chmod 755 /tmp/foo.py chmod 755 /tmp/baz.py NODESTATUS= if [ -z "$NODESTATUS" ] || [ "$NODESTATUS" != "0" -a "$NODESTATUS" != "N" -a "$NODESTATUS" != "n" ]; then /tmp/baz.py "installstatus installing" & fi /tmp/foo.py >/foo.log 2>&1 & #time to ascertain fstype and PReP/UEFI/legacy #also, find first available block device (sda or vda likely) #TODO: pick a likely non-SAN target if possible shopt -s nullglob # # The getinstdisk script is common for RHEL/SLES/PowerKVM/Ubuntu. # It will attempt to select the install disk and write the selection to /tmp/xcat.install_disk # #!/bin/sh #----------------------------------------------------------- # # Get proper disk to install OS # # 1. Check all partitions list in /proc/partitions, whether # there is disk had OS installed. If there is, add it to # the disk array. # 2. If there is disk had OS installed, check disks list # generated in Step 1. Else, check all disks get from # /proc/partitions file. Sort them by WWN/PATH and driver # type, select the first one. # 3. Select the default one: /dev/sda. # # Output: /tmp/xcat.install_disk # #----------------------------------------------------------- install_disk="" install_disk_file="/tmp/xcat.install_disk" tmpdir="/tmp/xcat.getinstalldisk" mkdir -p $tmpdir has_awk=$(find /usr/* -name "awk") utolcmd="sed -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/" tmpfile="$tmpdir/getinstalldisk_" if [ -z "$install_disk" ]; then echo "[get_install_disk]Information from /proc/partitions:" cat /proc/partitions echo "" # Get all partitions and disks from /proc/partitions file if [ -z "$has_awk" ]; then entries=$(cat /proc/partitions | sed 's/ */ /g' | cut -d " " -f5 | grep -v "name" | grep -e "[s|h|v]d.*$") else entries=$(awk -F ' ' '{print $4}' /proc/partitions | grep -v "name" | grep -e "[s|h|v]d.*$") fi # Classify entries by DEVTYPE for entry in $entries; do if [ -z "$has_awk" ]; then dev_type=$(udevadm info --query=property --name=/dev/$entry | grep -i "DEVTYPE" | cut -d "=" -f2 | $utolcmd) else dev_type=$(udevadm info --query=property --name=/dev/$entry | grep -i "DEVTYPE" | awk -F = '{print $2}' | $utolcmd) fi if [ "$dev_type" == "disk" ]; then disks=$disks"$entry " elif [ "$dev_type" == "partition" ]; then partitions=$partitions"$entry " fi done mount_dir=$tmpdir"/xcat.getinstalldisk.mount" mkdir -p $mount_dir; disk_array="" for partition in $partitions; do echo "[get_install_disk]Check the partition $partition." if [ -e "$tmpfile${partition%%[0-9]*}" ]; then echo "[get_install_disk] The disk ${partition%%[0-9]*} had OS installed, check next partition." continue fi # Get partition's fs_type if [ -z "$has_awk" ]; then fs_type=$(udevadm info --query=property --name=/dev/$partition | grep -i "FS_TYPE" | cut -d "=" -f2) else fs_type=$(udevadm info --query=property --name=/dev/$partition | grep -i "FS_TYPE" | awk -F = '{print $2}') fi rc=255 # Mount partition based on fs type, if fs_type is "swap", do not mount it, jump to next partition. if [ -z "$fs_type" ]; then mount /dev/$partition $mount_dir rc=$? elif [ "$fs_type" != "swap" ]; then mount -t $fs_type /dev/$partition $mount_dir rc=$? fi # Check whether mount successfully if [ $rc -eq 0 ]; then echo "[get_install_disk] Partition $partition mount success." ker_dir=$mount_dir if [ -d "$mount_dir/boot" ]; then ker_dir="$mount_dir/boot" fi # If there is kernel file, add partition's disk into disk_array # It seems the kernel file in ubuntu and sles are named like vmlinux, but in RH it is called vmlinuz # To check both vmlinux and vmlinuz, use regular expression "vmlinu*" to match them for i in $ker_dir/vmlinu*; do disk_part=${partition%%[0-9]*} touch "$tmpfile$disk_part" disk_array=$disk_array"$disk_part " echo "[get_install_disk] The partition $partition has kernel file." break done umount -l $mount_dir || echo "[get_install_disk] $partition umount failed." else echo "[get_install_disk] Partition $partition mount failed or the partition is swap." fi done # If disk_array is not empty, make disks equal disk_array for next step to sort if [ "$disk_array" ]; then disks=$disk_array echo "[get_install_disk]The disks which have kernel:" echo "[get_install_disk] $disks" echo "" fi rmdir $mount_dir; for file in $tmpfile*; do rm $file; done has_wwn=0 has_path=0 file_pre="" disk_data="" # Check disks which had installed OS, or check all disks in /proc/partitions for disk in $disks; do # Get disk's information: WWN, PATH and DRIVER disk_info=$(udevadm info --query=property --name=$disk) output_for_wwn=$(IFS= ;echo $disk_info | grep '\' | cut -d "=" -f2) disk_wwn=$(echo $output_for_wwn | $utolcmd) output_for_path=$(IFS= ;echo $disk_info | grep DEVPATH | cut -d "=" -f2) disk_path=$(echo $output_for_path | $utolcmd) disk_driver=$(udevadm info --attribute-walk --name=$disk | grep DRIVERS| grep -v '""'| grep -v '"sd"'| \head -n 1| sed -e 's/[^"]*"//' -e 's/"//' | $utolcmd) echo "[get_install_disk]The disk $disk information: " echo "[get_install_disk] disk_wwn=$disk_wwn" echo "[get_install_disk] disk_path=$disk_path" echo "[get_install_disk] disk_driver=$disk_driver" # Check whether there is WWN, PATH information if [ "$disk_wwn" ]; then has_wwn=1 file_pre="wwn" disk_data=$disk_wwn elif [ $has_wwn -eq 1 ]; then echo "[get_install_disk] The disk $disk has no wwn info." echo "[get_install_disk] There is other disk has wwn info, so don't record this disk." continue; elif [ "$disk_path" ]; then has_path=1 file_pre="path" disk_data=$disk_path elif [ $has_path -eq 1 ]; then echo "[get_install_disk] The disk $disk has no wwn or path info." echo "[get_install_disk] There is other disk has path info, so don't record this disk." continue; else file_pre="other" disk_data="" fi # Sort disks by DRIVER type case "$disk_driver" in "ata_piix"*|"PMC MaxRAID"|"ahci"|"megaraid_sas") echo "$disk $disk_data" >> "$tmpfile""$file_pre""firstchoicedisks" echo "[get_install_disk] Add disk: $disk $disk_data into $file_pre firstchoicedisks" ;; "mptsas"|"mpt2sas"|"mpt3sas") echo "$disk $disk_data" >> "$tmpfile""$file_pre""secondchoicedisks" echo "[get_install_disk] Add disk: $disk $disk_data into $file_pre secondchoicedisks" ;; *) echo "$disk $disk_data" >> "$tmpfile""$file_pre""thirdchoicedisks" echo "[get_install_disk] Add disk: $disk $disk_data into $file_pre thirdchoicedisks" ;; esac done for seq in first second third; do if [ -s $tmpfile$file_pre${seq}choicedisks ]; then install_file="$tmpfile$file_pre${seq}choicedisks" break fi done if [ "$install_file" ] && [ -s $install_file ]; then install_disk=/dev/$(cat $install_file | grep -v "^$" | sort -k 2 -b | cut -d " " -f1 | head -n 1) echo "[get_install_disk]The install_disk is $install_disk by sorting $file_pre and DRIVER." fi for file in $tmpfile*; do rm $file; done fi rm -rf $tmpdir; # Cannot find proper disk for OS install, select the default one "/dev/sda" if [ -z "$install_disk" ]; then install_disk="/dev/sda" echo "[get_install_disk]The default install_disk is $install_disk." fi # Output the result to $install_disk_file echo $install_disk > $install_disk_file if [ -e "/tmp/xcat.install_disk" ]; then instdisk=`cat /tmp/xcat.install_disk` fi modprobe ext4 >& /dev/null modprobe ext4dev >& /dev/null if grep ext4dev /proc/filesystems > /dev/null; then FSTYPE=ext3 elif grep ext4 /proc/filesystems > /dev/null; then FSTYPE=ext4 else FSTYPE=ext3 fi BOOTFSTYPE=ext3 EFIFSTYPE=vfat if [ `uname -m` = "ppc64" ]; then echo 'part None --fstype "PPC PReP Boot" --ondisk '$instdisk' --size 8' >> /tmp/partitionfile fi if [ -d /sys/firmware/efi ]; then echo 'bootloader --driveorder='$instdisk >> /tmp/partitionfile echo 'part /boot/efi --size 50 --ondisk '$instdisk' --fstype '$EFIFSTYPE >> /tmp/partitionfile else echo 'bootloader' >> /tmp/partitionfile fi #TODO: ondisk detection, /dev/disk/by-id/edd-int13_dev80 for legacy maybe, and no idea about efi. at least maybe blacklist SAN if mptsas/mpt2sas/megaraid_sas seen... echo "part /boot --size 256 --fstype $BOOTFSTYPE --ondisk $instdisk" >> /tmp/partitionfile echo "part swap --recommended --ondisk $instdisk" >> /tmp/partitionfile echo "part / --size 1 --grow --ondisk $instdisk --fstype $FSTYPE" >> /tmp/partitionfile #XCA_PARTITION_SCRIPT# #save the content of /tmp/partitionfile in /var/log/xcat/xcat.log #so that we can inspect the partition scheme after installation echo "=================The Partition Scheme================" cat /tmp/partitionfile echo "=====================================================" # The following code is to generate the repository for the installation cat /proc/cmdline NEXTSERVER=`cat /proc/cmdline | grep http | head -n 1` NEXTSERVER=${NEXTSERVER#*http://} NEXTSERVER=${NEXTSERVER%%:*} export nextserver=$NEXTSERVER echo 'url --url http://'$nextserver'//install/rhels6.5/x86_64' >> /tmp/repos if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then set +x fi dd bs=512 count=10 if=/dev/zero of=/dev/sda dd bs=512 count=10 if=/dev/zero of=/dev/sdb parted --script /dev/sda mklabel gpt parted --script /dev/sdb mklabel gpt parted --script /dev/sda print parted --script /dev/sdb print sleep 30 } >>/tmp/pre-install.log 2>&1 %end %post #exec < /dev/tty6 > /dev/tty6 2>/dev/tty6 #chvt 6 ## ## # Setup hostname # echo "post scripts" >/root/post.log [ $XCATDEBUGMODE ] || export XCATDEBUGMODE="0" [ $MASTER_IP ] || export MASTER_IP="XX.XX.XX.XX" declare -F msgutil_r &>/dev/null || function msgutil_r { local logserver=$1 local msgtype=$2 local msgstr=$3 local logfile=$4 if [ -z "$msgtype" ]; then msgtype="debug" fi if [ -n "$logserver" ];then logger -n $logserver -t xcat -p local4.$msgtype "$msgstr" if [ "$?" != "0" ];then exec 3<>/dev/udp/$logserver/514 >/dev/null;logger -s -t xcat -p local4.$msgtype "$msgstr" 2>&3 if [ "$?" != "0" ];then logger -s -t xcat -p local4.$msgtype "$msgstr" 2>&1|nc $logserver 514 >/dev/null 2>&1 if [ "$?" != "0" ];then logger -t xcat -p local4.$msgtype "$msgstr" fi fi fi else logger -t xcat -p local4.$msgtype "$msgstr" fi if [ -n "$logfile" ]; then local logdir="$(dirname $logfile)" if [ ! -d "$logdir" ]; then mkdir -p "$logdir" touch "$logfile" fi echo "$msgstr" >> $logfile fi } declare -F msgutil &>/dev/null || function msgutil { msgutil_r "" "$@" } export PRINIC= if [ "$PRINIC" == "mac" ] then export PRINIC='xx:xx:xx:xx:xx:xx' fi if [ -z "$PRINIC" ] then for karg in $(cat /proc/cmdline |sed -e 's/-/:/g' -e 's/ /\n/g'); do if [ "${karg%%=*}" = "BOOTIF" ]; then MACADDR="${karg#*=}"; #The BOOTIF in pxelinux will be the MAC address with the hardware type code as a prefix #such as BOOTIF=XX-XX-XX-XX-XX-XX-90 if [ "${#MACADDR}" == "20" ]; then MACADDR=${MACADDR:3:21} fi #export PRINIC=`ifconfig -a|grep -i "hwaddr ${karg#*=01:}"|awk '{print $1}'` export PRINIC=`ip -o link|grep -i "$MACADDR"|awk '{print $2}'|sed s/://` fi done if [ -z "$PRINIC" ]; then export PRINIC=eth0 fi fi if [ -z "$PRINIC" ] then export PRINIC=eth0 elif [[ `echo "$PRINIC" | grep -sqE ^[A-Fa-f0-9]+:[A-Fa-f0-9]+:[A-Fa-f0-9]+:[A-Fa-f0-9]+:[A-Fa-f0-9]+:[A-Fa-f0-9]+$ ;echo $?` == "0" ]]; then #export PRINIC=`ifconfig -a | grep -i "HWaddr $PRINIC" | awk '{print $1}'` export PRINIC=`ip -o link|grep -i "$PRINIC"|awk '{print $2}'|sed s/://` fi #IP=$(ifconfig $PRINIC | grep inet | awk '{print $2}' | awk -F: '{print $2}') IP=$(ip -4 -o a sh dev $PRINIC | awk '/inet/{print $4}' | head -n 1 | awk -F '/' '{print $1}') if [ -z "$IP" ] then dhclient $PRINIC #IP=$(ifconfig $PRINIC | grep inet | awk '{print $2}' | awk -F: '{print $2}') IP=$(ip -4 -o a sh dev $PRINIC | awk '/inet/{print $4}' | head -n 1 | awk -F '/' '{print $1}') fi export HOSTNAME=$(host $IP 2>/dev/null | awk '{print $5}' | awk -F. '{print $1}') if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "PRINIC=$PRINIC, IP=$IP,HOSTNAME=$HOSTNAME" "/var/log/xcat/xcat.log" fi hostname $HOSTNAME if [ -f /boot/efi/efi/redhat/grub.conf ]; then #RedHat bug, grub.efi corrupts console unless we are careful... sed -i s/^terminal.*// /boot/efi/efi/redhat/grub.conf bootpart=$(sed -e 's/#.*//' /boot/efi/efi/redhat/grub.conf |grep root|grep -v kernel|head -n 1|awk '{print $2}') bootpart="${bootpart%\\n}" sed -i s!^serial.*!splashimage=$bootpart/boot/grub/splash.xpm.gz! /boot/efi/efi/redhat/grub.conf fi # # Run xCAT post install # export MASTER_IP="XX.XX.XX.XX" export MASTER="xcat" export NODESTATUS="" export XCATIPORT=3002 export INSTALLDIR=/install export TFTPDIR=/tftpboot export XCATDEBUGMODE="1" declare -F msgutil_r &>/dev/null || function msgutil_r { local logserver=$1 local msgtype=$2 local msgstr=$3 local logfile=$4 if [ -z "$msgtype" ]; then msgtype="debug" fi if [ -n "$logserver" ];then logger -n $logserver -t xcat -p local4.$msgtype "$msgstr" if [ "$?" != "0" ];then exec 3<>/dev/udp/$logserver/514 >/dev/null;logger -s -t xcat -p local4.$msgtype "$msgstr" 2>&3 if [ "$?" != "0" ];then logger -s -t xcat -p local4.$msgtype "$msgstr" 2>&1|nc $logserver 514 >/dev/null 2>&1 if [ "$?" != "0" ];then logger -t xcat -p local4.$msgtype "$msgstr" fi fi fi else logger -t xcat -p local4.$msgtype "$msgstr" fi if [ -n "$logfile" ]; then local logdir="$(dirname $logfile)" if [ ! -d "$logdir" ]; then mkdir -p "$logdir" touch "$logfile" fi echo "$msgstr" >> $logfile fi } declare -F msgutil &>/dev/null || function msgutil { msgutil_r "" "$@" } if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then set -x fi if [ -z "$XCATIPORT" ]; then XCATIPORT="3002" fi if [ -z "$INSTALLDIR" ]; then INSTALLDIR="/install" fi if [ -z "$TFTPDIR" ]; then TFTPDIR="/tftpboot" fi if [[ $TFTPDIR != /* ]]; then TFTPDIR="/"$TFTPDIR fi NODESTATUS=$(echo "$NODESTATUS"| tr -d \'\"| tr A-Z a-z) (cat << 'EOF' #!/usr/bin/awk -f # IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html BEGIN { xcatdhost = ARGV[1] xcatdport = ARGV[2] flag = ARGV[3] if (!flag) flag = "next" ns = "/inet/tcp/0/" xcatdhost "/" xcatdport loop = 0 while(1) { if((ns |& getline) > 0) print $0 | "logger -t xcat -p local4.info" else { print "Retrying flag update" | "logger -t xcat -p local4.info" print "updateflag.awk: Retrying flag update" >> "/var/log/xcat/xcat.log" close(ns) system("sleep 10") loop = loop + 1 } if($0 == "ready") print flag |& ns if($0 == "done") break if(loop > 10) { print "flag update failed" | "logger -t xcat -p local4.info" print "updateflag.awk: flag update failed" >> "/var/log/xcat/xcat.log" break } } close(ns) exit 0 } EOF ) >/tmp/updateflag chmod 0755 /tmp/updateflag cd /tmp RAND=$(perl -e 'print int(rand(50)). "\n"') if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "sleep $RAND" "/var/log/xcat/xcat.log" fi sleep $RAND # Stop if no openssl to help the next bit if [ ! -x /usr/bin/openssl ]; then msgutil_r "$MASTER_IP" "debug" "/usr/bin/openssl does not exist, halt ..." "/var/log/xcat/xcat.log" /tmp/updateflag $MASTER $XCATIPORT "installstatus failed" sleep 36500d fi #save to /opt/xcat/xcatinfo file if [ ! -f /opt/xcat/xcatinfo ]; then mkdir -p /opt/xcat touch /opt/xcat/xcatinfo fi grep 'XCATSERVER' /opt/xcat/xcatinfo > /dev/null 2>&1 if [ $? -eq 0 ]; then sed -i "s/XCATSERVER=.*/XCATSERVER=$MASTER_IP/" /opt/xcat/xcatinfo else echo "XCATSERVER=$MASTER_IP" >> /opt/xcat/xcatinfo fi grep 'INSTALLDIR' /opt/xcat/xcatinfo > /dev/null 2>&1 if [ $? -eq 0 ]; then sed -i "s/INSTALLDIR=.*/INSTALLDIR=$INSTALLDIR/" /opt/xcat/xcatinfo else echo "INSTALLDIR=$INSTALLDIR" >> /opt/xcat/xcatinfo fi if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "/opt/xcat/xcatinfo generated" "/var/log/xcat/xcat.log" fi # download the postscripts if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "trying to download postscripts from http://$MASTER_IP$INSTALLDIR/postscripts/" "/var/log/xcat/xcat.log" fi # Stop if no wget to help the next bit if [ ! -x /usr/bin/wget ]; then msgutil_r "$MASTER_IP" "debug" "/usr/bin/wget does not exist, halt ..." "/var/log/xcat/xcat.log" /tmp/updateflag $MASTER $XCATIPORT "installstatus failed" sleep 36500d fi wget -l inf -N -r --waitretry=10 --random-wait --retry-connrefused -e robots=off -nH --cut-dirs=2 --reject "index.html*" --no-parent -t 20 -T 60 http://$MASTER_IP$INSTALLDIR/postscripts/ -P /xcatpost if [ "$?" != "0" ]; then msgutil_r "$MASTER_IP" "debug" "failed to download postscripts from http://$MASTER_IP$INSTALLDIR/postscripts/, halt ..." "/var/log/xcat/xcat.log" /tmp/updateflag $MASTER $XCATIPORT "installstatus failed" sleep 36500d fi chmod -R +x `find /xcatpost/ -maxdepth 1 -print | grep -E -v '^(/xcatpost/|/xcatpost/_xcat|/xcatpost/_ssh|/xcatpost/ca|/xcatpost/hostkeys)$'` if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "postscripts downloaded successfully" "/var/log/xcat/xcat.log" fi # get the precreated mypostscript file if [ -x /xcatpost/mypostscript ]; then rm -rf /xcatpost/mypostscript fi export NODE=n1 if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "trying to download precreated mypostscript file http://$MASTER_IP$TFTPDIR/mypostscripts/mypostscript.$NODE" "/var/log/xcat/xcat.log" fi wget -N --waitretry=10 --random-wait --retry-connrefused -t 20 -T 60 http://$MASTER_IP$TFTPDIR/mypostscripts/mypostscript.$NODE -P /xcatpost 2> /tmp/wget.log if [ "$?" = "0" ]; then if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "precreated mypostscript downloaded successfully" "/var/log/xcat/xcat.log" fi mv /xcatpost/mypostscript.$NODE /xcatpost/mypostscript chmod 700 /xcatpost/mypostscript fi USEOPENSSLFORXCAT=1 #Though this is the only method going forward, flag to allow backward compatibility with 2.2 generated netboot images export USEOPENSSLFORXCAT XCATSERVER=$MASTER_IP:3001 export XCATSERVER # If mypostscript doesn't exist, we will get it through getpostscript.awk if [ ! -x /xcatpost/mypostscript ]; then if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "failed to download precreated mypostscript, trying to generate with getpostscript.awk" "/var/log/xcat/xcat.log" fi # To support the postscripts in the subdirectories under /install/postscripts # chmod +x /xcatpost/* # Stop if no getpostscript.awk to help the next bit if [ ! -x /xcatpost/getpostscript.awk ]; then msgutil_r "$MASTER_IP" "debug" "/xcatpost/getpostscript.awk does not exist, halt ..." "/var/log/xcat/xcat.log" /tmp/updateflag $MASTER $XCATIPORT "installstatus failed" sleep 36500d fi /xcatpost/getpostscript.awk |egrep ''|sed -e 's/<[^>]*>//g'|egrep -v '^ *$'|sed -e 's/^ *//' | sed -e 's/<//g' -e 's/&/\&/g' -e 's/"/"/g' -e "s/'/'/g" > /xcatpost/mypostscript MYCONT=`grep ^MASTER= /xcatpost/mypostscript` RETRY=0 while [ -z "$MYCONT" ]; do RETRY=$(($RETRY+1)) if [ $RETRY -eq "10" ]; then break fi let SLI=$RANDOM%10+10 sleep $SLI /xcatpost/getpostscript.awk |egrep ''|sed -e 's/<[^>]*>//g'|egrep -v '^ *$'|sed -e 's/^ *//' | sed -e 's/<//g' -e 's/&/\&/g' -e 's/"/"/g' -e "s/'/'/g" > /xcatpost/mypostscript MYCONT=`grep ^MASTER= /xcatpost/mypostscript` done fi TMP=`sed "/^#\s*postscripts-start-here/,/^#\s*postscripts-end-here/ s/\(.*\)/run_ps postscript \1/;s/run_ps postscript\s*#/#/;s/run_ps postscript\s*$//" /xcatpost/mypostscript` echo "$TMP" > /xcatpost/mypostscript TMP=`sed "/^#\s*postbootscripts-start-here/,/^#\s*postbootscripts-end-here/ s/\(.*\)/run_ps postbootscript \1/;s/run_ps postbootscript\s*#/#/;s/run_ps postbootscript\s*$//" /xcatpost/mypostscript` cd /xcatpost #gunzip xcatpost.tar.gz #tar -xvf xcatpost.tar #/xcatpost/n1 export PATH=$PATH:/xcatpost # use the run_ps subroutine to run the postscripts if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then echo "set -x" > /xcatpost/mypostscript else cat /dev/null > /xcatpost/mypostscript fi echo " . /xcatpost/xcatlib.sh # global value to store the running status of the postbootscripts,the value is non-zero if one postbootscript failed return_value=0 # subroutine used to run postscripts # \$1 argument is the script type # rest argument is the script name and arguments run_ps () { local ret_local=0 mkdir -p "\"/var/log/xcat\"" # On some Linux distro, the rsyslogd daemon write log files with permision # other than root:root. And in some case, the directory /var/log/xcat was # created by xCAT, and had root:root ownership. In this way, rsyslogd # did not have enough permission to write to log files under this directory. # As a dirty hack, change the ownership of directory /var/log/xcat to the # same ownership of directory /var/log. chown `ls -ld /var/log | awk '{ print \$3\":\"\$4 }'` "\"/var/log/xcat\"" local logfile=\"/var/log/xcat/xcat.log\" local scriptype=\$1 shift; if [ -z \"\$scriptype\" ]; then scriptype=\"postscript\" fi if [ -f \$1 ]; then msgutil_r \"\$MASTER_IP\" \"info\" "\"\`date\` Running \$scriptype: \$1\"" \"\$logfile\" if [ \"\$XCATDEBUGMODE\" = \"1\" ] || [ \"\$XCATDEBUGMODE\" = \"2\" ]; then local compt=\$(file \$1) local reg=\"shell script\" if [[ \"\$compt\" =~ \$reg ]]; then bash -x ./\$@ 2>&1 ret_local=\$? else ./\$@ 2>&1 | logger -t xcat -p debug ret_local=\${PIPESTATUS[0]} fi else ./\$@ 2>&1 ret_local=\${PIPESTATUS[0]} fi if [ \"\$ret_local\" -ne \"0\" ]; then return_value=\$ret_local fi msgutil_r \"\$MASTER_IP\" \"info\" "\"\`date\` \$scriptype \$1 return with \$ret_local\"" \"\$logfile\" else msgutil_r \"\$MASTER_IP\" \"info\" "\"\`date\` \$scriptype \$1 does NOT exist.\"" \"\$logfile\" return_value=-1 fi return 0 } # subroutine end " >> /xcatpost/mypostscript echo "$TMP" >> /xcatpost/mypostscript if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then echo "set +x" >> /xcatpost/mypostscript fi chmod +x /xcatpost/mypostscript if [ ! -x /xcatpost/mypostscript ]; then msgutil_r "$MASTER_IP" "debug" "generate mypostscript file failure, halt ..." "/var/log/xcat/xcat.log" /tmp/updateflag $MASTER $XCATIPORT "installstatus failed" sleep 36500d else if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "generate mypostscript file successfully" "/var/log/xcat/xcat.log" fi fi #save the postboot scripts to /xcatpost/mypostscript.post TMP=`sed "/^#\s*postscripts-start-here/,/^#\s*postscripts-end-here/ d" /xcatpost/mypostscript` echo "$TMP" > /xcatpost/mypostscript.post chmod 755 /xcatpost/mypostscript.post if [ ! -x /xcatpost/mypostscript.post ]; then if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "failed to generate /xcatpost/mypostscript.post" "/var/log/xcat/xcat.log" fi else if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "/xcatpost/mypostscript.post generated" "/var/log/xcat/xcat.log" fi fi export OSVER=rhels6.5 #create the post init service as a hook to run PS and PBS, as well as status updating hassystemd=0 systemctl --version 2>/dev/null if [ $? -eq 0 ]; then hassystemd=1 fi if [ $hassystemd -eq 1 ] ; then cat >/etc/systemd/system/xcatpostinit1.service <<'EOF' [Unit] Description=xcat service on compute node, the framework to run postbootscript and update node status After=network.target rsyslog.service [Service] Type=oneshot ExecStart=/opt/xcat/xcatpostinit1 start ExecStop=/opt/xcat/xcatpostinit1 stop RemainAfterExit=yes [Install] WantedBy=multi-user.target EOF msgutil_r "$MASTER_IP" "debug" "/etc/systemd/system/xcatpostinit1.service generated" "/var/log/xcat/xcat.log" ln -s /etc/systemd/system/xcatpostinit1.service /etc/systemd/system/multi-user.target.wants/xcatpostinit1.service msgutil_r "$MASTER_IP" "debug" "xcatpostinit1.service enabled" "/var/log/xcat/xcat.log" cat >/opt/xcat/xcatpostinit1 << 'EOF' #!/bin/bash # IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html # chkconfig: 345 84 59 # description: the hook for systemd service unit to run PB and report node status on diskful node # processname: xcatpostinit1 ### BEGIN INIT INFO # Provides: xcatpostinit1 # Required-Start: $network $syslog # Should-Start: # Required-Stop: $network $syslog # Should-Stop: # Default-Start: 3 4 5 # Default-Stop: 0 1 2 6 # Short-Description: hook to run xcat PBS and report node status # Description: ### END INIT INFO # Source function library. if [ -x /etc/rc.d/init.d/functions ]; then . /etc/rc.d/init.d/functions fi [ -f /opt/xcat/xcatinfo ] && XCATSERVER=`grep 'XCATSERVER' /opt/xcat/xcatinfo |cut -d= -f2 | tr -d \'\" ` [ -f /xcatpost/mypostscript ] && NODESTATUS=`grep 'NODESTATUS=' /xcatpost/mypostscript |awk -F = '{print $2}'|tr -d \'\" | tr A-Z a-z ` [ -z "$NODESTATUS" ] && NODESTATUS="1" [ -f /xcatpost/mypostscript ] && RUNBOOTSCRIPTS=`grep 'RUNBOOTSCRIPTS=' /xcatpost/mypostscript |awk -F = '{print $2}' | tr -d \'\" | tr A-Z a-z ` case $1 in stop) [ "$NODESTATUS" != "n" ] && /xcatpost/updateflag.awk $XCATSERVER 3002 "installstatus powering-off" ;; start) # check for the REBOOT specified in xcatinfo to run post boot scripts on reboot if [ -f /opt/xcat/xcatinfo ]; then REBOOT=`grep 'REBOOT' /opt/xcat/xcatinfo |cut -d= -f2 | tr -d \'\"` fi # if the xcatdsklspost file exists and this is a reboot - run xcatdsklspost with a mode of 6 if [ "$REBOOT" = "TRUE" -a -r /opt/xcat/xcatdsklspost ] && [[ "$RUNBOOTSCRIPTS" =~ ^(1|yes|y)$ ]]; then /opt/xcat/xcatdsklspost 6 elif [ "$REBOOT" = "TRUE" ] && [[ "$NODESTATUS" =~ ^(1|yes|y)$ ]]; then /xcatpost/updateflag.awk $XCATSERVER 3002 "installstatus booted" else # run /opt/xcat/xcatinstallpost if [ -r /opt/xcat/xcatinstallpost ]; then /opt/xcat/xcatinstallpost fi fi ;; esac EOF chmod 755 /opt/xcat/xcatpostinit1 else cat >/etc/init.d/xcatpostinit1 << 'EOF' #!/bin/bash # IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html # chkconfig: 345 84 59 # description: the hook for systemd service unit to run PB and report node status on diskful node # processname: xcatpostinit1 ### BEGIN INIT INFO # Provides: xcatpostinit1 # Required-Start: $network $syslog # Should-Start: # Required-Stop: $network $syslog # Should-Stop: # Default-Start: 3 4 5 # Default-Stop: 0 1 2 6 # Short-Description: hook to run xcat PBS and report node status # Description: ### END INIT INFO # Source function library. if [ -x /etc/rc.d/init.d/functions ]; then . /etc/rc.d/init.d/functions fi [ -f /opt/xcat/xcatinfo ] && XCATSERVER=`grep 'XCATSERVER' /opt/xcat/xcatinfo |cut -d= -f2 | tr -d \'\" ` [ -f /xcatpost/mypostscript ] && NODESTATUS=`grep 'NODESTATUS=' /xcatpost/mypostscript |awk -F = '{print $2}'|tr -d \'\" | tr A-Z a-z ` [ -z "$NODESTATUS" ] && NODESTATUS="1" [ -f /xcatpost/mypostscript ] && RUNBOOTSCRIPTS=`grep 'RUNBOOTSCRIPTS=' /xcatpost/mypostscript |awk -F = '{print $2}' | tr -d \'\" | tr A-Z a-z ` case $1 in stop) [ "$NODESTATUS" != "n" ] && /xcatpost/updateflag.awk $XCATSERVER 3002 "installstatus powering-off" ;; start) # check for the REBOOT specified in xcatinfo to run post boot scripts on reboot if [ -f /opt/xcat/xcatinfo ]; then REBOOT=`grep 'REBOOT' /opt/xcat/xcatinfo |cut -d= -f2 | tr -d \'\"` fi # if the xcatdsklspost file exists and this is a reboot - run xcatdsklspost with a mode of 6 if [ "$REBOOT" = "TRUE" -a -r /opt/xcat/xcatdsklspost ] && [[ "$RUNBOOTSCRIPTS" =~ ^(1|yes|y)$ ]]; then /opt/xcat/xcatdsklspost 6 elif [ "$REBOOT" = "TRUE" ] && [[ "$NODESTATUS" =~ ^(1|yes|y)$ ]]; then /xcatpost/updateflag.awk $XCATSERVER 3002 "installstatus booted" else # run /opt/xcat/xcatinstallpost if [ -r /opt/xcat/xcatinstallpost ]; then /opt/xcat/xcatinstallpost fi fi ;; esac EOF chmod 755 /etc/init.d/xcatpostinit1 if [ ! -x /etc/init.d/xcatpostinit1 ]; then if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "failed to generate /etc/init.d/xcatpostinit1" "/var/log/xcat/xcat.log" fi else if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "/etc/init.d/xcatpostinit1 generated" "/var/log/xcat/xcat.log" fi fi if [[ $OSVER == ubuntu* ]]; then ln -s /etc/init.d/xcatpostinit1 /etc/rc2.d/S84xcatpostinit1 else ln -s /etc/init.d/xcatpostinit1 /etc/rc.d/rc3.d/S84xcatpostinit1 ln -s /etc/init.d/xcatpostinit1 /etc/rc.d/rc4.d/S84xcatpostinit1 ln -s /etc/init.d/xcatpostinit1 /etc/rc.d/rc5.d/S84xcatpostinit1 fi if [[ $OSVER == ubuntu* ]]; then update-rc.d xcatpostinit1 defaults else if [[ $OSVER == sles* ]]; then if [[ $OSVER == sles10* ]]; then /sbin/insserv xcatpostinit1 else /sbin/insserv -p /etc/init.d xcatpostinit1 fi fi #chkconfig --add xcatpostinit1 chkconfig xcatpostinit1 on if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "service xcatpostinit1 enabled" "/var/log/xcat/xcat.log" fi fi fi #create the xcatinstallpost mkdir -p /opt/xcat cat >/opt/xcat/xcatinstallpost << 'EOF' #!/bin/bash # IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html ################################################################# # # xCAT script for running postboot scripts for full install case. ################################################################# . /xcatpost/xcatlib.sh if [ -f /xcatpost/mypostscript.post ]; then XCATDEBUGMODE=`grep 'XCATDEBUGMODE=' /xcatpost/mypostscript.post |cut -d= -f2 | tr -d \'\" | tr A-Z a-z ` MASTER_IP=`grep '^MASTER_IP=' /xcatpost/mypostscript.post |cut -d= -f2|sed s/\'//g` OSVER=`grep '^OSVER=' /xcatpost/mypostscript.post |cut -d= -f2|sed s/\'//g` NODE=`grep '^NODE=' /xcatpost/mypostscript.post |cut -d= -f2|sed s/\'//g` fi if [ ! `uname` = Linux ]; then msgutil_r "$MASTER_IP" "err" "$0: the OS name is not Linux" "/var/log/xcat/xcat.log" exit fi SLI=$(awk 'BEGIN{srand(); printf("%d\n",rand()*10)}') sleep $SLI XCATINFOFILE=/opt/xcat/xcatinfo MACADDR=`grep MACADDRESS= /xcatpost/mypostscript.post |awk -F = '{print $2}'|sed s/\'//g` INSTALLNIC=`ip -o link|grep -i $MACADDR|awk '{print $2}'|sed s/://` # the network between the node and MASTER might be not well configured and activated when running the PBS sometimes # need to make sure... RETRY=0 while true; do #check whether the network access between MN/CN and the node is ready ping $MASTER_IP -c 1 >/dev/null && break RETRY=$[ $RETRY + 1 ] if [ $RETRY -eq 90 ];then #timeout, complain and exit msgutil_r "$MASTER_IP" "err" "`date`: xcatinstallpost: the network between the node and $MASTER_IP is not ready, please check[retry=$RETRY]..." "/var/log/xcat/xcat.log" exit 1 fi #sleep sometime before the next scan sleep 2 done cd /xcatpost; PATH=/xcatpost:$PATH export PATH # To support the postscripts in the subdirectories under /install/postscripts #chmod +x /xcatpost/*; chmod -R +x `find /xcatpost/ -maxdepth 1 -print | grep -E -v '^(/xcatpost/|/xcatpost/_xcat|/xcatpost/_ssh|/xcatpost/ca|/xcatpost/hostkeys)$'` POST_IN_DIR="/xcatpost" if [ -x /usr/bin/openssl ]; then SIP=`grep "^MASTER=" ${POST_IN_DIR}/mypostscript.post |cut -d= -f2` XCATSERVER="$SIP:3001" export XCATSERVER USEOPENSSLFORXCAT=1 #Though this is the only method going forward, flag to allow backward compatibility with 2.2 generated netboot images export USEOPENSSLFORXCAT fi # Regardless of where mypostscript.post was found, modify and run it in /xcatpost. DHCP_TMP=`sed 's/\(DHCPINTERFACES=\)\(.*\)$/\1"\2"/' /xcatpost/mypostscript.post` echo "$DHCP_TMP" > /xcatpost/mypostscript.post #mark that the first reboot after installation is finished grep 'REBOOT' /opt/xcat/xcatinfo > /dev/null 2>&1 if [ $? -eq 0 ]; then sed -i "s/REBOOT=.*/REBOOT=TRUE/" /opt/xcat/xcatinfo else echo "REBOOT=TRUE" >> /opt/xcat/xcatinfo fi #add node name to xcatinfo grep 'NODE' /opt/xcat/xcatinfo > /dev/null 2>&1 if [ $? -eq 0 ]; then sed -i "s/NODE=.*/NODE=$NODE/" /opt/xcat/xcatinfo else echo "NODE=$NODE" >> /opt/xcat/xcatinfo fi # Store the SERVICEGROUP into the xcatinfo file for statful installation sn_group=`grep '^SERVICEGROUP' /xcatpost/mypostscript |cut -d= -f2 | tr -d \'\"` if [ "x" != "x$sn_group" ]; then # Change or add SERVICEGROUP line if service node pool defined. grep 'SERVICEGROUP=' $XCATINFOFILE > /dev/null 2>&1 if [ $? -eq 0 ]; then sed -i "s/SERVICEGROUP=.*/SERVICEGROUP=$sn_group/" $XCATINFOFILE else echo "SERVICEGROUP=$sn_group" >> $XCATINFOFILE fi else # Remove SERVICEGROUP line if no service node pool defined. sed -i "/SERVICEGROUP=.*/d" $XCATINFOFILE fi [ -f /xcatpost/mypostscript ] && NODESTATUS=`grep 'NODESTATUS=' /xcatpost/mypostscript |awk -F = '{print $2}'|tr -d \'\" | tr A-Z a-z ` [ -z "$NODESTATUS" ] && NODESTATUS="1" CNS=$NODESTATUS if [ -z "$CNS" ] || [[ "$CNS" =~ ^(1|yes|y)$ ]]; then #update the node status during the postbootscript running #TMP=`sed "/postbootscripts-start-here/ i\updateflag.awk \\$MASTER 3002 \\"installstatus configuring\\"" /xcatpost/mypostscript.post` #echo "$TMP"> /xcatpost/mypostscript.post echo " [ -f /opt/xcat/xcatinfo ] && grep 'POSTSCRIPTS_RC=1' /opt/xcat/xcatinfo >/dev/null 2>&1 && return_value=1 if [ \"\$return_value\" -eq \"0\" ]; then if [ \"\$XCATDEBUGMODE\" = \"1\" ] || [ \"\$XCATDEBUGMODE\" = \"2\" ]; then msgutil_r \"\$MASTER_IP\" \"info\" \"node booted, reporting status...\" \"/var/log/xcat/xcat.log\" fi updateflag.awk \$MASTER 3002 \"installstatus booted\" msgutil_r \$MASTER_IP \"info\" \"provision completed.(\$NODE)\" \"/var/log/xcat/xcat.log\" else if [ \"\$XCATDEBUGMODE\" = \"1\" ] || [ \"\$XCATDEBUGMODE\" = \"2\" ]; then msgutil_r \"\$MASTER_IP\" \"info\" \"node boot failed, reporting status...\" \"/var/log/xcat/xcat.log\" fi updateflag.awk \$MASTER 3002 \"installstatus failed\" fi " >> /xcatpost/mypostscript.post fi chmod +x /xcatpost/mypostscript.post if [ -x /xcatpost/mypostscript.post ];then msgutil_r "$MASTER_IP" "info" "running /xcatpost/mypostscript.post" "/var/log/xcat/xcat.log" /xcatpost/mypostscript.post msgutil_r "$MASTER_IP" "info" "/xcatpost/mypostscript.post return" "/var/log/xcat/xcat.log" fi if [ -f /xcatpost/mypostscript.post ]; then RUNBOOTSCRIPTS=`grep 'RUNBOOTSCRIPTS=' /xcatpost/mypostscript.post |cut -d= -f2 | tr -d \'\" | tr A-Z a-z` fi if [[ $OSVER == ubuntu* ]]; then if [[ ! "$RUNBOOTSCRIPTS" =~ ^(1|yes|y)$ ]]; then update-rc.d -f xcatpostinit1 remove fi if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "update-rc.d -f xcatpostinit1 remove" "/var/log/xcat/xcat.log" fi else if [[ ! "$RUNBOOTSCRIPTS" =~ ^(1|yes|y)$ ]] && [[ ! "$NODESTATUS" =~ ^(1|yes|y)$ ]]; then chkconfig xcatpostinit1 off if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "service xcatpostinit1 disabled" "/var/log/xcat/xcat.log" fi fi fi EOF chmod 755 /opt/xcat/xcatinstallpost if [ ! -x /opt/xcat/xcatinstallpost ]; then if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "failed to generate /opt/xcat/xcatinstallpost" "/var/log/xcat/xcat.log" fi else if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "/opt/xcat/xcatinstallpost generated" "/var/log/xcat/xcat.log" fi fi #create the dskls post cat >/opt/xcat/xcatdsklspost << 'EOF' #!/bin/bash # IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html ##################################################### # # Generic xCAT post script for diskless nodes # The syntax of this script: # xcatdsklspost {mode} {-m|-M} [postscripts] --tftp /tftpboot --installdir /install --nfsv4 no -c -V # This script is called in the following different places: # updatenode -P ... --> xcatdsklspost 1 -m/-M ... # updatenode -S --> xcatdsklspost 2 -m/-M otherpkgs # moncfg rmcmon --> xcatdsklspost 3 configrmcnodes # node deployment --> xcatdsklspost # statelite mode --> xcatdsklspost 4 # update security --> xcatdsklspost 5 -m/-M ... # node reboot - xcatpostinit1 --> xcatdsklspost 6 # This script has a debug mode, if XCATDEBUG env variable is set, then # /xcatpost becomes /xcatpost.. This allow running multiple # instances of the script to simulate many node on one physical node # ##################################################### [ -f "/xcatpost/xcatlib.sh" ] && . /xcatpost/xcatlib.sh if [ -f /xcatpost/mypostscript.post ]; then XCATDEBUGMODE=`grep 'XCATDEBUGMODE=' /xcatpost/mypostscript.post | cut -d= -f2 | tr -d \'\" | tr A-Z a-z` MASTER_IP=`grep '^MASTER_IP=' /xcatpost/mypostscript.post |cut -d= -f2|sed s/\'//g` else for param in `cat /proc/cmdline`; do key=`echo $param|awk -F= '{print $1}'` if [ "$key" = "xcatdebugmode" ]; then XCATDEBUGMODE=`echo $param|awk -F= '{print $2}'| tr -d \'\" | tr A-Z a-z` fi if [ "$key" = "LOGSERVER" ]; then MASTER_IP=`echo $param|awk -F= '{print $2}'` fi done fi XCATINFOFILE=/opt/xcat/xcatinfo #echolog: process message log and echo in xcatdsklspost #arguments: # msgtype: message type, valid values:debug,info,warning,err # msgstr : the string of message #description: # echo messages only when ($msgtype != debug) or ($msgtype = debug && $VERBOSE = 1) # log "debug" messages only when (site.xcatdebugmode=1),log all messages with other types # append the "debug" messages to "/var/log/xcat/xcat.log" when (site.xcatdebugmode=1) # append all the other type messages to "/var/log/xcat/xcat.log" echolog() { local msgtype=$1 local msgstr=$2 local ismsgutil_r=1 #if msgutil_r is not defined, when no /xcatpost directory exists on the node running this script #write the message to local log file as a simplified function type -t msgutil_r >/dev/null || ismsgutil_r=0 [ "$ismsgutil_r" = "0" ] && msgutil_r () { echo "$(date) [$2]: $3" >> $4 } if [ "$msgtype" = "debug" ];then if [ "$VERBOSE" = "1" ]; then echo "$msgstr" fi if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "$msgtype" "$msgstr" "/var/log/xcat/xcat.log" fi else echo "$msgstr" msgutil_r "$MASTER_IP" "$msgtype" "$msgstr" "/var/log/xcat/xcat.log" fi #reload the functions defined in./xcatlib.sh if [ "$ismsgutil_r" = "0" ];then unset msgutil_r [ -f ./xcatlib.sh ] && source ./xcatlib.sh fi } update_VPD() { if [ -f /usr/sbin/vpdupdate ]; then vpdupdate #logger -t xCAT -p local4.info "xcatdsklspost: updating VPD database" echolog "info" "xcatdsklspost: updating VPD database" fi } # Run updatevpd only when necessary if [ -f /usr/sbin/lsvpd ]; then /usr/sbin/lsvpd | grep -i -E 'cpu|processor' 2>&1 1>/dev/null if [ "$?" = "1" ]; then update_VPD fi fi download_postscripts() { server=$1 if [ -z $server ]; then return 1; fi # Do not override the parameter --installdir if [ -z "$INSTALLDIR" ]; then if [ -f /opt/xcat/xcatinfo ]; then INSTALLDIR=`grep 'INSTALLDIR' /opt/xcat/xcatinfo |cut -d= -f2` fi if [ -z "$INSTALLDIR" ]; then INSTALLDIR="/install" fi fi #logger -t xCAT -p local4.debug "$0 : trying to download postscripts from http://$server$INSTALLDIR/postscripts/" echolog "debug" "xcatdsklspost : trying to download postscripts from http://$server$INSTALLDIR/postscripts/" max_retries=5 retry=0 rc=1 # this is a fail return while [ 0 -eq 0 ]; do if [ -e "$xcatpost" ]; then rm -rf "$xcatpost" fi export LANG=C; wget -l inf -nH -N -r --waitretry=10 --random-wait -e robots=off -T 60 -nH --cut-dirs=2 --reject "index.html*" --no-parent http://$server$INSTALLDIR/postscripts/ -P /$xcatpost 2> /tmp/wget.log rc=$? if [ $rc -eq 0 ]; then # return from wget was 0 but some OS do not return errors, so we # have additional checks for # failed: Connection httpd not running # 404: Not Found - if directory does not exist grep -i -E "... failed: Connection refused.$" /tmp/wget.log rc1=$? grep -i -E "ERROR 404: Not Found.$" /tmp/wget.log rc2=$? # check to see no errors at all, grep returns 1 if [ $rc1 -eq 1 ] && [ $rc2 -eq 1 ]; then echolog "debug" "$0 : download_postscripts return successfully " return 0 fi fi retry=$(($retry+1)) echolog "debug" "download_postscripts retry $retry" if [ $retry -eq $max_retries ]; then echolog "debug" "$0 : download_postscripts failed" break fi SLI=$(awk 'BEGIN{srand(); printf("%d\n",rand()*20)}') sleep $SLI done return $rc } download_mypostscript() { server=$1 node=$2 max_retries=$3 TFTPDIR=$4 if [ -z $server ]; then return 1; fi if [ -z "$TFTPDIR" ]; then TFTPDIR="/tftpboot" fi retry=0 rc=1 echolog "debug" "$0 : trying to download http://$server$TFTPDIR/mypostscripts/mypostscript.$node" while [ 0 -eq 0 ]; do wget -N --waitretry=10 --random-wait -T 60 http://$server$TFTPDIR/mypostscripts/mypostscript.$node -P /$xcatpost 2>> /tmp/wget.log rc=$? # if no error and the file was downloaded if [ $rc -eq 0 ] && [ -f /$xcatpost/mypostscript.$node ]; then mv /$xcatpost/mypostscript.$node /$xcatpost/mypostscript echolog "debug" "$0 download_mypostscript return successfully " return 0; fi retry=$(($retry+1)) if [ $retry -eq $max_retries ]; then echolog "debug" "$0 : download_mypostscript failed" break fi done return $rc } # pmatch determines if 1st argument string is matched by 2nd argument pattern pmatch () { case $1 in $2) return 0;; # zero return code means string matched by pattern esac return 1 # non-zero return code means string not matched by pattern } # Main # parse the arguments ARGNUM=$#; if [ -z $1 ]; then NODE_DEPLOYMENT=1 else NODE_DEPLOYMENT=0 case $1 in 1|2|5) MODE=$1 if [ $ARGNUM -gt 1 ]; then if [ $2 = "-m" ]; then P_SIP=$3 else if [ $2 = "-M" ]; then P_SIP=$3 new_ms=$P_SIP # -M means we will update xcatinfo file XCATSERVER fi fi fi if [ $ARGNUM -gt 3 ]; then POSTSCRIPTS=$4 fi if [ $ARGNUM -gt 4 ]; then if [ $5 = "--tftp" ]; then TFTPDIR=$6 fi fi if [ $ARGNUM -gt 6 ]; then if [ $7 = "--installdir" ]; then INSTALLDIR=$8 fi fi if [ $ARGNUM -gt 8 ]; then if [ $9 = "--nfsv4" ]; then NFSV4=${10} fi fi if [ $ARGNUM -gt 10 ]; then if [ ${11} = "-c" ]; then CFLAG=${11} fi fi if [ $ARGNUM -gt 11 ]; then if [ ${12} = "-V" ]; then export VERBOSE=1 fi if [ ${12} = "-F" ]; then export USEFLOWCONTROL=1 fi fi if [ $ARGNUM -gt 12 ]; then if [ ${13} = "-V" ]; then export VERBOSE=1 fi fi ;; 3|4|6) MODE=$1;; esac fi # set the default path for the xcatpost directory xcatpost="/xcatpost" # Check for debug mode and you have nodename available you can change the path for debug echolog "debug" "running $0 $*" if [ -n "$XCATDEBUG" ]; then if [ -n "$NODE" ]; then xcatpost="/xcatpost.$NODE" fi fi #echo "xcatpost = $xcatpost" useflowcontrol=0 if [ "$USEFLOWCONTROL" = "1" ]; then useflowcontrol=1 fi # from install kcmdline if [ "$FC" = "1" ] || [ "$FC" = "yes" ] || [ "$FC" = "YES" ]; then useflowcontrol=1 fi # If on AIX node if [ ! `uname` = Linux ]; then #Get a new copy of xcataixpost on the node mkdir -p /$xcatpost; mkdir -p /xcatmnt; if [ "$NFSV4" = "yes" ]; then mount -o vers=4 $P_SIP:$INSTALLDIR/postscripts /xcatmnt else mount $P_SIP:$INSTALLDIR/postscripts /xcatmnt fi cp /xcatmnt/xcataixpost /$xcatpost umount /xcatmnt rmdir /xcatmnt logger -t xcat -p local4.err "Running xcataixpost $*" # note not supporting -F or -V on AIX echo "/$xcatpost/xcataixpost $1 $2 $3 '"$4"' $5 $6 $7 $8 $9 ${10} ${11}" exec /$xcatpost/xcataixpost $1 $2 $3 "$4" $5 $6 $7 $8 $9 ${10} ${11} exit fi #SLI=$(awk 'BEGIN{srand(); printf("%d\n",rand()*10)}') #sleep $SLI if [ ! -d /$xcatpost ]; then mkdir -p /$xcatpost; fi if [ ! -d /tmp/postage ]; then mkdir -p /tmp/postage fi rm -R -f /tmp/postage/* #here we get all the postscripts. Please do not change this behaviour because some scripts depend on others cd /tmp/postage if [ "$MODE" = "4" ]; then # for statelite mode # We have written the xCATSERVER info into the kernel command line!! for i in `cat /proc/cmdline`; do KEY=`echo $i | awk -F= '{print $1}'` if [ "$KEY" = "XCAT" ]; then TMP=`echo $i | awk -F= '{print $2}'` XCATSERVER=`echo $TMP | cut -d: -f1` grep 'XCATSERVER' /opt/xcat/xcatinfo > /dev/null 2>&1 if [ $? -eq 0 ]; then sed -i "s/XCATSERVER=.*/XCATSERVER=$XCATSERVER/" /opt/xcat/xcatinfo else echo "XCATSERVER=$XCATSERVER" >> /opt/xcat/xcatinfo fi break fi done if [ -f /opt/xcat/xcatinfo ]; then SIP=`grep 'XCATSERVER' /opt/xcat/xcatinfo |cut -d= -f2` if [ -n "$SIP" ]; then download_postscripts $SIP if [ $? -eq 0 ]; then downloaded=1 fi fi else #echo "xCAT management server IP can't be determined."; #echo "exiting..."; #logger -t xCAT -p local4.err "xcatdsklspost:xCAT management server IP can't be determined.\nexiting..."; echolog "err" "xcatdsklspost:xCAT management server IP can't be determined.\nexiting..." exit; fi else # for common mode MODE=1,2,3,5 (updatenode,moncfg,node deployment) # non-Statelite MODE # If we have written the NODE info into the kernel command line, # put in in xcatinfo if [ ! -f /opt/xcat/xcatinfo ]; then mkdir -p /opt/xcat touch /opt/xcat/xcatinfo fi for i in `cat /proc/cmdline`; do KEY=`echo $i | awk -F= '{print $1}'` if [ "$KEY" = "NODE" ]; then NODE=`echo $i | awk -F= '{print $2}'` break fi done grep 'NODE' /opt/xcat/xcatinfo > /dev/null 2>&1 if [ $? -eq 0 ]; then sed -i "s/NODE=.*/NODE=$NODE/" /opt/xcat/xcatinfo else echo "NODE=$NODE" >> /opt/xcat/xcatinfo fi downloaded=0; # have not downloaded the postscripts # try the -m/-M input (P_SIP) if it is specified, # -m/-M is passed in the updatenode command # and is the address of the xcatmaster for this node. Using -M just means # also update the XCATSERVER in the /etc/xcat/xcatinfo file with this # address if [ -n "$P_SIP" ]; then # passed in with updatenode on -M/-m SIP=$P_SIP download_postscripts $SIP if [ $? -eq 0 ]; then downloaded=1 fi fi # if the download failed then, if not updatenode # open the xcatinfo file to look for an XCATSERVER address to try # if the address if not the same as the one on the -m/M flag then # try it if [ $downloaded -eq 0 ]; then # if this is an updatenode call, then stop trying and # return an error if [ "$MODE" = "1" ] || [ "$MODE" = "2" ] || [ "$MODE" = "5" ]; then # updatenode hn=`hostname` #echo "Cannot download the postscripts from $SIP for $hn check /tmp/wget.log on the node." #logger -t xCAT -p local4.err "xcatdsklspost:Cannot download the postscripts from the xCAT server $SIP for node $hn check /tmp/wget.log on the node." echolog "err" "xcatdsklspost:Cannot download the postscripts from the xCAT server $SIP for node $hn check /tmp/wget.log on the node." exit fi # if not updatenode, then look in xcatinfo for the xcatmaster if [ -f /opt/xcat/xcatinfo ]; then SIP=`grep 'XCATSERVER' /opt/xcat/xcatinfo |cut -d= -f2` if [ -n "$SIP" ]; then download_postscripts $SIP if [ $? -eq 0 ]; then downloaded=1 fi fi fi fi # download postscripts has not worked yet if [ $downloaded -eq 0 ]; then # for the non-updatenode calls try the host in the XCAT kernel param. for i in `cat /proc/cmdline`; do KEY=`echo $i | awk -F= '{print $1}'` if [ "$KEY" = "XCAT" ]; then TMP=`echo $i | awk -F= '{print $2}'` SIP=`echo $TMP | cut -d: -f1` if [ -n "$SIP" ]; then download_postscripts $SIP if [ $? -eq 0 ]; then downloaded=1 break fi fi fi done fi # download poscripts has not worked yet #try the dhcp server, this is used for initial boot for the node. if [ $downloaded -eq 0 ]; then #setup $OSVER ,for SLES11 if [ -e '/etc/SuSE-release' ]; then OSVER=`grep -h VERSION /etc/SuSE-release |awk '{print $3}'` fi SIPS=`grep -h dhcp-server-identifier /var/lib/dhclient/dhclient*eth*.leases 2> /dev/null|awk '{print $3}'|sed -e 's/;//'` if [ -z "$SIPS" ]; then SIPS=`grep -h dhcp-server-identifier /var/lib/dhclient/dhclient*hf*.leases 2> /dev/null|awk '{print $3}'|sed -e 's/;//'` if [ -z "$SIPS" ]; then SIPS=`grep -h DHCPSID /var/lib/dhcpcd/*.info 2> /dev/null|awk -F= '{print $2}'|sed -e s/\'//g` fi fi SIP=`echo $SIPS|awk '{printf $NF}' | tail -n 1` #Pick one for wget if [ -n "$SIP" ]; then download_postscripts $SIP if [ $? -eq 0 ]; then downloaded=1 fi elif [ -x "/sbin/dhcpcd" ]; then # New dhcpcd doesn't creates *.info files. for lease in $(ls "/var/lib/dhcpcd/"); do iface="$(echo "$lease" | sed -n -e 's/^dhcpcd-\(.*\)\.lease$/\1/p')" if [ -n "$iface" ]; then SIP="$(dhcpcd -q -T "$iface" | sed -n -e '/new_dhcp_server_identifier/ s/.*=//p')" if [ -n "$SIP" ]; then download_postscripts $SIP if [ $? -eq 0 ]; then downloaded=1 break fi fi fi done fi fi #no hope to download postscripts, now let's get out of here. if [ $downloaded -eq 0 ]; then hn=`hostname` #echo "Cannot download the postscripts from the xCAT server for node $hn" #logger -t xCAT -p local4.err "xcatdsklspost:Cannot download the postscripts from the xCAT server for node $hn" echolog "err" "xcatdsklspost: Cannot download the postscripts from the xCAT server for node $hn" exit else echolog "info" "xcatdsklspost: downloaded postscripts successfully" fi fi # finish the postscripts download # remove the current mypostscript file rm -rf /$xcatpost/mypostscript # if NODE is exported ( updatenode call or from kernel parameter) # use it as the nodename to get the mypostscript file. if [ -n "$NODE" ]; then node_short=$NODE else #get node name and download the mypostscript.$node file #try to get the node ip address that connects to the server. #then resolve the name of the ip real_SIP=`getent hosts $SIP |awk {'print $1'}` if [ $? -ne 0 ]; then real_SIP=$SIP fi NIP=`ip route get $real_SIP | head -n 1 | sed 's/^.*src//g' | awk {'print $1'}` if [ $? -eq 0 ] && [ -n "$NIP" ]; then #resolve the name of the node from ip address result=`getent hosts $NIP` if [ $? -eq 0 ]; then node1=`echo $result | awk {'print $2'}` node2=`echo $result | awk {'print $3'}` if [ ${#node1} -gt ${#node2} ]; then node=$node1 node_short=$node2 else node=$node2 node_short=$node1 fi if [ -z "$node_short" ]; then node_short=`echo $node |awk -F. {'print $1'}` fi else if [ -z "$node" ]; then node=`hostname` node_short=`hostname -s` fi fi else node=`hostname` node_short=`hostname -s` fi fi max_retries=2 # try short hostname first if [ -n "$node_short" ]; then download_mypostscript $SIP $node_short $max_retries $TFTPDIR if [ $? -ne 0 ]; then # try long hostname if [ "$node" != "$node_short" ]; then download_mypostscript $SIP $node $postfix $max_retries $TFTPDIR fi fi fi # on reboot and shutdown, make sure /ro and /rw are not stuck mounted if grep 'rw /rw tmpfs ' /proc/mounts >/dev/null 2>&1; then touch /var/lock/subsys/xcatmounts echo '#!/bin/bash' > /etc/rc6.d/K10xcatmounts echo umount -l /ro >> /etc/rc6.d/K10xcatmounts echo umount -l /rw >> /etc/rc6.d/K10xcatmounts chmod 755 /etc/rc6.d/K10xcatmounts ln -sf /etc/rc6.d/K10xcatmounts /etc/rc0.d/K10xcatmounts fi # To support the postscripts in the subdirectories under /install/postscripts #chmod +x /$xcatpost/*; chmod -R +x `find $xcatpost/ -maxdepth 1 -print | grep -E -v "^($xcatpost/|$xcatpost/_xcat|$xcatpost/_ssh|$xcatpost/ca|$xcatpost/hostkeys)$"` cd /$xcatpost; PATH=/$xcatpost:$PATH export PATH if [ -x /usr/bin/openssl ]; then XCATSERVER="$SIP:3001" export XCATSERVER USEOPENSSLFORXCAT=1 #Though this is the only method going forward, flag to allow backward compatibility with 2.2 generated netboot images export USEOPENSSLFORXCAT fi # if download of postscript failed, # probably the /tftpboot/mypostcript/mypostscript. does not exist. # We need to call getpostscript.awk . if [ ! -x /$xcatpost/mypostscript ]; then echolog "info" "xcatdsklspost: failed to download mypostscript., trying to call getpostscript.awk..." if [ $useflowcontrol = "1" ]; then # first contact daemon xcatflowrequest 3001 #logger -t xCAT -p local4.info "xcatdsklspost:sending xcatflowrequest $SIP 3001" echolog "debug" "xcatdsklspost:sending xcatflowrequest $SIP 3001" /$xcatpost/xcatflowrequest $SIP 3001 rc=$? #logger -t xCAT -p local4.info "xcatdsklspost:xcatflowrequest return=$rc" echolog "debug" "xcatdsklspost:xcatflowrequest return=$rc" if [ $rc -ne 0 ]; then #logger -t xCAT -p local4.info "xcatdsklspost: error from xcatflowrequest, will not use flow control" echolog "debug" "xcatdsklspost: error from xcatflowrequest, will not use flow control" useflowcontrol=0 fi fi /$xcatpost/getpostscript.awk | egrep '' | sed -e 's/<[^>]*>//g'|egrep -v '^ *$'|sed -e 's/^ *//' | sed -e 's/<//g' -e 's/&/\&/g' -e 's/"/"/g' -e "s/'/'/g" > /$xcatpost/mypostscript; MYCONT=`grep MASTER /$xcatpost/mypostscript` MAX_RETRIES=10 RETRY=0 while [ -z "$MYCONT" ]; do # not using flow control , need to sleep if [ $useflowcontrol = "0" ]; then let SLI=$RANDOM%10 let SLI=SLI+10 sleep $SLI fi RETRY=$(($RETRY+1)) if [ $RETRY -eq $MAX_RETRIES ] then break fi if [ $useflowcontrol = "1" ]; then # contact daemon xcatflowrequest 3001 #logger -t xCAT -p local4.info "xcatdsklspost: sending xcatflowrequest $SIP 3001" echolog "debug" "xcatdsklspost: sending xcatflowrequest $SIP 3001" /$xcatpost/xcatflowrequest $SIP 3001 rc=$? #logger -t xCAT -p local4.info "xcatdsklspost:xcatflowrequest return=$rc" echolog "debug" "xcatdsklspost:xcatflowrequest return=$rc" if [ $rc -ne 0 ]; then #logger -t xCAT -p local4.info "xcatdsklspost: error from xcatflowrequest, will not use flow control" echolog "debug" "xcatdsklspost: error from xcatflowrequest, will not use flow control" useflowcontrol=0 fi fi /$xcatpost/getpostscript.awk | egrep '' | sed -e 's/<[^>]*>//g'|egrep -v '^ *$'|sed -e 's/^ *//' | sed -e 's/<//g' -e 's/&/\&/g' -e 's/"/"/g' -e "s/'/'/g" > /$xcatpost/mypostscript; MYCONT=`grep MASTER /$xcatpost/mypostscript` if [ ! -z "$MYCONT" ]; then break; fi done fi #save the MASTER into the xcatinfo file for node deployment case, #for updatenode case, only save it when -M is specified if [ $NODE_DEPLOYMENT -eq 1 ] || [ "$MODE" = "4" ]; then new_ms=`grep '^MASTER' /$xcatpost/mypostscript |head -n 1 |cut -d= -f2` fi if [ -n "$new_ms" ]; then if [ ! -f /opt/xcat/xcatinfo ]; then mkdir -p /opt/xcat touch /opt/xcat/xcatinfo fi grep 'XCATSERVER' /opt/xcat/xcatinfo > /dev/null 2>&1 if [ $? -eq 0 ]; then sed -i "s/XCATSERVER=.*/XCATSERVER=$new_ms/" /opt/xcat/xcatinfo else echo "XCATSERVER=$new_ms" >> /opt/xcat/xcatinfo fi fi #save the USEFLOWCONTROL into the xcatinfo file #for updatenode case, passwd in with the -f flag if [ $NODE_DEPLOYMENT -eq 1 ] || [ "$MODE" = "4" ]; then useflowcontrol=`grep '^USEFLOWCONTROL' /$xcatpost/mypostscript |cut -d= -f2 | tr -d \'\" | tr A-Z a-z` fi if [ ! -f /opt/xcat/xcatinfo ]; then mkdir -p /opt/xcat touch /opt/xcat/xcatinfo fi if [ -n "$useflowcontrol" ]; then # lets just put YES or NO in xcatinfo if [[ "$useflowcontrol" =~ ^(1|yes|y)$ ]]; then new_fc="YES" else new_fc="NO" fi grep 'USEFLOWCONTROL' /opt/xcat/xcatinfo > /dev/null 2>&1 if [ $? -eq 0 ]; then sed -i "s/USEFLOWCONTROL=.*/USEFLOWCONTROL=$new_fc/" /opt/xcat/xcatinfo else echo "USEFLOWCONTROL=$new_fc" >> /opt/xcat/xcatinfo fi # no setting means do not use flowcontrol else echo "USEFLOWCONTROL=NO" >> /opt/xcat/xcatinfo fi # Store the SERVICEGROUP into the xcatinfo file for node deployment, and also for updatenode -s if [ $NODE_DEPLOYMENT -eq 1 ] || [ "$MODE" = "1" ]; then sn_group=`grep '^SERVICEGROUP' /$xcatpost/mypostscript |cut -d= -f2 | tr -d \'\"` if [ "x" != "x$sn_group" ]; then # Change or add SERVICEGROUP line if service node pool defined. grep 'SERVICEGROUP=' $XCATINFOFILE > /dev/null 2>&1 if [ $? -eq 0 ]; then sed -i "s/SERVICEGROUP=.*/SERVICEGROUP=$sn_group/" $XCATINFOFILE else echo "SERVICEGROUP=$sn_group" >> $XCATINFOFILE fi else # Remove SERVICEGROUP line if no service node pool defined. sed -i "/SERVICEGROUP=.*/d" $XCATINFOFILE fi fi # when called by the updatenode command MODE=1,2 # the nodename is passed in by xdsh in the NODE environment variable by xdsh. #modify the UPDATENODE flag to 1 # put NODE in /opt/xcat/xcatinfo if [ "$MODE" = "1" ] || [ "$MODE" = "2" ]; then TMP=`sed -e 's/UPDATENODE=0/UPDATENODE=1/g' /$xcatpost/mypostscript`; echo "$TMP" > /$xcatpost/mypostscript; if [ ! -f /opt/xcat/xcatinfo ]; then mkdir -p /opt/xcat touch /opt/xcat/xcatinfo fi grep 'NODE' /opt/xcat/xcatinfo > /dev/null 2>&1 if [ $? -eq 0 ]; then sed -i "s/NODE=.*/NODE=$NODE/" /opt/xcat/xcatinfo else echo "NODE=$NODE" >> /opt/xcat/xcatinfo fi #echo "xcatdsklspost:my nodename in the database is $NODE" fi if [ "$MODE" = "5" ]; then TMP=`sed -e 's/UPDATENODE=0/UPDATENODE=1\nUPDATESECURITY=1\nexport UPDATESECURITY/g' /$xcatpost/mypostscript`; echo "$TMP" > /$xcatpost/mypostscript; fi #when a diskfull reboot mode if [ "$MODE" = "6" ]; then # remove the post scripts so that they are not run on reboot TMP=`sed "/# postscripts-start-here/,/# postscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript # get the RUNBOOTSCRIPTS site variable if [ -f /$xcatpost/mypostscript ]; then RUNBOOTSCRIPTS=`grep 'RUNBOOTSCRIPTS=' /$xcatpost/mypostscript |cut -d= -f2 | tr -d \'\" | tr A-Z a-z ` fi # if admin did not requested running of post boot scripts - then remove PBS if [[ ! "$RUNBOOTSCRIPTS" =~ ^(1|yes|y)$ ]]; then #remove all the postscripts TMP=`sed "/# postbootscripts-start-here/,/# postbootscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript #TMP=`sed "/postbootscripts-start-here/,/postbootscripts-end-here/ d" /$xcatpost/mypostscript.post` #echo "$TMP" > /$xcatpost/mypostscript.post fi fi # postscript name is specified with the updatenode #cp /$xcatpost/mypostscript /$xcatpost/mypostscript.backup # if the list has a postscript named *start-here* then we must rebuild the # mypostscript file with only the matching *start-here stanza. if ( pmatch $POSTSCRIPTS "*start-here*" ); then if ( pmatch $POSTSCRIPTS "*osimage-postbootscripts-start-here" ); then # remove all sections but the osimage-postbootscripts section TMP=`sed "/# postscripts-start-here/,/# postscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript TMP=`sed "/# defaults-postbootscripts-start-here/,/# defaults-postbootscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript TMP=`sed "/# node-postbootscripts-start-here/,/# node-postbootscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript fi if ( pmatch $POSTSCRIPTS "*postscripts-start-here" ); then #remove all the postbootscripts TMP=`sed "/# postbootscripts-start-here/,/# postbootscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript fi if ( pmatch $POSTSCRIPTS "*postbootscripts-start-here" ); then #remove all the postscripts TMP=`sed "/# postscripts-start-here/,/# postscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript fi if ( pmatch $POSTSCRIPTS "*defaults-postscripts-start-here" ); then # remove all sections but the defaults-postscripts section TMP=`sed "/# osimage-postscripts-start-here/,/# osimage-postscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript TMP=`sed "/# node-postscripts-start-here/,/# node-postscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript TMP=`sed "/# postbootscripts-start-here/,/# postbootscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript fi if ( pmatch $POSTSCRIPTS "*node-postscripts-start-here" ); then # remove all sections but the node-postscripts section TMP=`sed "/# osimage-postscripts-start-here/,/# osimage-postscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript TMP=`sed "/# defaults-postscripts-start-here/,/# defaults-postscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript TMP=`sed "/# postbootscripts-start-here/,/# postbootscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript fi if ( pmatch $POSTSCRIPTS "*defaults-postbootscripts-start-here" ); then # remove all sections but the defaults-postbootscripts section TMP=`sed "/# osimage-postbootscripts-start-here/,/# osimage-postbootscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript TMP=`sed "/# node-postbootscripts-start-here/,/# node-postbootscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript TMP=`sed "/# postscripts-start-here/,/# postscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript fi if ( pmatch $POSTSCRIPTS "*node-postbootscripts-start-here" ); then # remove all sections but the node-postbootscripts section TMP=`sed "/# osimage-postbootscripts-start-here/,/# osimage-postbootscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript TMP=`sed "/# defaults-postbootscripts-start-here/,/# defaults-postbootscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript TMP=`sed "/# postscripts-start-here/,/# postscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript fi # check to see if input postscript list is not empty. If there is a list # remove the built postscripts and only add the ones for the list. else if [ -n "$POSTSCRIPTS" ]; then #remove all the postbootscripts, and replace with list provided TMP=`sed "/# postbootscripts-start-here/,/# postbootscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript #remove all the postscripts TMP=`sed "/# postscripts-start-here/,/# postscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript echo "# postscripts-start-here" >> /$xcatpost/mypostscript #add requested postscripts in echo "$POSTSCRIPTS" | tr "," "\n" >> /$xcatpost/mypostscript echo "# postscripts-end-here" >> /$xcatpost/mypostscript fi fi #ADDSITEYUM is set by post.rh and post.rh.iscsi for full installtion #if [[ "$ADDSITEYUM" = "1" ]]; then # TMP=`sed "/postscripts-start-here/ a addsiteyum" /$xcatpost/mypostscript` # echo "$TMP" > /$xcatpost/mypostscript #fi #MYCONT=`cat /$xcatpost/mypostscript` #echo "$MYCONT" # use the run_ps subroutine to run the postscripts if [ $NODE_DEPLOYMENT -eq 1 ] || [ "$MODE" = "4" ] || [ "$MODE" = "6" ]; then TMP=`sed "/# postscripts-start-here/,/# postscripts-end-here/ s/\(.*\)/run_ps postbootscript \1/;s/run_ps postbootscript\s*#/#/;s/run_ps postbootscript\s*$//" /$xcatpost/mypostscript` else TMP=`sed "/# postscripts-start-here/,/# postscripts-end-here/ s/\(.*\)/run_ps postscript \1/;s/run_ps postscript\s*#/#/;s/run_ps postscript\s*$//" /$xcatpost/mypostscript` fi echo "#!/bin/bash . /xcatpost/xcatlib.sh # global value to store the running status of the postbootscripts,the value is non-zero if one postbootscript failed return_value=0 # subroutine used to run postscripts # \$1 argument is the script type # rest argument is the script name and arguments run_ps () { local ret_local=0 mkdir -p "\"/var/log/xcat\"" local logfile=\"/var/log/xcat/xcat.log\" local scriptype=\$1 shift; if [ -z \"\$scriptype\" ]; then scriptype=\"postscript\" fi if [ -f \$1 ]; then echo \"\`date\` Running \$scriptype: \$1\" msgutil_r \"\$MASTER_IP\" \"info\" "\"\`date\` Running \$scriptype: \$1\"" \"\$logfile\" if [ \"\$XCATDEBUGMODE\" = \"1\" ] || [ \"\$XCATDEBUGMODE\" = \"2\" ]; then local compt=\$(file \$1) local reg=\"shell script\" if [[ \"\$compt\" =~ \$reg ]]; then bash -x ./\$@ 2>&1 | tee -a \$logfile | tee >(logger -t xcat -p debug) ret_local=\${PIPESTATUS[0]} else ./\$@ 2>&1 | tee -a \$logfile | logger -t xcat -p debug ret_local=\${PIPESTATUS[0]} fi else ./\$@ 2>&1 | tee -a \$logfile ret_local=\${PIPESTATUS[0]} fi if [ \"\$ret_local\" -ne \"0\" ]; then return_value=\$ret_local fi echo \"\$scriptype: \$1 exited with code \$ret_local\" msgutil_r \"\$MASTER_IP\" \"info\" "\"\`date\` \$scriptype \$1 return with \$ret_local\"" \"\$logfile\" else echo \"\`date\` \$scriptype \$1 does NOT exist.\" msgutil_r \"\$MASTER_IP\" \"info\" "\"\`date\` \$scriptype \$1 does NOT exist.\"" \"\$logfile\" return_value=-1 fi return 0 } # subroutine end " > /$xcatpost/mypostscript echo "$TMP" >> /$xcatpost/mypostscript if [ "$MODE" = "1" ] || [ "$MODE" = "2" ] || [ "$MODE" = "3" ] || [ "$MODE" = "5" ]; then TMP=`sed "/# postbootscripts-start-here/,/# postbootscripts-end-here/ s/\(.*\)/run_ps postscript \1/;s/run_ps postscript\s*#/#/;s/run_ps postscript\s*$//" /$xcatpost/mypostscript` else TMP=`sed "/# postbootscripts-start-here/,/# postbootscripts-end-here/ s/\(.*\)/run_ps postbootscript \1/;s/run_ps postbootscript\s*#/#/;s/run_ps postbootscript\s*$//" /$xcatpost/mypostscript` fi echo "$TMP" > /$xcatpost/mypostscript if [ $NODE_DEPLOYMENT -eq 1 ] || [ "$MODE" = "4" ] || [ "$MODE" = "6" ]; then #notify the server that we are done with netbooting CNS=`grep NODESTATUS= /$xcatpost/mypostscript |awk -F = '{print $2}' | tr -d \'\" | tr A-Z a-z` if [ -z "$CNS" ] || [[ "$CNS" =~ ^(1|yes|y)$ ]]; then # TMP=`sed "/postscripts-start-here/ i\updateflag.awk \\$MASTER 3002 \\"installstatus configuring\\"" /$xcatpost/mypostscript` # echo "$TMP"> /$xcatpost/mypostscript if [ "$MODE" = "6" ]; then echo " if [ \"\$return_value\" -eq \"0\" ]; then msgutil_r \$MASTER_IP \"debug\" \"node booted successfully,reporting status...\" \"/var/log/xcat/xcat.log\" updateflag.awk \$MASTER 3002 \"installstatus booted\" else msgutil_r \$MASTER_IP \"debug\" \"node boot failed,reporting status...\" \"/var/log/xcat/xcat.log\" updateflag.awk \$MASTER 3002 \"installstatus failed\" fi " >> /$xcatpost/mypostscript else echo " if [ \"\$return_value\" -eq \"0\" ]; then msgutil_r \$MASTER_IP \"debug\" \"node booted successfully,reporting status...\" \"/var/log/xcat/xcat.log\" updateflag.awk \$MASTER 3002 \"installstatus booted\" msgutil_r \$MASTER_IP \"info\" \"provision completed.(\$NODE)\" \"/var/log/xcat/xcat.log\" else msgutil_r \$MASTER_IP \"debug\" \"node boot failed,reporting status...\" \"/var/log/xcat/xcat.log\" updateflag.awk \$MASTER 3002 \"installstatus failed\" fi " >> /$xcatpost/mypostscript fi fi fi DHCP_TMP=`sed 's/\(DHCPINTERFACES=\)\(.*\)$/\1"\2"/' /$xcatpost/mypostscript` echo "$DHCP_TMP" > /$xcatpost/mypostscript CLEANUPXCATPOST=`grep CLEANUPXCATPOST= /$xcatpost/mypostscript |awk -F = '{print $2}' | tr -d \'\" | tr A-Z a-z` if [[ "$CLEANUPXCATPOST" =~ ^(1|yes|y)$ ]]; then echo "cd /" >> /$xcatpost/mypostscript # /xcatpost might be read-only for statelite nodes echo "rm -rf /$xcatpost/*" >> /$xcatpost/mypostscript fi if [ "$MODE" = "1" ] || [ "$MODE" = "2" ] || [ "$MODE" = "5" ]; then echo "exit \$return_value" >> /$xcatpost/mypostscript fi chmod 700 /$xcatpost/mypostscript if [ -x /$xcatpost/mypostscript ];then echolog "debug" "running /$xcatpost/mypostscript" /$xcatpost/mypostscript VRET_POST=$? echolog "debug" "/$xcatpost/mypostscript return with $VRET_POST" fi #tell user it is done when this is called by updatenode command if [ "$MODE" = "1" ] || [ "$MODE" = "2" ] || [ "$MODE" = "5" ]; then echolog "info" "returned from postscript" fi exit $VRET_POST EOF chmod 755 /opt/xcat/xcatdsklspost if [ ! -x /opt/xcat/xcatdsklspost ]; then if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "failed to generate /opt/xcat/xcatdsklspost" "/var/log/xcat/xcat.log" fi else if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "/opt/xcat/xcatdsklspost generated" "/var/log/xcat/xcat.log" fi fi #create the preboot script and run here TMP=`sed "/^#\s*postbootscripts-start-here/,/^#\s*postbootscripts-end-here/ d" /xcatpost/mypostscript` echo "$TMP" > /xcatpost/mypostscript echo " #save bad return code to /opt/xcat/xcatinfo if [ \"\$return_value\" -ne \"0\" ]; then grep 'POSTSCRIPTS_RC' /opt/xcat/xcatinfo > /dev/null 2>&1 if [ \$? -eq 0 ]; then sed -i \"s/POSTSCRIPTS_RC=.*/POSTSCRIPTS_RC=1/\" /opt/xcat/xcatinfo else echo \"POSTSCRIPTS_RC=1\" >> /opt/xcat/xcatinfo fi fi " >> /xcatpost/mypostscript chmod 700 /xcatpost/mypostscript export ARCH=x86_64 export CONSOLEPORT=0 #for redhat: #place-holder for the code to save the repo info on compute node,pointing to the "pkgdir" of the osimage #so that the provisioned node has the repo pointed to the distro path on MN cat >/etc/yum.repos.d/local-repository-0.repo << 'EOF' [local-rhels6.5-x86_64--install-rhels6.5-x86_64] name=xCAT configured yum repository for /install/rhels6.5/x86_64 baseurl=http://xcat//install/rhels6.5/x86_64 enabled=1 gpgcheck=0 [local-rhels6.5-x86_64--install-rhels6.5-x86_64-Server] name=xCAT configured yum repository for /install/rhels6.5/x86_64/Server baseurl=http://xcat//install/rhels6.5/x86_64/Server enabled=1 gpgcheck=0 [local-rhels6.5-x86_64--install-rhels6.5-x86_64-ScalableFileSystem] name=xCAT configured yum repository for /install/rhels6.5/x86_64/ScalableFileSystem baseurl=http://xcat//install/rhels6.5/x86_64/ScalableFileSystem enabled=1 gpgcheck=0 [local-rhels6.5-x86_64--install-rhels6.5-x86_64-ResilientStorage] name=xCAT configured yum repository for /install/rhels6.5/x86_64/ResilientStorage baseurl=http://xcat//install/rhels6.5/x86_64/ResilientStorage enabled=1 gpgcheck=0 [local-rhels6.5-x86_64--install-rhels6.5-x86_64-LoadBalancer] name=xCAT configured yum repository for /install/rhels6.5/x86_64/LoadBalancer baseurl=http://xcat//install/rhels6.5/x86_64/LoadBalancer enabled=1 gpgcheck=0 [local-rhels6.5-x86_64--install-rhels6.5-x86_64-HighAvailability] name=xCAT configured yum repository for /install/rhels6.5/x86_64/HighAvailability baseurl=http://xcat//install/rhels6.5/x86_64/HighAvailability enabled=1 gpgcheck=0 EOF if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "info" "running mypostscript" "/var/log/xcat/xcat.log" fi /xcatpost/mypostscript if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "info" "mypostscript returned" "/var/log/xcat/xcat.log" fi if [[ $OSVER == ubuntu* ]]; then if [[ -r /boot/grub/menu.lst ]]; then sed -i 's/^serial/#serial/' /boot/grub/menu.lst sed -i 's/^terminal/#terminal/' /boot/grub/menu.lst elif [[ -r /boot/grub/grub.cfg ]] ; then update-grub fi #print the kernel messages and service start messages with systemd on the console during system bootup [ -f /etc/default/grub ] && sed -i -e '/GRUB_CMDLINE_LINUX_DEFAULT=/s/quiet//;s/splash//' -e '/#GRUB_TERMINAL=/s/#//' -e 's/#GRUB_GFXMODE=.*/GRUB_GFXMODE=text/' /etc/default/grub && update-grub if echo "$ARCH" | grep -i 'x86_64'; then #grab the install-time console configuration from /proc/cmdline inside os installer CONSOLECFG=$(awk 'BEGIN{RS="[ \n]" ;ORS=" "} $0 ~ /^console=/{print $0}' /proc/cmdline) #if the console configuration is not applied to the grub configuration,apply it cat /boot/grub/grub.cfg |grep "$CONSOLECFG" >/dev/null 2>&1 || ([ -f /etc/default/grub ] && sed -i -e "/GRUB_CMDLINE_LINUX_DEFAULT=/s/=\"/=\" $CONSOLECFG /" /etc/default/grub && update-grub) fi if echo "$ARCH" | grep -i 'ppc64'; then if [ -z "$CONSOLEPORT" ] ; then export CONSOLEPORT=0 fi CONSOLE="hvc$CONSOLEPORT" if [[ -r /etc/default/grub ]] ; then sed -i "s/GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT=\"console=$CONSOLE\"/" /etc/default/grub else echo "GRUB_CMDLINE_LINUX_DEFAULT=\"console=$CONSOLE\"" > /etc/default/grub fi update-grub cat >/etc/init/$CONSOLE\.conf << 'EOF' start on stopped rc RUNLEVEL=[2345] and ( not-container or container CONTAINER=lxc or container CONTAINER=lxc-libvirt) stop on runlevel [!2345] respawn #exec /sbin/getty -L 115200 hvc0 vt102 script for i in `cat /proc/cmdline`; do KEY=`echo $i|cut -d= -f 1` if [ "$KEY" == "console" -a "$i" != "console=tty0" ]; then VALUE=`echo $i | awk -F= '{print $2}'` COTTY=`echo $VALUE|awk -F, '{print $1}'` COSPEED=`echo $VALUE|awk -F, '{print $2}'|awk -Fn '{print $1}'` break fi done exec /sbin/getty -L $COSPEED $COTTY vt102 end script EOF fi sed -i '/127.0.1.1/d' /etc/hosts else [ -f /boot/grub/grub.conf ] && sed -i 's/^serial/#serial/' /boot/grub/grub.conf [ -f /boot/grub/grub.conf ] && sed -i 's/^terminal/#terminal/' /boot/grub/grub.conf if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "/boot/grub/grub.conf updated" "/var/log/xcat/xcat.log" fi fi if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "info" "finished node installation, reporting status..." "/var/log/xcat/xcat.log" fi #the following command should always be run to prevent infinite installation loops updateflag.awk $MASTER 3002 cd / # fix the issue#929@github, the "service network restart" in # makes the 'network' service in start status, then it causes the # services YaST2-Second-Stage.service and xcatpostinit1 services to be run in parallel. # But the YaST2-Second-Stage.service calls the Yast2 which conflics with the zypper # which is called in xcatpostinit1->otherpkgs. # The correct services start order is 'YaST2-Second-Stage.service'->'network'->'xcatpostinit1' in serial. # To skip the conflict, the network service should be stoped in the yast first stage. Then base on the service # dependency, the service start order will be 'YaST2-Second-Stage.service'->'network'->'xcatpostinit1' in serial. # Then the Yast2 will be stopped before running the zypper in otherpkgs. if [[ $OSVER =~ sles && $OSVER != sles11* ]]; then service network stop fi if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then set +x fi exit 0 # #chvt 1 mkdir -p /var/log/xcat/ { cat >> /var/log/xcat/xcat.log << "EOF" %include /tmp/pre-install.log EOF echo "Running Kickstart Post-Installation script..." # # Setup hostname # echo "post scripts" >/root/post.log [ $XCATDEBUGMODE ] || export XCATDEBUGMODE="0" [ $MASTER_IP ] || export MASTER_IP="XX.XX.XX.XX" declare -F msgutil_r &>/dev/null || function msgutil_r { local logserver=$1 local msgtype=$2 local msgstr=$3 local logfile=$4 if [ -z "$msgtype" ]; then msgtype="debug" fi if [ -n "$logserver" ];then logger -n $logserver -t xcat -p local4.$msgtype "$msgstr" if [ "$?" != "0" ];then exec 3<>/dev/udp/$logserver/514 >/dev/null;logger -s -t xcat -p local4.$msgtype "$msgstr" 2>&3 if [ "$?" != "0" ];then logger -s -t xcat -p local4.$msgtype "$msgstr" 2>&1|nc $logserver 514 >/dev/null 2>&1 if [ "$?" != "0" ];then logger -t xcat -p local4.$msgtype "$msgstr" fi fi fi else logger -t xcat -p local4.$msgtype "$msgstr" fi if [ -n "$logfile" ]; then local logdir="$(dirname $logfile)" if [ ! -d "$logdir" ]; then mkdir -p "$logdir" touch "$logfile" fi echo "$msgstr" >> $logfile fi } declare -F msgutil &>/dev/null || function msgutil { msgutil_r "" "$@" } export PRINIC= if [ "$PRINIC" == "mac" ] then export PRINIC='xx:xx:xx:xx:xx:xx' fi if [ -z "$PRINIC" ] then for karg in $(cat /proc/cmdline |sed -e 's/-/:/g' -e 's/ /\n/g'); do if [ "${karg%%=*}" = "BOOTIF" ]; then MACADDR="${karg#*=}"; #The BOOTIF in pxelinux will be the MAC address with the hardware type code as a prefix #such as BOOTIF=XX-XX-XX-XX-XX-XX-90 if [ "${#MACADDR}" == "20" ]; then MACADDR=${MACADDR:3:21} fi #export PRINIC=`ifconfig -a|grep -i "hwaddr ${karg#*=01:}"|awk '{print $1}'` export PRINIC=`ip -o link|grep -i "$MACADDR"|awk '{print $2}'|sed s/://` fi done if [ -z "$PRINIC" ]; then export PRINIC=eth0 fi fi if [ -z "$PRINIC" ] then export PRINIC=eth0 elif [[ `echo "$PRINIC" | grep -sqE ^[A-Fa-f0-9]+:[A-Fa-f0-9]+:[A-Fa-f0-9]+:[A-Fa-f0-9]+:[A-Fa-f0-9]+:[A-Fa-f0-9]+$ ;echo $?` == "0" ]]; then #export PRINIC=`ifconfig -a | grep -i "HWaddr $PRINIC" | awk '{print $1}'` export PRINIC=`ip -o link|grep -i "$PRINIC"|awk '{print $2}'|sed s/://` fi #IP=$(ifconfig $PRINIC | grep inet | awk '{print $2}' | awk -F: '{print $2}') IP=$(ip -4 -o a sh dev $PRINIC | awk '/inet/{print $4}' | head -n 1 | awk -F '/' '{print $1}') if [ -z "$IP" ] then dhclient $PRINIC #IP=$(ifconfig $PRINIC | grep inet | awk '{print $2}' | awk -F: '{print $2}') IP=$(ip -4 -o a sh dev $PRINIC | awk '/inet/{print $4}' | head -n 1 | awk -F '/' '{print $1}') fi export HOSTNAME=$(host $IP 2>/dev/null | awk '{print $5}' | awk -F. '{print $1}') if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "PRINIC=$PRINIC, IP=$IP,HOSTNAME=$HOSTNAME" "/var/log/xcat/xcat.log" fi hostname $HOSTNAME if [ -f /boot/efi/efi/redhat/grub.conf ]; then #RedHat bug, grub.efi corrupts console unless we are careful... sed -i s/^terminal.*// /boot/efi/efi/redhat/grub.conf bootpart=$(sed -e 's/#.*//' /boot/efi/efi/redhat/grub.conf |grep root|grep -v kernel|head -n 1|awk '{print $2}') bootpart="${bootpart%\\n}" sed -i s!^serial.*!splashimage=$bootpart/boot/grub/splash.xpm.gz! /boot/efi/efi/redhat/grub.conf fi # # Run xCAT post install # export MASTER_IP="XX.XX.XX.XX" export MASTER="xcat" export NODESTATUS="" export XCATIPORT=3002 export INSTALLDIR=/install export TFTPDIR=/tftpboot export XCATDEBUGMODE="1" declare -F msgutil_r &>/dev/null || function msgutil_r { local logserver=$1 local msgtype=$2 local msgstr=$3 local logfile=$4 if [ -z "$msgtype" ]; then msgtype="debug" fi if [ -n "$logserver" ];then logger -n $logserver -t xcat -p local4.$msgtype "$msgstr" if [ "$?" != "0" ];then exec 3<>/dev/udp/$logserver/514 >/dev/null;logger -s -t xcat -p local4.$msgtype "$msgstr" 2>&3 if [ "$?" != "0" ];then logger -s -t xcat -p local4.$msgtype "$msgstr" 2>&1|nc $logserver 514 >/dev/null 2>&1 if [ "$?" != "0" ];then logger -t xcat -p local4.$msgtype "$msgstr" fi fi fi else logger -t xcat -p local4.$msgtype "$msgstr" fi if [ -n "$logfile" ]; then local logdir="$(dirname $logfile)" if [ ! -d "$logdir" ]; then mkdir -p "$logdir" touch "$logfile" fi echo "$msgstr" >> $logfile fi } declare -F msgutil &>/dev/null || function msgutil { msgutil_r "" "$@" } if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then set -x fi if [ -z "$XCATIPORT" ]; then XCATIPORT="3002" fi if [ -z "$INSTALLDIR" ]; then INSTALLDIR="/install" fi if [ -z "$TFTPDIR" ]; then TFTPDIR="/tftpboot" fi if [[ $TFTPDIR != /* ]]; then TFTPDIR="/"$TFTPDIR fi NODESTATUS=$(echo "$NODESTATUS"| tr -d \'\"| tr A-Z a-z) (cat << 'EOF' #!/usr/bin/awk -f # IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html BEGIN { xcatdhost = ARGV[1] xcatdport = ARGV[2] flag = ARGV[3] if (!flag) flag = "next" ns = "/inet/tcp/0/" xcatdhost "/" xcatdport loop = 0 while(1) { if((ns |& getline) > 0) print $0 | "logger -t xcat -p local4.info" else { print "Retrying flag update" | "logger -t xcat -p local4.info" print "updateflag.awk: Retrying flag update" >> "/var/log/xcat/xcat.log" close(ns) system("sleep 10") loop = loop + 1 } if($0 == "ready") print flag |& ns if($0 == "done") break if(loop > 10) { print "flag update failed" | "logger -t xcat -p local4.info" print "updateflag.awk: flag update failed" >> "/var/log/xcat/xcat.log" break } } close(ns) exit 0 } EOF ) >/tmp/updateflag chmod 0755 /tmp/updateflag cd /tmp RAND=$(perl -e 'print int(rand(50)). "\n"') if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "sleep $RAND" "/var/log/xcat/xcat.log" fi sleep $RAND # Stop if no openssl to help the next bit if [ ! -x /usr/bin/openssl ]; then msgutil_r "$MASTER_IP" "debug" "/usr/bin/openssl does not exist, halt ..." "/var/log/xcat/xcat.log" /tmp/updateflag $MASTER $XCATIPORT "installstatus failed" sleep 36500d fi #save to /opt/xcat/xcatinfo file if [ ! -f /opt/xcat/xcatinfo ]; then mkdir -p /opt/xcat touch /opt/xcat/xcatinfo fi grep 'XCATSERVER' /opt/xcat/xcatinfo > /dev/null 2>&1 if [ $? -eq 0 ]; then sed -i "s/XCATSERVER=.*/XCATSERVER=$MASTER_IP/" /opt/xcat/xcatinfo else echo "XCATSERVER=$MASTER_IP" >> /opt/xcat/xcatinfo fi grep 'INSTALLDIR' /opt/xcat/xcatinfo > /dev/null 2>&1 if [ $? -eq 0 ]; then sed -i "s/INSTALLDIR=.*/INSTALLDIR=$INSTALLDIR/" /opt/xcat/xcatinfo else echo "INSTALLDIR=$INSTALLDIR" >> /opt/xcat/xcatinfo fi if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "/opt/xcat/xcatinfo generated" "/var/log/xcat/xcat.log" fi # download the postscripts if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "trying to download postscripts from http://$MASTER_IP$INSTALLDIR/postscripts/" "/var/log/xcat/xcat.log" fi # Stop if no wget to help the next bit if [ ! -x /usr/bin/wget ]; then msgutil_r "$MASTER_IP" "debug" "/usr/bin/wget does not exist, halt ..." "/var/log/xcat/xcat.log" /tmp/updateflag $MASTER $XCATIPORT "installstatus failed" sleep 36500d fi wget -l inf -N -r --waitretry=10 --random-wait --retry-connrefused -e robots=off -nH --cut-dirs=2 --reject "index.html*" --no-parent -t 20 -T 60 http://$MASTER_IP$INSTALLDIR/postscripts/ -P /xcatpost if [ "$?" != "0" ]; then msgutil_r "$MASTER_IP" "debug" "failed to download postscripts from http://$MASTER_IP$INSTALLDIR/postscripts/, halt ..." "/var/log/xcat/xcat.log" /tmp/updateflag $MASTER $XCATIPORT "installstatus failed" sleep 36500d fi chmod -R +x `find /xcatpost/ -maxdepth 1 -print | grep -E -v '^(/xcatpost/|/xcatpost/_xcat|/xcatpost/_ssh|/xcatpost/ca|/xcatpost/hostkeys)$'` if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "postscripts downloaded successfully" "/var/log/xcat/xcat.log" fi # get the precreated mypostscript file if [ -x /xcatpost/mypostscript ]; then rm -rf /xcatpost/mypostscript fi export NODE=n1 if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "trying to download precreated mypostscript file http://$MASTER_IP$TFTPDIR/mypostscripts/mypostscript.$NODE" "/var/log/xcat/xcat.log" fi wget -N --waitretry=10 --random-wait --retry-connrefused -t 20 -T 60 http://$MASTER_IP$TFTPDIR/mypostscripts/mypostscript.$NODE -P /xcatpost 2> /tmp/wget.log if [ "$?" = "0" ]; then if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "precreated mypostscript downloaded successfully" "/var/log/xcat/xcat.log" fi mv /xcatpost/mypostscript.$NODE /xcatpost/mypostscript chmod 700 /xcatpost/mypostscript fi USEOPENSSLFORXCAT=1 #Though this is the only method going forward, flag to allow backward compatibility with 2.2 generated netboot images export USEOPENSSLFORXCAT XCATSERVER=$MASTER_IP:3001 export XCATSERVER # If mypostscript doesn't exist, we will get it through getpostscript.awk if [ ! -x /xcatpost/mypostscript ]; then if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "failed to download precreated mypostscript, trying to generate with getpostscript.awk" "/var/log/xcat/xcat.log" fi # To support the postscripts in the subdirectories under /install/postscripts # chmod +x /xcatpost/* # Stop if no getpostscript.awk to help the next bit if [ ! -x /xcatpost/getpostscript.awk ]; then msgutil_r "$MASTER_IP" "debug" "/xcatpost/getpostscript.awk does not exist, halt ..." "/var/log/xcat/xcat.log" /tmp/updateflag $MASTER $XCATIPORT "installstatus failed" sleep 36500d fi /xcatpost/getpostscript.awk |egrep ''|sed -e 's/<[^>]*>//g'|egrep -v '^ *$'|sed -e 's/^ *//' | sed -e 's/<//g' -e 's/&/\&/g' -e 's/"/"/g' -e "s/'/'/g" > /xcatpost/mypostscript MYCONT=`grep ^MASTER= /xcatpost/mypostscript` RETRY=0 while [ -z "$MYCONT" ]; do RETRY=$(($RETRY+1)) if [ $RETRY -eq "10" ]; then break fi let SLI=$RANDOM%10+10 sleep $SLI /xcatpost/getpostscript.awk |egrep ''|sed -e 's/<[^>]*>//g'|egrep -v '^ *$'|sed -e 's/^ *//' | sed -e 's/<//g' -e 's/&/\&/g' -e 's/"/"/g' -e "s/'/'/g" > /xcatpost/mypostscript MYCONT=`grep ^MASTER= /xcatpost/mypostscript` done fi TMP=`sed "/^#\s*postscripts-start-here/,/^#\s*postscripts-end-here/ s/\(.*\)/run_ps postscript \1/;s/run_ps postscript\s*#/#/;s/run_ps postscript\s*$//" /xcatpost/mypostscript` echo "$TMP" > /xcatpost/mypostscript TMP=`sed "/^#\s*postbootscripts-start-here/,/^#\s*postbootscripts-end-here/ s/\(.*\)/run_ps postbootscript \1/;s/run_ps postbootscript\s*#/#/;s/run_ps postbootscript\s*$//" /xcatpost/mypostscript` cd /xcatpost #gunzip xcatpost.tar.gz #tar -xvf xcatpost.tar #/xcatpost/n1 export PATH=$PATH:/xcatpost # use the run_ps subroutine to run the postscripts if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then echo "set -x" > /xcatpost/mypostscript else cat /dev/null > /xcatpost/mypostscript fi echo " . /xcatpost/xcatlib.sh # global value to store the running status of the postbootscripts,the value is non-zero if one postbootscript failed return_value=0 # subroutine used to run postscripts # \$1 argument is the script type # rest argument is the script name and arguments run_ps () { local ret_local=0 mkdir -p "\"/var/log/xcat\"" # On some Linux distro, the rsyslogd daemon write log files with permision # other than root:root. And in some case, the directory /var/log/xcat was # created by xCAT, and had root:root ownership. In this way, rsyslogd # did not have enough permission to write to log files under this directory. # As a dirty hack, change the ownership of directory /var/log/xcat to the # same ownership of directory /var/log. chown `ls -ld /var/log | awk '{ print \$3\":\"\$4 }'` "\"/var/log/xcat\"" local logfile=\"/var/log/xcat/xcat.log\" local scriptype=\$1 shift; if [ -z \"\$scriptype\" ]; then scriptype=\"postscript\" fi if [ -f \$1 ]; then msgutil_r \"\$MASTER_IP\" \"info\" "\"\`date\` Running \$scriptype: \$1\"" \"\$logfile\" if [ \"\$XCATDEBUGMODE\" = \"1\" ] || [ \"\$XCATDEBUGMODE\" = \"2\" ]; then local compt=\$(file \$1) local reg=\"shell script\" if [[ \"\$compt\" =~ \$reg ]]; then bash -x ./\$@ 2>&1 ret_local=\$? else ./\$@ 2>&1 | logger -t xcat -p debug ret_local=\${PIPESTATUS[0]} fi else ./\$@ 2>&1 ret_local=\${PIPESTATUS[0]} fi if [ \"\$ret_local\" -ne \"0\" ]; then return_value=\$ret_local fi msgutil_r \"\$MASTER_IP\" \"info\" "\"\`date\` \$scriptype \$1 return with \$ret_local\"" \"\$logfile\" else msgutil_r \"\$MASTER_IP\" \"info\" "\"\`date\` \$scriptype \$1 does NOT exist.\"" \"\$logfile\" return_value=-1 fi return 0 } # subroutine end " >> /xcatpost/mypostscript echo "$TMP" >> /xcatpost/mypostscript if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then echo "set +x" >> /xcatpost/mypostscript fi chmod +x /xcatpost/mypostscript if [ ! -x /xcatpost/mypostscript ]; then msgutil_r "$MASTER_IP" "debug" "generate mypostscript file failure, halt ..." "/var/log/xcat/xcat.log" /tmp/updateflag $MASTER $XCATIPORT "installstatus failed" sleep 36500d else if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "generate mypostscript file successfully" "/var/log/xcat/xcat.log" fi fi #save the postboot scripts to /xcatpost/mypostscript.post TMP=`sed "/^#\s*postscripts-start-here/,/^#\s*postscripts-end-here/ d" /xcatpost/mypostscript` echo "$TMP" > /xcatpost/mypostscript.post chmod 755 /xcatpost/mypostscript.post if [ ! -x /xcatpost/mypostscript.post ]; then if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "failed to generate /xcatpost/mypostscript.post" "/var/log/xcat/xcat.log" fi else if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "/xcatpost/mypostscript.post generated" "/var/log/xcat/xcat.log" fi fi export OSVER=rhels6.5 #create the post init service as a hook to run PS and PBS, as well as status updating hassystemd=0 systemctl --version 2>/dev/null if [ $? -eq 0 ]; then hassystemd=1 fi if [ $hassystemd -eq 1 ] ; then cat >/etc/systemd/system/xcatpostinit1.service <<'EOF' [Unit] Description=xcat service on compute node, the framework to run postbootscript and update node status After=network.target rsyslog.service [Service] Type=oneshot ExecStart=/opt/xcat/xcatpostinit1 start ExecStop=/opt/xcat/xcatpostinit1 stop RemainAfterExit=yes [Install] WantedBy=multi-user.target EOF msgutil_r "$MASTER_IP" "debug" "/etc/systemd/system/xcatpostinit1.service generated" "/var/log/xcat/xcat.log" ln -s /etc/systemd/system/xcatpostinit1.service /etc/systemd/system/multi-user.target.wants/xcatpostinit1.service msgutil_r "$MASTER_IP" "debug" "xcatpostinit1.service enabled" "/var/log/xcat/xcat.log" cat >/opt/xcat/xcatpostinit1 << 'EOF' #!/bin/bash # IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html # chkconfig: 345 84 59 # description: the hook for systemd service unit to run PB and report node status on diskful node # processname: xcatpostinit1 ### BEGIN INIT INFO # Provides: xcatpostinit1 # Required-Start: $network $syslog # Should-Start: # Required-Stop: $network $syslog # Should-Stop: # Default-Start: 3 4 5 # Default-Stop: 0 1 2 6 # Short-Description: hook to run xcat PBS and report node status # Description: ### END INIT INFO # Source function library. if [ -x /etc/rc.d/init.d/functions ]; then . /etc/rc.d/init.d/functions fi [ -f /opt/xcat/xcatinfo ] && XCATSERVER=`grep 'XCATSERVER' /opt/xcat/xcatinfo |cut -d= -f2 | tr -d \'\" ` [ -f /xcatpost/mypostscript ] && NODESTATUS=`grep 'NODESTATUS=' /xcatpost/mypostscript |awk -F = '{print $2}'|tr -d \'\" | tr A-Z a-z ` [ -z "$NODESTATUS" ] && NODESTATUS="1" [ -f /xcatpost/mypostscript ] && RUNBOOTSCRIPTS=`grep 'RUNBOOTSCRIPTS=' /xcatpost/mypostscript |awk -F = '{print $2}' | tr -d \'\" | tr A-Z a-z ` case $1 in stop) [ "$NODESTATUS" != "n" ] && /xcatpost/updateflag.awk $XCATSERVER 3002 "installstatus powering-off" ;; start) # check for the REBOOT specified in xcatinfo to run post boot scripts on reboot if [ -f /opt/xcat/xcatinfo ]; then REBOOT=`grep 'REBOOT' /opt/xcat/xcatinfo |cut -d= -f2 | tr -d \'\"` fi # if the xcatdsklspost file exists and this is a reboot - run xcatdsklspost with a mode of 6 if [ "$REBOOT" = "TRUE" -a -r /opt/xcat/xcatdsklspost ] && [[ "$RUNBOOTSCRIPTS" =~ ^(1|yes|y)$ ]]; then /opt/xcat/xcatdsklspost 6 elif [ "$REBOOT" = "TRUE" ] && [[ "$NODESTATUS" =~ ^(1|yes|y)$ ]]; then /xcatpost/updateflag.awk $XCATSERVER 3002 "installstatus booted" else # run /opt/xcat/xcatinstallpost if [ -r /opt/xcat/xcatinstallpost ]; then /opt/xcat/xcatinstallpost fi fi ;; esac EOF chmod 755 /opt/xcat/xcatpostinit1 else cat >/etc/init.d/xcatpostinit1 << 'EOF' #!/bin/bash # IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html # chkconfig: 345 84 59 # description: the hook for systemd service unit to run PB and report node status on diskful node # processname: xcatpostinit1 ### BEGIN INIT INFO # Provides: xcatpostinit1 # Required-Start: $network $syslog # Should-Start: # Required-Stop: $network $syslog # Should-Stop: # Default-Start: 3 4 5 # Default-Stop: 0 1 2 6 # Short-Description: hook to run xcat PBS and report node status # Description: ### END INIT INFO # Source function library. if [ -x /etc/rc.d/init.d/functions ]; then . /etc/rc.d/init.d/functions fi [ -f /opt/xcat/xcatinfo ] && XCATSERVER=`grep 'XCATSERVER' /opt/xcat/xcatinfo |cut -d= -f2 | tr -d \'\" ` [ -f /xcatpost/mypostscript ] && NODESTATUS=`grep 'NODESTATUS=' /xcatpost/mypostscript |awk -F = '{print $2}'|tr -d \'\" | tr A-Z a-z ` [ -z "$NODESTATUS" ] && NODESTATUS="1" [ -f /xcatpost/mypostscript ] && RUNBOOTSCRIPTS=`grep 'RUNBOOTSCRIPTS=' /xcatpost/mypostscript |awk -F = '{print $2}' | tr -d \'\" | tr A-Z a-z ` case $1 in stop) [ "$NODESTATUS" != "n" ] && /xcatpost/updateflag.awk $XCATSERVER 3002 "installstatus powering-off" ;; start) # check for the REBOOT specified in xcatinfo to run post boot scripts on reboot if [ -f /opt/xcat/xcatinfo ]; then REBOOT=`grep 'REBOOT' /opt/xcat/xcatinfo |cut -d= -f2 | tr -d \'\"` fi # if the xcatdsklspost file exists and this is a reboot - run xcatdsklspost with a mode of 6 if [ "$REBOOT" = "TRUE" -a -r /opt/xcat/xcatdsklspost ] && [[ "$RUNBOOTSCRIPTS" =~ ^(1|yes|y)$ ]]; then /opt/xcat/xcatdsklspost 6 elif [ "$REBOOT" = "TRUE" ] && [[ "$NODESTATUS" =~ ^(1|yes|y)$ ]]; then /xcatpost/updateflag.awk $XCATSERVER 3002 "installstatus booted" else # run /opt/xcat/xcatinstallpost if [ -r /opt/xcat/xcatinstallpost ]; then /opt/xcat/xcatinstallpost fi fi ;; esac EOF chmod 755 /etc/init.d/xcatpostinit1 if [ ! -x /etc/init.d/xcatpostinit1 ]; then if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "failed to generate /etc/init.d/xcatpostinit1" "/var/log/xcat/xcat.log" fi else if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "/etc/init.d/xcatpostinit1 generated" "/var/log/xcat/xcat.log" fi fi if [[ $OSVER == ubuntu* ]]; then ln -s /etc/init.d/xcatpostinit1 /etc/rc2.d/S84xcatpostinit1 else ln -s /etc/init.d/xcatpostinit1 /etc/rc.d/rc3.d/S84xcatpostinit1 ln -s /etc/init.d/xcatpostinit1 /etc/rc.d/rc4.d/S84xcatpostinit1 ln -s /etc/init.d/xcatpostinit1 /etc/rc.d/rc5.d/S84xcatpostinit1 fi if [[ $OSVER == ubuntu* ]]; then update-rc.d xcatpostinit1 defaults else if [[ $OSVER == sles* ]]; then if [[ $OSVER == sles10* ]]; then /sbin/insserv xcatpostinit1 else /sbin/insserv -p /etc/init.d xcatpostinit1 fi fi #chkconfig --add xcatpostinit1 chkconfig xcatpostinit1 on if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "service xcatpostinit1 enabled" "/var/log/xcat/xcat.log" fi fi fi #create the xcatinstallpost mkdir -p /opt/xcat cat >/opt/xcat/xcatinstallpost << 'EOF' #!/bin/bash # IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html ################################################################# # # xCAT script for running postboot scripts for full install case. ################################################################# . /xcatpost/xcatlib.sh if [ -f /xcatpost/mypostscript.post ]; then XCATDEBUGMODE=`grep 'XCATDEBUGMODE=' /xcatpost/mypostscript.post |cut -d= -f2 | tr -d \'\" | tr A-Z a-z ` MASTER_IP=`grep '^MASTER_IP=' /xcatpost/mypostscript.post |cut -d= -f2|sed s/\'//g` OSVER=`grep '^OSVER=' /xcatpost/mypostscript.post |cut -d= -f2|sed s/\'//g` NODE=`grep '^NODE=' /xcatpost/mypostscript.post |cut -d= -f2|sed s/\'//g` fi if [ ! `uname` = Linux ]; then msgutil_r "$MASTER_IP" "err" "$0: the OS name is not Linux" "/var/log/xcat/xcat.log" exit fi SLI=$(awk 'BEGIN{srand(); printf("%d\n",rand()*10)}') sleep $SLI XCATINFOFILE=/opt/xcat/xcatinfo MACADDR=`grep MACADDRESS= /xcatpost/mypostscript.post |awk -F = '{print $2}'|sed s/\'//g` INSTALLNIC=`ip -o link|grep -i $MACADDR|awk '{print $2}'|sed s/://` # the network between the node and MASTER might be not well configured and activated when running the PBS sometimes # need to make sure... RETRY=0 while true; do #check whether the network access between MN/CN and the node is ready ping $MASTER_IP -c 1 >/dev/null && break RETRY=$[ $RETRY + 1 ] if [ $RETRY -eq 90 ];then #timeout, complain and exit msgutil_r "$MASTER_IP" "err" "`date`: xcatinstallpost: the network between the node and $MASTER_IP is not ready, please check[retry=$RETRY]..." "/var/log/xcat/xcat.log" exit 1 fi #sleep sometime before the next scan sleep 2 done cd /xcatpost; PATH=/xcatpost:$PATH export PATH # To support the postscripts in the subdirectories under /install/postscripts #chmod +x /xcatpost/*; chmod -R +x `find /xcatpost/ -maxdepth 1 -print | grep -E -v '^(/xcatpost/|/xcatpost/_xcat|/xcatpost/_ssh|/xcatpost/ca|/xcatpost/hostkeys)$'` POST_IN_DIR="/xcatpost" if [ -x /usr/bin/openssl ]; then SIP=`grep "^MASTER=" ${POST_IN_DIR}/mypostscript.post |cut -d= -f2` XCATSERVER="$SIP:3001" export XCATSERVER USEOPENSSLFORXCAT=1 #Though this is the only method going forward, flag to allow backward compatibility with 2.2 generated netboot images export USEOPENSSLFORXCAT fi # Regardless of where mypostscript.post was found, modify and run it in /xcatpost. DHCP_TMP=`sed 's/\(DHCPINTERFACES=\)\(.*\)$/\1"\2"/' /xcatpost/mypostscript.post` echo "$DHCP_TMP" > /xcatpost/mypostscript.post #mark that the first reboot after installation is finished grep 'REBOOT' /opt/xcat/xcatinfo > /dev/null 2>&1 if [ $? -eq 0 ]; then sed -i "s/REBOOT=.*/REBOOT=TRUE/" /opt/xcat/xcatinfo else echo "REBOOT=TRUE" >> /opt/xcat/xcatinfo fi #add node name to xcatinfo grep 'NODE' /opt/xcat/xcatinfo > /dev/null 2>&1 if [ $? -eq 0 ]; then sed -i "s/NODE=.*/NODE=$NODE/" /opt/xcat/xcatinfo else echo "NODE=$NODE" >> /opt/xcat/xcatinfo fi # Store the SERVICEGROUP into the xcatinfo file for statful installation sn_group=`grep '^SERVICEGROUP' /xcatpost/mypostscript |cut -d= -f2 | tr -d \'\"` if [ "x" != "x$sn_group" ]; then # Change or add SERVICEGROUP line if service node pool defined. grep 'SERVICEGROUP=' $XCATINFOFILE > /dev/null 2>&1 if [ $? -eq 0 ]; then sed -i "s/SERVICEGROUP=.*/SERVICEGROUP=$sn_group/" $XCATINFOFILE else echo "SERVICEGROUP=$sn_group" >> $XCATINFOFILE fi else # Remove SERVICEGROUP line if no service node pool defined. sed -i "/SERVICEGROUP=.*/d" $XCATINFOFILE fi [ -f /xcatpost/mypostscript ] && NODESTATUS=`grep 'NODESTATUS=' /xcatpost/mypostscript |awk -F = '{print $2}'|tr -d \'\" | tr A-Z a-z ` [ -z "$NODESTATUS" ] && NODESTATUS="1" CNS=$NODESTATUS if [ -z "$CNS" ] || [[ "$CNS" =~ ^(1|yes|y)$ ]]; then #update the node status during the postbootscript running #TMP=`sed "/postbootscripts-start-here/ i\updateflag.awk \\$MASTER 3002 \\"installstatus configuring\\"" /xcatpost/mypostscript.post` #echo "$TMP"> /xcatpost/mypostscript.post echo " [ -f /opt/xcat/xcatinfo ] && grep 'POSTSCRIPTS_RC=1' /opt/xcat/xcatinfo >/dev/null 2>&1 && return_value=1 if [ \"\$return_value\" -eq \"0\" ]; then if [ \"\$XCATDEBUGMODE\" = \"1\" ] || [ \"\$XCATDEBUGMODE\" = \"2\" ]; then msgutil_r \"\$MASTER_IP\" \"info\" \"node booted, reporting status...\" \"/var/log/xcat/xcat.log\" fi updateflag.awk \$MASTER 3002 \"installstatus booted\" msgutil_r \$MASTER_IP \"info\" \"provision completed.(\$NODE)\" \"/var/log/xcat/xcat.log\" else if [ \"\$XCATDEBUGMODE\" = \"1\" ] || [ \"\$XCATDEBUGMODE\" = \"2\" ]; then msgutil_r \"\$MASTER_IP\" \"info\" \"node boot failed, reporting status...\" \"/var/log/xcat/xcat.log\" fi updateflag.awk \$MASTER 3002 \"installstatus failed\" fi " >> /xcatpost/mypostscript.post fi chmod +x /xcatpost/mypostscript.post if [ -x /xcatpost/mypostscript.post ];then msgutil_r "$MASTER_IP" "info" "running /xcatpost/mypostscript.post" "/var/log/xcat/xcat.log" /xcatpost/mypostscript.post msgutil_r "$MASTER_IP" "info" "/xcatpost/mypostscript.post return" "/var/log/xcat/xcat.log" fi if [ -f /xcatpost/mypostscript.post ]; then RUNBOOTSCRIPTS=`grep 'RUNBOOTSCRIPTS=' /xcatpost/mypostscript.post |cut -d= -f2 | tr -d \'\" | tr A-Z a-z` fi if [[ $OSVER == ubuntu* ]]; then if [[ ! "$RUNBOOTSCRIPTS" =~ ^(1|yes|y)$ ]]; then update-rc.d -f xcatpostinit1 remove fi if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "update-rc.d -f xcatpostinit1 remove" "/var/log/xcat/xcat.log" fi else if [[ ! "$RUNBOOTSCRIPTS" =~ ^(1|yes|y)$ ]] && [[ ! "$NODESTATUS" =~ ^(1|yes|y)$ ]]; then chkconfig xcatpostinit1 off if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "service xcatpostinit1 disabled" "/var/log/xcat/xcat.log" fi fi fi EOF chmod 755 /opt/xcat/xcatinstallpost if [ ! -x /opt/xcat/xcatinstallpost ]; then if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "failed to generate /opt/xcat/xcatinstallpost" "/var/log/xcat/xcat.log" fi else if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "/opt/xcat/xcatinstallpost generated" "/var/log/xcat/xcat.log" fi fi #create the dskls post cat >/opt/xcat/xcatdsklspost << 'EOF' #!/bin/bash # IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html ##################################################### # # Generic xCAT post script for diskless nodes # The syntax of this script: # xcatdsklspost {mode} {-m|-M} [postscripts] --tftp /tftpboot --installdir /install --nfsv4 no -c -V # This script is called in the following different places: # updatenode -P ... --> xcatdsklspost 1 -m/-M ... # updatenode -S --> xcatdsklspost 2 -m/-M otherpkgs # moncfg rmcmon --> xcatdsklspost 3 configrmcnodes # node deployment --> xcatdsklspost # statelite mode --> xcatdsklspost 4 # update security --> xcatdsklspost 5 -m/-M ... # node reboot - xcatpostinit1 --> xcatdsklspost 6 # This script has a debug mode, if XCATDEBUG env variable is set, then # /xcatpost becomes /xcatpost.. This allow running multiple # instances of the script to simulate many node on one physical node # ##################################################### [ -f "/xcatpost/xcatlib.sh" ] && . /xcatpost/xcatlib.sh if [ -f /xcatpost/mypostscript.post ]; then XCATDEBUGMODE=`grep 'XCATDEBUGMODE=' /xcatpost/mypostscript.post | cut -d= -f2 | tr -d \'\" | tr A-Z a-z` MASTER_IP=`grep '^MASTER_IP=' /xcatpost/mypostscript.post |cut -d= -f2|sed s/\'//g` else for param in `cat /proc/cmdline`; do key=`echo $param|awk -F= '{print $1}'` if [ "$key" = "xcatdebugmode" ]; then XCATDEBUGMODE=`echo $param|awk -F= '{print $2}'| tr -d \'\" | tr A-Z a-z` fi if [ "$key" = "LOGSERVER" ]; then MASTER_IP=`echo $param|awk -F= '{print $2}'` fi done fi XCATINFOFILE=/opt/xcat/xcatinfo #echolog: process message log and echo in xcatdsklspost #arguments: # msgtype: message type, valid values:debug,info,warning,err # msgstr : the string of message #description: # echo messages only when ($msgtype != debug) or ($msgtype = debug && $VERBOSE = 1) # log "debug" messages only when (site.xcatdebugmode=1),log all messages with other types # append the "debug" messages to "/var/log/xcat/xcat.log" when (site.xcatdebugmode=1) # append all the other type messages to "/var/log/xcat/xcat.log" echolog() { local msgtype=$1 local msgstr=$2 local ismsgutil_r=1 #if msgutil_r is not defined, when no /xcatpost directory exists on the node running this script #write the message to local log file as a simplified function type -t msgutil_r >/dev/null || ismsgutil_r=0 [ "$ismsgutil_r" = "0" ] && msgutil_r () { echo "$(date) [$2]: $3" >> $4 } if [ "$msgtype" = "debug" ];then if [ "$VERBOSE" = "1" ]; then echo "$msgstr" fi if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "$msgtype" "$msgstr" "/var/log/xcat/xcat.log" fi else echo "$msgstr" msgutil_r "$MASTER_IP" "$msgtype" "$msgstr" "/var/log/xcat/xcat.log" fi #reload the functions defined in./xcatlib.sh if [ "$ismsgutil_r" = "0" ];then unset msgutil_r [ -f ./xcatlib.sh ] && source ./xcatlib.sh fi } update_VPD() { if [ -f /usr/sbin/vpdupdate ]; then vpdupdate #logger -t xCAT -p local4.info "xcatdsklspost: updating VPD database" echolog "info" "xcatdsklspost: updating VPD database" fi } # Run updatevpd only when necessary if [ -f /usr/sbin/lsvpd ]; then /usr/sbin/lsvpd | grep -i -E 'cpu|processor' 2>&1 1>/dev/null if [ "$?" = "1" ]; then update_VPD fi fi download_postscripts() { server=$1 if [ -z $server ]; then return 1; fi # Do not override the parameter --installdir if [ -z "$INSTALLDIR" ]; then if [ -f /opt/xcat/xcatinfo ]; then INSTALLDIR=`grep 'INSTALLDIR' /opt/xcat/xcatinfo |cut -d= -f2` fi if [ -z "$INSTALLDIR" ]; then INSTALLDIR="/install" fi fi #logger -t xCAT -p local4.debug "$0 : trying to download postscripts from http://$server$INSTALLDIR/postscripts/" echolog "debug" "xcatdsklspost : trying to download postscripts from http://$server$INSTALLDIR/postscripts/" max_retries=5 retry=0 rc=1 # this is a fail return while [ 0 -eq 0 ]; do if [ -e "$xcatpost" ]; then rm -rf "$xcatpost" fi export LANG=C; wget -l inf -nH -N -r --waitretry=10 --random-wait -e robots=off -T 60 -nH --cut-dirs=2 --reject "index.html*" --no-parent http://$server$INSTALLDIR/postscripts/ -P /$xcatpost 2> /tmp/wget.log rc=$? if [ $rc -eq 0 ]; then # return from wget was 0 but some OS do not return errors, so we # have additional checks for # failed: Connection httpd not running # 404: Not Found - if directory does not exist grep -i -E "... failed: Connection refused.$" /tmp/wget.log rc1=$? grep -i -E "ERROR 404: Not Found.$" /tmp/wget.log rc2=$? # check to see no errors at all, grep returns 1 if [ $rc1 -eq 1 ] && [ $rc2 -eq 1 ]; then echolog "debug" "$0 : download_postscripts return successfully " return 0 fi fi retry=$(($retry+1)) echolog "debug" "download_postscripts retry $retry" if [ $retry -eq $max_retries ]; then echolog "debug" "$0 : download_postscripts failed" break fi SLI=$(awk 'BEGIN{srand(); printf("%d\n",rand()*20)}') sleep $SLI done return $rc } download_mypostscript() { server=$1 node=$2 max_retries=$3 TFTPDIR=$4 if [ -z $server ]; then return 1; fi if [ -z "$TFTPDIR" ]; then TFTPDIR="/tftpboot" fi retry=0 rc=1 echolog "debug" "$0 : trying to download http://$server$TFTPDIR/mypostscripts/mypostscript.$node" while [ 0 -eq 0 ]; do wget -N --waitretry=10 --random-wait -T 60 http://$server$TFTPDIR/mypostscripts/mypostscript.$node -P /$xcatpost 2>> /tmp/wget.log rc=$? # if no error and the file was downloaded if [ $rc -eq 0 ] && [ -f /$xcatpost/mypostscript.$node ]; then mv /$xcatpost/mypostscript.$node /$xcatpost/mypostscript echolog "debug" "$0 download_mypostscript return successfully " return 0; fi retry=$(($retry+1)) if [ $retry -eq $max_retries ]; then echolog "debug" "$0 : download_mypostscript failed" break fi done return $rc } # pmatch determines if 1st argument string is matched by 2nd argument pattern pmatch () { case $1 in $2) return 0;; # zero return code means string matched by pattern esac return 1 # non-zero return code means string not matched by pattern } # Main # parse the arguments ARGNUM=$#; if [ -z $1 ]; then NODE_DEPLOYMENT=1 else NODE_DEPLOYMENT=0 case $1 in 1|2|5) MODE=$1 if [ $ARGNUM -gt 1 ]; then if [ $2 = "-m" ]; then P_SIP=$3 else if [ $2 = "-M" ]; then P_SIP=$3 new_ms=$P_SIP # -M means we will update xcatinfo file XCATSERVER fi fi fi if [ $ARGNUM -gt 3 ]; then POSTSCRIPTS=$4 fi if [ $ARGNUM -gt 4 ]; then if [ $5 = "--tftp" ]; then TFTPDIR=$6 fi fi if [ $ARGNUM -gt 6 ]; then if [ $7 = "--installdir" ]; then INSTALLDIR=$8 fi fi if [ $ARGNUM -gt 8 ]; then if [ $9 = "--nfsv4" ]; then NFSV4=${10} fi fi if [ $ARGNUM -gt 10 ]; then if [ ${11} = "-c" ]; then CFLAG=${11} fi fi if [ $ARGNUM -gt 11 ]; then if [ ${12} = "-V" ]; then export VERBOSE=1 fi if [ ${12} = "-F" ]; then export USEFLOWCONTROL=1 fi fi if [ $ARGNUM -gt 12 ]; then if [ ${13} = "-V" ]; then export VERBOSE=1 fi fi ;; 3|4|6) MODE=$1;; esac fi # set the default path for the xcatpost directory xcatpost="/xcatpost" # Check for debug mode and you have nodename available you can change the path for debug echolog "debug" "running $0 $*" if [ -n "$XCATDEBUG" ]; then if [ -n "$NODE" ]; then xcatpost="/xcatpost.$NODE" fi fi #echo "xcatpost = $xcatpost" useflowcontrol=0 if [ "$USEFLOWCONTROL" = "1" ]; then useflowcontrol=1 fi # from install kcmdline if [ "$FC" = "1" ] || [ "$FC" = "yes" ] || [ "$FC" = "YES" ]; then useflowcontrol=1 fi # If on AIX node if [ ! `uname` = Linux ]; then #Get a new copy of xcataixpost on the node mkdir -p /$xcatpost; mkdir -p /xcatmnt; if [ "$NFSV4" = "yes" ]; then mount -o vers=4 $P_SIP:$INSTALLDIR/postscripts /xcatmnt else mount $P_SIP:$INSTALLDIR/postscripts /xcatmnt fi cp /xcatmnt/xcataixpost /$xcatpost umount /xcatmnt rmdir /xcatmnt logger -t xcat -p local4.err "Running xcataixpost $*" # note not supporting -F or -V on AIX echo "/$xcatpost/xcataixpost $1 $2 $3 '"$4"' $5 $6 $7 $8 $9 ${10} ${11}" exec /$xcatpost/xcataixpost $1 $2 $3 "$4" $5 $6 $7 $8 $9 ${10} ${11} exit fi #SLI=$(awk 'BEGIN{srand(); printf("%d\n",rand()*10)}') #sleep $SLI if [ ! -d /$xcatpost ]; then mkdir -p /$xcatpost; fi if [ ! -d /tmp/postage ]; then mkdir -p /tmp/postage fi rm -R -f /tmp/postage/* #here we get all the postscripts. Please do not change this behaviour because some scripts depend on others cd /tmp/postage if [ "$MODE" = "4" ]; then # for statelite mode # We have written the xCATSERVER info into the kernel command line!! for i in `cat /proc/cmdline`; do KEY=`echo $i | awk -F= '{print $1}'` if [ "$KEY" = "XCAT" ]; then TMP=`echo $i | awk -F= '{print $2}'` XCATSERVER=`echo $TMP | cut -d: -f1` grep 'XCATSERVER' /opt/xcat/xcatinfo > /dev/null 2>&1 if [ $? -eq 0 ]; then sed -i "s/XCATSERVER=.*/XCATSERVER=$XCATSERVER/" /opt/xcat/xcatinfo else echo "XCATSERVER=$XCATSERVER" >> /opt/xcat/xcatinfo fi break fi done if [ -f /opt/xcat/xcatinfo ]; then SIP=`grep 'XCATSERVER' /opt/xcat/xcatinfo |cut -d= -f2` if [ -n "$SIP" ]; then download_postscripts $SIP if [ $? -eq 0 ]; then downloaded=1 fi fi else #echo "xCAT management server IP can't be determined."; #echo "exiting..."; #logger -t xCAT -p local4.err "xcatdsklspost:xCAT management server IP can't be determined.\nexiting..."; echolog "err" "xcatdsklspost:xCAT management server IP can't be determined.\nexiting..." exit; fi else # for common mode MODE=1,2,3,5 (updatenode,moncfg,node deployment) # non-Statelite MODE # If we have written the NODE info into the kernel command line, # put in in xcatinfo if [ ! -f /opt/xcat/xcatinfo ]; then mkdir -p /opt/xcat touch /opt/xcat/xcatinfo fi for i in `cat /proc/cmdline`; do KEY=`echo $i | awk -F= '{print $1}'` if [ "$KEY" = "NODE" ]; then NODE=`echo $i | awk -F= '{print $2}'` break fi done grep 'NODE' /opt/xcat/xcatinfo > /dev/null 2>&1 if [ $? -eq 0 ]; then sed -i "s/NODE=.*/NODE=$NODE/" /opt/xcat/xcatinfo else echo "NODE=$NODE" >> /opt/xcat/xcatinfo fi downloaded=0; # have not downloaded the postscripts # try the -m/-M input (P_SIP) if it is specified, # -m/-M is passed in the updatenode command # and is the address of the xcatmaster for this node. Using -M just means # also update the XCATSERVER in the /etc/xcat/xcatinfo file with this # address if [ -n "$P_SIP" ]; then # passed in with updatenode on -M/-m SIP=$P_SIP download_postscripts $SIP if [ $? -eq 0 ]; then downloaded=1 fi fi # if the download failed then, if not updatenode # open the xcatinfo file to look for an XCATSERVER address to try # if the address if not the same as the one on the -m/M flag then # try it if [ $downloaded -eq 0 ]; then # if this is an updatenode call, then stop trying and # return an error if [ "$MODE" = "1" ] || [ "$MODE" = "2" ] || [ "$MODE" = "5" ]; then # updatenode hn=`hostname` #echo "Cannot download the postscripts from $SIP for $hn check /tmp/wget.log on the node." #logger -t xCAT -p local4.err "xcatdsklspost:Cannot download the postscripts from the xCAT server $SIP for node $hn check /tmp/wget.log on the node." echolog "err" "xcatdsklspost:Cannot download the postscripts from the xCAT server $SIP for node $hn check /tmp/wget.log on the node." exit fi # if not updatenode, then look in xcatinfo for the xcatmaster if [ -f /opt/xcat/xcatinfo ]; then SIP=`grep 'XCATSERVER' /opt/xcat/xcatinfo |cut -d= -f2` if [ -n "$SIP" ]; then download_postscripts $SIP if [ $? -eq 0 ]; then downloaded=1 fi fi fi fi # download postscripts has not worked yet if [ $downloaded -eq 0 ]; then # for the non-updatenode calls try the host in the XCAT kernel param. for i in `cat /proc/cmdline`; do KEY=`echo $i | awk -F= '{print $1}'` if [ "$KEY" = "XCAT" ]; then TMP=`echo $i | awk -F= '{print $2}'` SIP=`echo $TMP | cut -d: -f1` if [ -n "$SIP" ]; then download_postscripts $SIP if [ $? -eq 0 ]; then downloaded=1 break fi fi fi done fi # download poscripts has not worked yet #try the dhcp server, this is used for initial boot for the node. if [ $downloaded -eq 0 ]; then #setup $OSVER ,for SLES11 if [ -e '/etc/SuSE-release' ]; then OSVER=`grep -h VERSION /etc/SuSE-release |awk '{print $3}'` fi SIPS=`grep -h dhcp-server-identifier /var/lib/dhclient/dhclient*eth*.leases 2> /dev/null|awk '{print $3}'|sed -e 's/;//'` if [ -z "$SIPS" ]; then SIPS=`grep -h dhcp-server-identifier /var/lib/dhclient/dhclient*hf*.leases 2> /dev/null|awk '{print $3}'|sed -e 's/;//'` if [ -z "$SIPS" ]; then SIPS=`grep -h DHCPSID /var/lib/dhcpcd/*.info 2> /dev/null|awk -F= '{print $2}'|sed -e s/\'//g` fi fi SIP=`echo $SIPS|awk '{printf $NF}' | tail -n 1` #Pick one for wget if [ -n "$SIP" ]; then download_postscripts $SIP if [ $? -eq 0 ]; then downloaded=1 fi elif [ -x "/sbin/dhcpcd" ]; then # New dhcpcd doesn't creates *.info files. for lease in $(ls "/var/lib/dhcpcd/"); do iface="$(echo "$lease" | sed -n -e 's/^dhcpcd-\(.*\)\.lease$/\1/p')" if [ -n "$iface" ]; then SIP="$(dhcpcd -q -T "$iface" | sed -n -e '/new_dhcp_server_identifier/ s/.*=//p')" if [ -n "$SIP" ]; then download_postscripts $SIP if [ $? -eq 0 ]; then downloaded=1 break fi fi fi done fi fi #no hope to download postscripts, now let's get out of here. if [ $downloaded -eq 0 ]; then hn=`hostname` #echo "Cannot download the postscripts from the xCAT server for node $hn" #logger -t xCAT -p local4.err "xcatdsklspost:Cannot download the postscripts from the xCAT server for node $hn" echolog "err" "xcatdsklspost: Cannot download the postscripts from the xCAT server for node $hn" exit else echolog "info" "xcatdsklspost: downloaded postscripts successfully" fi fi # finish the postscripts download # remove the current mypostscript file rm -rf /$xcatpost/mypostscript # if NODE is exported ( updatenode call or from kernel parameter) # use it as the nodename to get the mypostscript file. if [ -n "$NODE" ]; then node_short=$NODE else #get node name and download the mypostscript.$node file #try to get the node ip address that connects to the server. #then resolve the name of the ip real_SIP=`getent hosts $SIP |awk {'print $1'}` if [ $? -ne 0 ]; then real_SIP=$SIP fi NIP=`ip route get $real_SIP | head -n 1 | sed 's/^.*src//g' | awk {'print $1'}` if [ $? -eq 0 ] && [ -n "$NIP" ]; then #resolve the name of the node from ip address result=`getent hosts $NIP` if [ $? -eq 0 ]; then node1=`echo $result | awk {'print $2'}` node2=`echo $result | awk {'print $3'}` if [ ${#node1} -gt ${#node2} ]; then node=$node1 node_short=$node2 else node=$node2 node_short=$node1 fi if [ -z "$node_short" ]; then node_short=`echo $node |awk -F. {'print $1'}` fi else if [ -z "$node" ]; then node=`hostname` node_short=`hostname -s` fi fi else node=`hostname` node_short=`hostname -s` fi fi max_retries=2 # try short hostname first if [ -n "$node_short" ]; then download_mypostscript $SIP $node_short $max_retries $TFTPDIR if [ $? -ne 0 ]; then # try long hostname if [ "$node" != "$node_short" ]; then download_mypostscript $SIP $node $postfix $max_retries $TFTPDIR fi fi fi # on reboot and shutdown, make sure /ro and /rw are not stuck mounted if grep 'rw /rw tmpfs ' /proc/mounts >/dev/null 2>&1; then touch /var/lock/subsys/xcatmounts echo '#!/bin/bash' > /etc/rc6.d/K10xcatmounts echo umount -l /ro >> /etc/rc6.d/K10xcatmounts echo umount -l /rw >> /etc/rc6.d/K10xcatmounts chmod 755 /etc/rc6.d/K10xcatmounts ln -sf /etc/rc6.d/K10xcatmounts /etc/rc0.d/K10xcatmounts fi # To support the postscripts in the subdirectories under /install/postscripts #chmod +x /$xcatpost/*; chmod -R +x `find $xcatpost/ -maxdepth 1 -print | grep -E -v "^($xcatpost/|$xcatpost/_xcat|$xcatpost/_ssh|$xcatpost/ca|$xcatpost/hostkeys)$"` cd /$xcatpost; PATH=/$xcatpost:$PATH export PATH if [ -x /usr/bin/openssl ]; then XCATSERVER="$SIP:3001" export XCATSERVER USEOPENSSLFORXCAT=1 #Though this is the only method going forward, flag to allow backward compatibility with 2.2 generated netboot images export USEOPENSSLFORXCAT fi # if download of postscript failed, # probably the /tftpboot/mypostcript/mypostscript. does not exist. # We need to call getpostscript.awk . if [ ! -x /$xcatpost/mypostscript ]; then echolog "info" "xcatdsklspost: failed to download mypostscript., trying to call getpostscript.awk..." if [ $useflowcontrol = "1" ]; then # first contact daemon xcatflowrequest 3001 #logger -t xCAT -p local4.info "xcatdsklspost:sending xcatflowrequest $SIP 3001" echolog "debug" "xcatdsklspost:sending xcatflowrequest $SIP 3001" /$xcatpost/xcatflowrequest $SIP 3001 rc=$? #logger -t xCAT -p local4.info "xcatdsklspost:xcatflowrequest return=$rc" echolog "debug" "xcatdsklspost:xcatflowrequest return=$rc" if [ $rc -ne 0 ]; then #logger -t xCAT -p local4.info "xcatdsklspost: error from xcatflowrequest, will not use flow control" echolog "debug" "xcatdsklspost: error from xcatflowrequest, will not use flow control" useflowcontrol=0 fi fi /$xcatpost/getpostscript.awk | egrep '' | sed -e 's/<[^>]*>//g'|egrep -v '^ *$'|sed -e 's/^ *//' | sed -e 's/<//g' -e 's/&/\&/g' -e 's/"/"/g' -e "s/'/'/g" > /$xcatpost/mypostscript; MYCONT=`grep MASTER /$xcatpost/mypostscript` MAX_RETRIES=10 RETRY=0 while [ -z "$MYCONT" ]; do # not using flow control , need to sleep if [ $useflowcontrol = "0" ]; then let SLI=$RANDOM%10 let SLI=SLI+10 sleep $SLI fi RETRY=$(($RETRY+1)) if [ $RETRY -eq $MAX_RETRIES ] then break fi if [ $useflowcontrol = "1" ]; then # contact daemon xcatflowrequest 3001 #logger -t xCAT -p local4.info "xcatdsklspost: sending xcatflowrequest $SIP 3001" echolog "debug" "xcatdsklspost: sending xcatflowrequest $SIP 3001" /$xcatpost/xcatflowrequest $SIP 3001 rc=$? #logger -t xCAT -p local4.info "xcatdsklspost:xcatflowrequest return=$rc" echolog "debug" "xcatdsklspost:xcatflowrequest return=$rc" if [ $rc -ne 0 ]; then #logger -t xCAT -p local4.info "xcatdsklspost: error from xcatflowrequest, will not use flow control" echolog "debug" "xcatdsklspost: error from xcatflowrequest, will not use flow control" useflowcontrol=0 fi fi /$xcatpost/getpostscript.awk | egrep '' | sed -e 's/<[^>]*>//g'|egrep -v '^ *$'|sed -e 's/^ *//' | sed -e 's/<//g' -e 's/&/\&/g' -e 's/"/"/g' -e "s/'/'/g" > /$xcatpost/mypostscript; MYCONT=`grep MASTER /$xcatpost/mypostscript` if [ ! -z "$MYCONT" ]; then break; fi done fi #save the MASTER into the xcatinfo file for node deployment case, #for updatenode case, only save it when -M is specified if [ $NODE_DEPLOYMENT -eq 1 ] || [ "$MODE" = "4" ]; then new_ms=`grep '^MASTER' /$xcatpost/mypostscript |head -n 1 |cut -d= -f2` fi if [ -n "$new_ms" ]; then if [ ! -f /opt/xcat/xcatinfo ]; then mkdir -p /opt/xcat touch /opt/xcat/xcatinfo fi grep 'XCATSERVER' /opt/xcat/xcatinfo > /dev/null 2>&1 if [ $? -eq 0 ]; then sed -i "s/XCATSERVER=.*/XCATSERVER=$new_ms/" /opt/xcat/xcatinfo else echo "XCATSERVER=$new_ms" >> /opt/xcat/xcatinfo fi fi #save the USEFLOWCONTROL into the xcatinfo file #for updatenode case, passwd in with the -f flag if [ $NODE_DEPLOYMENT -eq 1 ] || [ "$MODE" = "4" ]; then useflowcontrol=`grep '^USEFLOWCONTROL' /$xcatpost/mypostscript |cut -d= -f2 | tr -d \'\" | tr A-Z a-z` fi if [ ! -f /opt/xcat/xcatinfo ]; then mkdir -p /opt/xcat touch /opt/xcat/xcatinfo fi if [ -n "$useflowcontrol" ]; then # lets just put YES or NO in xcatinfo if [[ "$useflowcontrol" =~ ^(1|yes|y)$ ]]; then new_fc="YES" else new_fc="NO" fi grep 'USEFLOWCONTROL' /opt/xcat/xcatinfo > /dev/null 2>&1 if [ $? -eq 0 ]; then sed -i "s/USEFLOWCONTROL=.*/USEFLOWCONTROL=$new_fc/" /opt/xcat/xcatinfo else echo "USEFLOWCONTROL=$new_fc" >> /opt/xcat/xcatinfo fi # no setting means do not use flowcontrol else echo "USEFLOWCONTROL=NO" >> /opt/xcat/xcatinfo fi # Store the SERVICEGROUP into the xcatinfo file for node deployment, and also for updatenode -s if [ $NODE_DEPLOYMENT -eq 1 ] || [ "$MODE" = "1" ]; then sn_group=`grep '^SERVICEGROUP' /$xcatpost/mypostscript |cut -d= -f2 | tr -d \'\"` if [ "x" != "x$sn_group" ]; then # Change or add SERVICEGROUP line if service node pool defined. grep 'SERVICEGROUP=' $XCATINFOFILE > /dev/null 2>&1 if [ $? -eq 0 ]; then sed -i "s/SERVICEGROUP=.*/SERVICEGROUP=$sn_group/" $XCATINFOFILE else echo "SERVICEGROUP=$sn_group" >> $XCATINFOFILE fi else # Remove SERVICEGROUP line if no service node pool defined. sed -i "/SERVICEGROUP=.*/d" $XCATINFOFILE fi fi # when called by the updatenode command MODE=1,2 # the nodename is passed in by xdsh in the NODE environment variable by xdsh. #modify the UPDATENODE flag to 1 # put NODE in /opt/xcat/xcatinfo if [ "$MODE" = "1" ] || [ "$MODE" = "2" ]; then TMP=`sed -e 's/UPDATENODE=0/UPDATENODE=1/g' /$xcatpost/mypostscript`; echo "$TMP" > /$xcatpost/mypostscript; if [ ! -f /opt/xcat/xcatinfo ]; then mkdir -p /opt/xcat touch /opt/xcat/xcatinfo fi grep 'NODE' /opt/xcat/xcatinfo > /dev/null 2>&1 if [ $? -eq 0 ]; then sed -i "s/NODE=.*/NODE=$NODE/" /opt/xcat/xcatinfo else echo "NODE=$NODE" >> /opt/xcat/xcatinfo fi #echo "xcatdsklspost:my nodename in the database is $NODE" fi if [ "$MODE" = "5" ]; then TMP=`sed -e 's/UPDATENODE=0/UPDATENODE=1\nUPDATESECURITY=1\nexport UPDATESECURITY/g' /$xcatpost/mypostscript`; echo "$TMP" > /$xcatpost/mypostscript; fi #when a diskfull reboot mode if [ "$MODE" = "6" ]; then # remove the post scripts so that they are not run on reboot TMP=`sed "/# postscripts-start-here/,/# postscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript # get the RUNBOOTSCRIPTS site variable if [ -f /$xcatpost/mypostscript ]; then RUNBOOTSCRIPTS=`grep 'RUNBOOTSCRIPTS=' /$xcatpost/mypostscript |cut -d= -f2 | tr -d \'\" | tr A-Z a-z ` fi # if admin did not requested running of post boot scripts - then remove PBS if [[ ! "$RUNBOOTSCRIPTS" =~ ^(1|yes|y)$ ]]; then #remove all the postscripts TMP=`sed "/# postbootscripts-start-here/,/# postbootscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript #TMP=`sed "/postbootscripts-start-here/,/postbootscripts-end-here/ d" /$xcatpost/mypostscript.post` #echo "$TMP" > /$xcatpost/mypostscript.post fi fi # postscript name is specified with the updatenode #cp /$xcatpost/mypostscript /$xcatpost/mypostscript.backup # if the list has a postscript named *start-here* then we must rebuild the # mypostscript file with only the matching *start-here stanza. if ( pmatch $POSTSCRIPTS "*start-here*" ); then if ( pmatch $POSTSCRIPTS "*osimage-postbootscripts-start-here" ); then # remove all sections but the osimage-postbootscripts section TMP=`sed "/# postscripts-start-here/,/# postscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript TMP=`sed "/# defaults-postbootscripts-start-here/,/# defaults-postbootscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript TMP=`sed "/# node-postbootscripts-start-here/,/# node-postbootscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript fi if ( pmatch $POSTSCRIPTS "*postscripts-start-here" ); then #remove all the postbootscripts TMP=`sed "/# postbootscripts-start-here/,/# postbootscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript fi if ( pmatch $POSTSCRIPTS "*postbootscripts-start-here" ); then #remove all the postscripts TMP=`sed "/# postscripts-start-here/,/# postscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript fi if ( pmatch $POSTSCRIPTS "*defaults-postscripts-start-here" ); then # remove all sections but the defaults-postscripts section TMP=`sed "/# osimage-postscripts-start-here/,/# osimage-postscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript TMP=`sed "/# node-postscripts-start-here/,/# node-postscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript TMP=`sed "/# postbootscripts-start-here/,/# postbootscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript fi if ( pmatch $POSTSCRIPTS "*node-postscripts-start-here" ); then # remove all sections but the node-postscripts section TMP=`sed "/# osimage-postscripts-start-here/,/# osimage-postscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript TMP=`sed "/# defaults-postscripts-start-here/,/# defaults-postscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript TMP=`sed "/# postbootscripts-start-here/,/# postbootscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript fi if ( pmatch $POSTSCRIPTS "*defaults-postbootscripts-start-here" ); then # remove all sections but the defaults-postbootscripts section TMP=`sed "/# osimage-postbootscripts-start-here/,/# osimage-postbootscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript TMP=`sed "/# node-postbootscripts-start-here/,/# node-postbootscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript TMP=`sed "/# postscripts-start-here/,/# postscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript fi if ( pmatch $POSTSCRIPTS "*node-postbootscripts-start-here" ); then # remove all sections but the node-postbootscripts section TMP=`sed "/# osimage-postbootscripts-start-here/,/# osimage-postbootscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript TMP=`sed "/# defaults-postbootscripts-start-here/,/# defaults-postbootscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript TMP=`sed "/# postscripts-start-here/,/# postscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript fi # check to see if input postscript list is not empty. If there is a list # remove the built postscripts and only add the ones for the list. else if [ -n "$POSTSCRIPTS" ]; then #remove all the postbootscripts, and replace with list provided TMP=`sed "/# postbootscripts-start-here/,/# postbootscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript #remove all the postscripts TMP=`sed "/# postscripts-start-here/,/# postscripts-end-here/ d" /$xcatpost/mypostscript` echo "$TMP" > /$xcatpost/mypostscript echo "# postscripts-start-here" >> /$xcatpost/mypostscript #add requested postscripts in echo "$POSTSCRIPTS" | tr "," "\n" >> /$xcatpost/mypostscript echo "# postscripts-end-here" >> /$xcatpost/mypostscript fi fi #ADDSITEYUM is set by post.rh and post.rh.iscsi for full installtion #if [[ "$ADDSITEYUM" = "1" ]]; then # TMP=`sed "/postscripts-start-here/ a addsiteyum" /$xcatpost/mypostscript` # echo "$TMP" > /$xcatpost/mypostscript #fi #MYCONT=`cat /$xcatpost/mypostscript` #echo "$MYCONT" # use the run_ps subroutine to run the postscripts if [ $NODE_DEPLOYMENT -eq 1 ] || [ "$MODE" = "4" ] || [ "$MODE" = "6" ]; then TMP=`sed "/# postscripts-start-here/,/# postscripts-end-here/ s/\(.*\)/run_ps postbootscript \1/;s/run_ps postbootscript\s*#/#/;s/run_ps postbootscript\s*$//" /$xcatpost/mypostscript` else TMP=`sed "/# postscripts-start-here/,/# postscripts-end-here/ s/\(.*\)/run_ps postscript \1/;s/run_ps postscript\s*#/#/;s/run_ps postscript\s*$//" /$xcatpost/mypostscript` fi echo "#!/bin/bash . /xcatpost/xcatlib.sh # global value to store the running status of the postbootscripts,the value is non-zero if one postbootscript failed return_value=0 # subroutine used to run postscripts # \$1 argument is the script type # rest argument is the script name and arguments run_ps () { local ret_local=0 mkdir -p "\"/var/log/xcat\"" local logfile=\"/var/log/xcat/xcat.log\" local scriptype=\$1 shift; if [ -z \"\$scriptype\" ]; then scriptype=\"postscript\" fi if [ -f \$1 ]; then echo \"\`date\` Running \$scriptype: \$1\" msgutil_r \"\$MASTER_IP\" \"info\" "\"\`date\` Running \$scriptype: \$1\"" \"\$logfile\" if [ \"\$XCATDEBUGMODE\" = \"1\" ] || [ \"\$XCATDEBUGMODE\" = \"2\" ]; then local compt=\$(file \$1) local reg=\"shell script\" if [[ \"\$compt\" =~ \$reg ]]; then bash -x ./\$@ 2>&1 | tee -a \$logfile | tee >(logger -t xcat -p debug) ret_local=\${PIPESTATUS[0]} else ./\$@ 2>&1 | tee -a \$logfile | logger -t xcat -p debug ret_local=\${PIPESTATUS[0]} fi else ./\$@ 2>&1 | tee -a \$logfile ret_local=\${PIPESTATUS[0]} fi if [ \"\$ret_local\" -ne \"0\" ]; then return_value=\$ret_local fi echo \"\$scriptype: \$1 exited with code \$ret_local\" msgutil_r \"\$MASTER_IP\" \"info\" "\"\`date\` \$scriptype \$1 return with \$ret_local\"" \"\$logfile\" else echo \"\`date\` \$scriptype \$1 does NOT exist.\" msgutil_r \"\$MASTER_IP\" \"info\" "\"\`date\` \$scriptype \$1 does NOT exist.\"" \"\$logfile\" return_value=-1 fi return 0 } # subroutine end " > /$xcatpost/mypostscript echo "$TMP" >> /$xcatpost/mypostscript if [ "$MODE" = "1" ] || [ "$MODE" = "2" ] || [ "$MODE" = "3" ] || [ "$MODE" = "5" ]; then TMP=`sed "/# postbootscripts-start-here/,/# postbootscripts-end-here/ s/\(.*\)/run_ps postscript \1/;s/run_ps postscript\s*#/#/;s/run_ps postscript\s*$//" /$xcatpost/mypostscript` else TMP=`sed "/# postbootscripts-start-here/,/# postbootscripts-end-here/ s/\(.*\)/run_ps postbootscript \1/;s/run_ps postbootscript\s*#/#/;s/run_ps postbootscript\s*$//" /$xcatpost/mypostscript` fi echo "$TMP" > /$xcatpost/mypostscript if [ $NODE_DEPLOYMENT -eq 1 ] || [ "$MODE" = "4" ] || [ "$MODE" = "6" ]; then #notify the server that we are done with netbooting CNS=`grep NODESTATUS= /$xcatpost/mypostscript |awk -F = '{print $2}' | tr -d \'\" | tr A-Z a-z` if [ -z "$CNS" ] || [[ "$CNS" =~ ^(1|yes|y)$ ]]; then # TMP=`sed "/postscripts-start-here/ i\updateflag.awk \\$MASTER 3002 \\"installstatus configuring\\"" /$xcatpost/mypostscript` # echo "$TMP"> /$xcatpost/mypostscript if [ "$MODE" = "6" ]; then echo " if [ \"\$return_value\" -eq \"0\" ]; then msgutil_r \$MASTER_IP \"debug\" \"node booted successfully,reporting status...\" \"/var/log/xcat/xcat.log\" updateflag.awk \$MASTER 3002 \"installstatus booted\" else msgutil_r \$MASTER_IP \"debug\" \"node boot failed,reporting status...\" \"/var/log/xcat/xcat.log\" updateflag.awk \$MASTER 3002 \"installstatus failed\" fi " >> /$xcatpost/mypostscript else echo " if [ \"\$return_value\" -eq \"0\" ]; then msgutil_r \$MASTER_IP \"debug\" \"node booted successfully,reporting status...\" \"/var/log/xcat/xcat.log\" updateflag.awk \$MASTER 3002 \"installstatus booted\" msgutil_r \$MASTER_IP \"info\" \"provision completed.(\$NODE)\" \"/var/log/xcat/xcat.log\" else msgutil_r \$MASTER_IP \"debug\" \"node boot failed,reporting status...\" \"/var/log/xcat/xcat.log\" updateflag.awk \$MASTER 3002 \"installstatus failed\" fi " >> /$xcatpost/mypostscript fi fi fi DHCP_TMP=`sed 's/\(DHCPINTERFACES=\)\(.*\)$/\1"\2"/' /$xcatpost/mypostscript` echo "$DHCP_TMP" > /$xcatpost/mypostscript CLEANUPXCATPOST=`grep CLEANUPXCATPOST= /$xcatpost/mypostscript |awk -F = '{print $2}' | tr -d \'\" | tr A-Z a-z` if [[ "$CLEANUPXCATPOST" =~ ^(1|yes|y)$ ]]; then echo "cd /" >> /$xcatpost/mypostscript # /xcatpost might be read-only for statelite nodes echo "rm -rf /$xcatpost/*" >> /$xcatpost/mypostscript fi if [ "$MODE" = "1" ] || [ "$MODE" = "2" ] || [ "$MODE" = "5" ]; then echo "exit \$return_value" >> /$xcatpost/mypostscript fi chmod 700 /$xcatpost/mypostscript if [ -x /$xcatpost/mypostscript ];then echolog "debug" "running /$xcatpost/mypostscript" /$xcatpost/mypostscript VRET_POST=$? echolog "debug" "/$xcatpost/mypostscript return with $VRET_POST" fi #tell user it is done when this is called by updatenode command if [ "$MODE" = "1" ] || [ "$MODE" = "2" ] || [ "$MODE" = "5" ]; then echolog "info" "returned from postscript" fi exit $VRET_POST EOF chmod 755 /opt/xcat/xcatdsklspost if [ ! -x /opt/xcat/xcatdsklspost ]; then if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "failed to generate /opt/xcat/xcatdsklspost" "/var/log/xcat/xcat.log" fi else if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "/opt/xcat/xcatdsklspost generated" "/var/log/xcat/xcat.log" fi fi #create the preboot script and run here TMP=`sed "/^#\s*postbootscripts-start-here/,/^#\s*postbootscripts-end-here/ d" /xcatpost/mypostscript` echo "$TMP" > /xcatpost/mypostscript echo " #save bad return code to /opt/xcat/xcatinfo if [ \"\$return_value\" -ne \"0\" ]; then grep 'POSTSCRIPTS_RC' /opt/xcat/xcatinfo > /dev/null 2>&1 if [ \$? -eq 0 ]; then sed -i \"s/POSTSCRIPTS_RC=.*/POSTSCRIPTS_RC=1/\" /opt/xcat/xcatinfo else echo \"POSTSCRIPTS_RC=1\" >> /opt/xcat/xcatinfo fi fi " >> /xcatpost/mypostscript chmod 700 /xcatpost/mypostscript export ARCH=x86_64 export CONSOLEPORT=0 #for redhat: #place-holder for the code to save the repo info on compute node,pointing to the "pkgdir" of the osimage #so that the provisioned node has the repo pointed to the distro path on MN cat >/etc/yum.repos.d/local-repository-0.repo << 'EOF' [local-rhels6.5-x86_64--install-rhels6.5-x86_64] name=xCAT configured yum repository for /install/rhels6.5/x86_64 baseurl=http://xcat//install/rhels6.5/x86_64 enabled=1 gpgcheck=0 [local-rhels6.5-x86_64--install-rhels6.5-x86_64-Server] name=xCAT configured yum repository for /install/rhels6.5/x86_64/Server baseurl=http://xcat//install/rhels6.5/x86_64/Server enabled=1 gpgcheck=0 [local-rhels6.5-x86_64--install-rhels6.5-x86_64-ScalableFileSystem] name=xCAT configured yum repository for /install/rhels6.5/x86_64/ScalableFileSystem baseurl=http://xcat//install/rhels6.5/x86_64/ScalableFileSystem enabled=1 gpgcheck=0 [local-rhels6.5-x86_64--install-rhels6.5-x86_64-ResilientStorage] name=xCAT configured yum repository for /install/rhels6.5/x86_64/ResilientStorage baseurl=http://xcat//install/rhels6.5/x86_64/ResilientStorage enabled=1 gpgcheck=0 [local-rhels6.5-x86_64--install-rhels6.5-x86_64-LoadBalancer] name=xCAT configured yum repository for /install/rhels6.5/x86_64/LoadBalancer baseurl=http://xcat//install/rhels6.5/x86_64/LoadBalancer enabled=1 gpgcheck=0 [local-rhels6.5-x86_64--install-rhels6.5-x86_64-HighAvailability] name=xCAT configured yum repository for /install/rhels6.5/x86_64/HighAvailability baseurl=http://xcat//install/rhels6.5/x86_64/HighAvailability enabled=1 gpgcheck=0 EOF if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "info" "running mypostscript" "/var/log/xcat/xcat.log" fi /xcatpost/mypostscript if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "info" "mypostscript returned" "/var/log/xcat/xcat.log" fi if [[ $OSVER == ubuntu* ]]; then if [[ -r /boot/grub/menu.lst ]]; then sed -i 's/^serial/#serial/' /boot/grub/menu.lst sed -i 's/^terminal/#terminal/' /boot/grub/menu.lst elif [[ -r /boot/grub/grub.cfg ]] ; then update-grub fi #print the kernel messages and service start messages with systemd on the console during system bootup [ -f /etc/default/grub ] && sed -i -e '/GRUB_CMDLINE_LINUX_DEFAULT=/s/quiet//;s/splash//' -e '/#GRUB_TERMINAL=/s/#//' -e 's/#GRUB_GFXMODE=.*/GRUB_GFXMODE=text/' /etc/default/grub && update-grub if echo "$ARCH" | grep -i 'x86_64'; then #grab the install-time console configuration from /proc/cmdline inside os installer CONSOLECFG=$(awk 'BEGIN{RS="[ \n]" ;ORS=" "} $0 ~ /^console=/{print $0}' /proc/cmdline) #if the console configuration is not applied to the grub configuration,apply it cat /boot/grub/grub.cfg |grep "$CONSOLECFG" >/dev/null 2>&1 || ([ -f /etc/default/grub ] && sed -i -e "/GRUB_CMDLINE_LINUX_DEFAULT=/s/=\"/=\" $CONSOLECFG /" /etc/default/grub && update-grub) fi if echo "$ARCH" | grep -i 'ppc64'; then if [ -z "$CONSOLEPORT" ] ; then export CONSOLEPORT=0 fi CONSOLE="hvc$CONSOLEPORT" if [[ -r /etc/default/grub ]] ; then sed -i "s/GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT=\"console=$CONSOLE\"/" /etc/default/grub else echo "GRUB_CMDLINE_LINUX_DEFAULT=\"console=$CONSOLE\"" > /etc/default/grub fi update-grub cat >/etc/init/$CONSOLE\.conf << 'EOF' start on stopped rc RUNLEVEL=[2345] and ( not-container or container CONTAINER=lxc or container CONTAINER=lxc-libvirt) stop on runlevel [!2345] respawn #exec /sbin/getty -L 115200 hvc0 vt102 script for i in `cat /proc/cmdline`; do KEY=`echo $i|cut -d= -f 1` if [ "$KEY" == "console" -a "$i" != "console=tty0" ]; then VALUE=`echo $i | awk -F= '{print $2}'` COTTY=`echo $VALUE|awk -F, '{print $1}'` COSPEED=`echo $VALUE|awk -F, '{print $2}'|awk -Fn '{print $1}'` break fi done exec /sbin/getty -L $COSPEED $COTTY vt102 end script EOF fi sed -i '/127.0.1.1/d' /etc/hosts else [ -f /boot/grub/grub.conf ] && sed -i 's/^serial/#serial/' /boot/grub/grub.conf [ -f /boot/grub/grub.conf ] && sed -i 's/^terminal/#terminal/' /boot/grub/grub.conf if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "debug" "/boot/grub/grub.conf updated" "/var/log/xcat/xcat.log" fi fi if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then msgutil_r "$MASTER_IP" "info" "finished node installation, reporting status..." "/var/log/xcat/xcat.log" fi #the following command should always be run to prevent infinite installation loops updateflag.awk $MASTER 3002 cd / # fix the issue#929@github, the "service network restart" in # makes the 'network' service in start status, then it causes the # services YaST2-Second-Stage.service and xcatpostinit1 services to be run in parallel. # But the YaST2-Second-Stage.service calls the Yast2 which conflics with the zypper # which is called in xcatpostinit1->otherpkgs. # The correct services start order is 'YaST2-Second-Stage.service'->'network'->'xcatpostinit1' in serial. # To skip the conflict, the network service should be stoped in the yast first stage. Then base on the service # dependency, the service start order will be 'YaST2-Second-Stage.service'->'network'->'xcatpostinit1' in serial. # Then the Yast2 will be stopped before running the zypper in otherpkgs. if [[ $OSVER =~ sles && $OSVER != sles11* ]]; then service network stop fi if [ "$XCATDEBUGMODE" = "1" ] || [ "$XCATDEBUGMODE" = "2" ]; then set +x fi exit 0 } >>/var/log/xcat/xcat.log 2>&1 %end