diff --git a/xCAT-server/lib/perl/xCAT/Postage.pm b/xCAT-server/lib/perl/xCAT/Postage.pm index 0755f5bfc..b9ba53cac 100644 --- a/xCAT-server/lib/perl/xCAT/Postage.pm +++ b/xCAT-server/lib/perl/xCAT/Postage.pm @@ -106,6 +106,7 @@ sub create_mypostscript_or_not { } + #----------------------------------------------------------------------------- =head3 makescript @@ -338,6 +339,8 @@ sub makescript { } } + + #Some of the strings are same to all the nodes. #So move the string substitutions outside the loop $t_inc =~ s/#SITE_TABLE_ALL_ATTRIBS_EXPORT#/$allattribsfromsitetable/eg; @@ -525,10 +528,18 @@ sub makescript { $macaddress = xCAT::Utils->parseMacTabEntry($macmac, $node); } + + my ($host, $ipaddr) = xCAT::NetworkUtils->gethostnameandip($master); + my $master_ip; + if($ipaddr){ + $master_ip="$ipaddr"; + } + #ok, now do everything else.. #$inc =~ s/#XCATVAR:([^#]+)#/envvar($1)/eg; - #$inc =~ s/#ENV:([^#]+)#/envvar($1)/eg; + #$inc =~ s/#ENV:([^#]+)#/xCAT::Template::envvar($1)/eg; #$inc =~ s/#NODE#/$node/eg; + $inc =~ s/#MASTER_IP_ADDR#/$master_ip/eg; $inc =~ s/\$NODE/$node/eg; #$inc =~ s/#TABLE:([^:]+):([^:]+):([^:]+):BLANKOKAY#/tabdb($1,$2,$3,1)/eg; $inc =~ s/#TABLE:([^:]+):([^:]+):([^#]+)#/xCAT::Template::tabdb($1,$2,$3)/eg; diff --git a/xCAT-server/lib/perl/xCAT/Template.pm b/xCAT-server/lib/perl/xCAT/Template.pm index 0c05cf84c..dd82b9e32 100644 --- a/xCAT-server/lib/perl/xCAT/Template.pm +++ b/xCAT-server/lib/perl/xCAT/Template.pm @@ -96,6 +96,11 @@ sub subvars { } $ENV{XCATMASTER}=$master; + my ($host, $ipaddr) = xCAT::NetworkUtils->gethostnameandip($master); + if($ipaddr){ + $ENV{MASTER_IP}="$ipaddr"; + } + my @nodestatus = xCAT::TableUtils->get_site_attribute("nodestatus"); my $tmp=$nodestatus[0]; if( defined($tmp) ){ @@ -1459,6 +1464,7 @@ sub command sub envvar { + my $envvar = shift; if($envvar =~ /^\$/) { @@ -1496,7 +1502,6 @@ sub tabdb my $field = shift; my $blankok = shift; - if( %::GLOBAL_TAB_HASH && defined( $::GLOBAL_TAB_HASH{$table} ) ) { if( !defined( $::GLOBAL_TAB_HASH{$table}{$key}) ) { return "''"; diff --git a/xCAT-server/lib/xcat/plugins/anaconda.pm b/xCAT-server/lib/xcat/plugins/anaconda.pm index e5ac5122c..2dccff4b4 100755 --- a/xCAT-server/lib/xcat/plugins/anaconda.pm +++ b/xCAT-server/lib/xcat/plugins/anaconda.pm @@ -745,6 +745,16 @@ sub mknetboot $kcmdline .= " nonodestatus "; } + if($::XCATSITEVALS{xcatdebugmode} eq "1"){ + + my ($host, $ipaddr) = xCAT::NetworkUtils->gethostnameandip($xcatmaster); + if($ipaddr){ + $kcmdline .=" LOGSERVER=$ipaddr "; + } + + $kcmdline .= " xcatdebugmode=1 "; + } + # Add kernel parameters to specify the boot network interface my $installnic; my $primarynic; @@ -1481,7 +1491,6 @@ sub mkinstall } if($::XCATSITEVALS{xcatdebugmode} eq "1"){ - unless($instserver eq '!myipfn!'){ my($host,$ip)=xCAT::NetworkUtils->gethostnameandip($instserver); $instserver=$ip; diff --git a/xCAT-server/share/xcat/install/scripts/post.rh.common b/xCAT-server/share/xcat/install/scripts/post.rh.common index 54dd3af5e..deaccae05 100644 --- a/xCAT-server/share/xcat/install/scripts/post.rh.common +++ b/xCAT-server/share/xcat/install/scripts/post.rh.common @@ -3,6 +3,9 @@ # echo "post scripts" >/root/post.log +[ $XCATDEBUGMODE ] || export XCATDEBUGMODE="#TABLEBLANKOKAY:site:key=xcatdebugmode:value#" +[ $MASTER_IP ] || export MASTER_IP="#ENV:MASTER_IP#" +#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/scriptlib# export PRINIC=#TABLEBLANKOKAY:noderes:THISNODE:primarynic# if [ "$PRINIC" == "mac" ] @@ -34,6 +37,7 @@ elif [[ `echo "$PRINIC" | grep -sqE ^[A-Fa-f0-9]+:[A-Fa-f0-9]+:[A-Fa-f0-9]+:[A-F #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 addr show dev $PRINIC | grep inet | grep -v inet6 | awk '{print $2}' | head -n 1 | awk -F '/' '{print $1}') if [ -z $IP ] @@ -44,6 +48,11 @@ then fi export HOSTNAME=$(host $IP 2>/dev/null | awk '{print $5}' | awk -F. '{print $1}') + +if [ "$XCATDEBUGMODE" > "0" ]; 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... diff --git a/xCAT-server/share/xcat/install/scripts/post.rhels7 b/xCAT-server/share/xcat/install/scripts/post.rhels7 index fc3ab7285..6d7d018a4 100644 --- a/xCAT-server/share/xcat/install/scripts/post.rhels7 +++ b/xCAT-server/share/xcat/install/scripts/post.rhels7 @@ -1,9 +1,18 @@ #the nic name might change between the installation and 1st boot #active all the nics with network link during system boot + + +[ $XCATDEBUGMODE ] || export XCATDEBUGMODE="#TABLEBLANKOKAY:site:key=xcatdebugmode:value#" +[ $MASTER_IP ] || export MASTER_IP="#ENV:MASTER_IP#" +#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/scriptlib# + for i in $(find /etc/sysconfig/network-scripts/ifcfg-*|egrep -v ifcfg-lo ) do nicname=$(echo $i|awk -F 'ifcfg-' '{print $2}') if ethtool $nicname|grep -E -i "Link detected.*yes" >/dev/null 2>&1 + if [ "$XCATDEBUGMODE" > "0" ]; then + msgutil_r "$MASTER_IP" "info" "set NIC $nicname to be activated on system boot" "/var/log/xcat/xcat.log" + fi then sed -i 's/ONBOOT=no/ONBOOT=yes/' $i fi @@ -11,4 +20,3 @@ do #nic name change during the install and first_reboot sed -i '/HWADDR/d' $i done - diff --git a/xCAT-server/share/xcat/install/scripts/post.sles.common b/xCAT-server/share/xcat/install/scripts/post.sles.common index f7f17a2dd..6c443c3eb 100755 --- a/xCAT-server/share/xcat/install/scripts/post.sles.common +++ b/xCAT-server/share/xcat/install/scripts/post.sles.common @@ -1,4 +1,10 @@ #!/bin/sh + + +export XCATDEBUGMODE="#TABLEBLANKOKAY:site:key=xcatdebugmode:value#" +export MASTER_IP="#ENV:MASTER_IP#" +#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/scriptlib# + export MANAGEDADDRESSMODE=#MANAGEDADDRESSMODE# cd /etc/sysconfig/network @@ -52,5 +58,8 @@ echo "Slept $jsi seconds before hostname made sense." HOSTNAME=$(hostname -s) echo $HOSTNAME +if [ "$XCATDEBUGMODE" > "0" ]; then + msgutil_r "$MASTER_IP" "debug" "PRINIC=$PRINIC,HOSTNAME=$HOSTNAME" "/var/log/xcat/xcat.log" +fi /sbin/portmap diff --git a/xCAT-server/share/xcat/install/scripts/post.ubuntu b/xCAT-server/share/xcat/install/scripts/post.ubuntu index a8f86af22..d158cdeae 100755 --- a/xCAT-server/share/xcat/install/scripts/post.ubuntu +++ b/xCAT-server/share/xcat/install/scripts/post.ubuntu @@ -2,7 +2,13 @@ # # Setup hostname # + echo "post scripts" >/root/post.log + +[ $XCATDEBUGMODE ] || export XCATDEBUGMODE="#TABLEBLANKOKAY:site:key=xcatdebugmode:value#" +[ $MASTER_IP ] || export MASTER_IP="#ENV:MASTER_IP#" +#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/scriptlib# + export PRINIC=#TABLEBLANKOKAY:noderes:THISNODE:primarynic# if [ "$PRINIC" == "mac" ] then @@ -23,6 +29,17 @@ then #IP=$(ifconfig $PRINIC | grep inet | awk '{print $2}' | awk -F: '{print $2}') IP=$(ip addr show dev $PRINIC | grep inet | grep -v inet6 | awk '{print $2}' | head -n 1 | awk -F '/' '{print $1}') fi + +if [ "$XCATDEBUGMODE" > "0" ]; then + msgutil_r "$MASTER_IP" "debug" "PRINIC=$PRINIC,IP=$IP" "/var/log/xcat/xcat.log" +fi + + + +if [ "$XCATDEBUGMODE" > "0" ]; then + msgutil_r "$MASTER_IP" "debug" "generating /etc/resolv.conf" "/var/log/xcat/xcat.log" +fi + echo "search #TABLE:site:key=domain:value#" >/etc/resolv.conf for i in $(echo #TABLE:site:key=nameservers:value# | tr ',' ' ') do @@ -35,7 +52,7 @@ ln -sf /bin/bash /bin/sh #sed -i 's/^deb.*updates.*$/#&/g' /etc/apt/sources.list # Run xCAT post install # -export MASTER_IP="#XCATVAR:XCATMASTER#" +export MASTER_IP="#ENV:MASTER_IP#" export MASTER_IPS="#XCATVAR:XCATMASTER#" export MASTER="#XCATVAR:XCATMASTER#" export INSTALLDIR=#TABLE:site:key=installdir:value# @@ -50,43 +67,55 @@ do GOTIT=0 for i in $MASTER_IPS do + + if [ "$XCATDEBUGMODE" > "0" ]; then + msgutil_r "$MASTER_IP" "debug" "downloading postscripts from http://$i$INSTALLDIR/postscripts/" "/var/log/xcat/xcat.log" + 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 0 -T 60 http://$i$INSTALLDIR/postscripts/ -P /xcatpost #wget --wait=10 --random-wait --waitretry=10 --retry-connrefused -t 0 -T 60 http://$i/install/autoinst/xcatpost.tar.gz if [ "$?" = "0" ] then - if [ ! -x /usr/bin/openssl ]; then #Stop if no openssl to help the next bit - exit 1 - 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=$i:3001 - export XCATSERVER - mv $i/postscripts /xcatpost - rm -rf $i - # 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)$'` - /xcatpost/getpostscript.awk |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 - RETRY=$(($RETRY+1)) - if [ $RETRY -eq $MAX_RETRIES ] - then - break - fi + if [ ! -x /usr/bin/openssl ]; then #Stop if no openssl to help the next bit + if [ "$XCATDEBUGMODE" > "0" ]; then + msgutil_r "$MASTER_IP" "debug" "/usr/bin/openssl does not exist,exit..." "/var/log/xcat/xcat.log" + fi + exit 1 + 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=$i:3001 + export XCATSERVER + mv $i/postscripts /xcatpost + rm -rf $i + # 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)$'` + + if [ "$XCATDEBUGMODE" > "0" ]; then + msgutil_r "$MASTER_IP" "debug" "trying to get mypostscript with getpostscript.awk" "/var/log/xcat/xcat.log" + fi + /xcatpost/getpostscript.awk |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 + RETRY=$(($RETRY+1)) + if [ $RETRY -eq $MAX_RETRIES ] + then + break + fi - let SLI=$RANDOM%10+10 - sleep $SLI - /xcatpost/getpostscript.awk |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 + let SLI=$RANDOM%10+10 + sleep $SLI + /xcatpost/getpostscript.awk |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 - - chmod +x /xcatpost/mypostscript - GOTIT=1 - break + + chmod +x /xcatpost/mypostscript + GOTIT=1 + break fi done if [ "$GOTIT" = "1" ] @@ -116,29 +145,33 @@ export PATH=$PATH:/xcatpost # use the run_ps subroutine to run the postscripts TMP=`sed "/postscripts-start-here/,/postscripts-end-here/ s/\(.*\)/run_ps \1/;s/run_ps\s*#/#/;s/run_ps\s*$//" /xcatpost/mypostscript` echo " +. /xcatpost/xcatlib.sh + +# global value to store the running status of the postbootscripts,the value is non-zero if one postbootscript fa +iled return_value=0 # subroutine used to run postscripts run_ps () { - logdir=\"/var/log/xcat\" - mkdir -p \$logdir - logfile=\"/var/log/xcat/xcat.log\" - - if [ -f \$1 ]; then - echo "\"\`date\` Running postscript: \$@\"" | tee -a \$logfile - #./\$@ 2>&1 1> /tmp/tmp4xcatlog - #cat /tmp/tmp4xcatlog | tee -a \$logfile - ./\$@ 2>&1 | tee -a \$logfile + local ret_local=0 + local logfile=\"/var/log/xcat/xcat.log\" + + if [ -f \$1 ]; then + msgutil_r \"\$MASTER_IP\" \"info\" "\"\`date\` Running postscript: \$@\"" \"\$logfile\" + bash -x ./\$@ 2>&1 | tee -a \$logfile ret_local=\${PIPESTATUS[0]} + msgutil_r \"\$MASTER_IP\" \"info\" "\"\`date\` postscript \$@ return with \$ret_local\"" \"\$logfile\" if [ \"\$ret_local\" -ne \"0\" ]; then - return_value=\$ret_local + return_value=\$ret_local fi + else - echo "\"\`date\` Postscript \$1 does NOT exist.\"" | tee -a \$logfile - return_value=-1 + msgutil_r \"\$MASTER_IP\" \"info\" "\"\`date\` Postscript \$1 does NOT exist.\"" \"\$logfile\" + return_value=-1 fi + + return 0 } # subroutine end - " > /xcatpost/mypostscript echo "$TMP" >> /xcatpost/mypostscript TMP=`sed "/postbootscripts-start-here/,/postbootscripts-end-here/ s/\(.*\)/run_ps \1/;s/run_ps\s*#/#/;s/run_ps\s*$//" /xcatpost/mypostscript` @@ -163,9 +196,10 @@ if [ -f /xcatpost/mypostscript.post ]; then RUNBOOTSCRIPTS=`grep 'RUNBOOTSCRIPTS=' /xcatpost/mypostscript.post |cut -d= -f2` fi if [ "$RUNBOOTSCRIPTS" != "'yes'" ]; then + msgutil_r "$MASTER_IP" "debug" "update-rc.d -f xcatpostinit1 remove" "/var/log/xcat/xcat.log" update-rc.d -f xcatpostinit1 remove fi -echo "REBOOT=TRUE" >> /opt/xcat/xcatinf +echo "REBOOT=TRUE" >> /opt/xcat/xcatinfo EOF chmod 755 /opt/xcat/xcatinstallpost @@ -181,7 +215,14 @@ chmod 755 /opt/xcat/xcatdsklspost TMP=`sed "/postbootscripts-start-here/,/postbootscripts-end-here/ d" /xcatpost/mypostscript` echo "$TMP" > /xcatpost/mypostscript +if [ "$XCATDEBUGMODE" > "0" ]; then + msgutil_r "$MASTER_IP" "debug" "running mypostscript" "/var/log/xcat/xcat.log" +fi /xcatpost/mypostscript +if [ "$XCATDEBUGMODE" > "0" ]; then + msgutil_r "$MASTER_IP" "debug" "mypostscript return" "/var/log/xcat/xcat.log" +fi + export NODE=#TABLE:nodelist:THISNODE:node# export OSVER=#TABLE:nodetype:THISNODE:os# export ARCH=#TABLE:nodetype:THISNODE:arch# @@ -235,6 +276,10 @@ fi #sed -i 's/^\(\s*deb-src.*install.*\)$/#\1/g' /etc/apt/sources.list #delete the 127.0.1.1 line from /etc/hosts sed -i '/127.0.1.1/d' /etc/hosts + +if [ "$XCATDEBUGMODE" > "0" ]; then + msgutil_r "$MASTER_IP" "debug" "installation finished, reporting status..." "/var/log/xcat/xcat.log" +fi updateflag.awk $MASTER 3002 cd / #rm -Rf /xcatpost diff --git a/xCAT-server/share/xcat/install/scripts/post.xcat b/xCAT-server/share/xcat/install/scripts/post.xcat index 8db67f756..1b7fe568f 100755 --- a/xCAT-server/share/xcat/install/scripts/post.xcat +++ b/xCAT-server/share/xcat/install/scripts/post.xcat @@ -1,12 +1,17 @@ # # Run xCAT post install # -export MASTER_IP="#XCATVAR:XCATMASTER#" +export MASTER_IP="#ENV:MASTER_IP#" export MASTER_IPS="#XCATVAR:XCATMASTER#" export MASTER="#XCATVAR:XCATMASTER#" export NODESTATUS="#XCATVAR:NODESTATUS#" export INSTALLDIR=#TABLE:site:key=installdir:value# export TFTPDIR=#TABLE:site:key=tftpdir:value# +export XCATDEBUGMODE="#TABLEBLANKOKAY:site:key=xcatdebugmode:value#" + +#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/scriptlib# + + if [ -z "$INSTALLDIR" ]; then INSTALLDIR="/install" fi @@ -17,61 +22,84 @@ fi cd /tmp RAND=$(perl -e 'print int(rand(50)). "\n"') + +if [ "$XCATDEBUGMODE" > "0" ]; then + msgutil_r "$MASTER_IP" "debug" "sleep $RAND" "/var/log/xcat/xcat.log" +fi sleep $RAND + for t in $(seq 1 20) do GOTIT=0 for i in $MASTER_IPS do - wget -l inf -N -r --waitretry=10 --random-wait --retry-connrefused -e robots=off -nH --cut-dirs=2 --reject "index.html*" --no-parent -t 0 -T 60 http://$i$INSTALLDIR/postscripts/ -P /xcatpost - if [ "$?" = "0" ] - then - rm -rf /xcatpost/mypostscript - export NODE=#TABLE:nodelist:THISNODE:node# - wget -N --waitretry=10 --random-wait -T 60 http://$i$TFTPDIR/mypostscripts/mypostscript.$NODE -P /xcatpost 2> /tmp/wget.log - mv /xcatpost/mypostscript.$NODE /xcatpost/mypostscript + if [ "$XCATDEBUGMODE" > "0" ]; then + msgutil_r "$MASTER_IP" "debug" "downloading postscripts from http://$i$INSTALLDIR/postscripts/" "/var/log/xcat/xcat.log" + 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 0 -T 60 http://$i$INSTALLDIR/postscripts/ -P /xcatpost + if [ "$?" = "0" ] + then + if [ "$XCATDEBUGMODE" > "0" ]; then + msgutil_r "$MASTER_IP" "debug" "postscripts downloaded successfully" "/var/log/xcat/xcat.log" + fi - if [ ! -x /usr/bin/openssl ]; then #Stop if no openssl to help the next bit - exit 1 - 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=$i:3001 - export XCATSERVER - # If mypostscript doesn't exist, we will get it through getpostscript.awk - if [ ! -x /xcatpost/mypostscript ]; then + rm -rf /xcatpost/mypostscript + export NODE=#TABLE:nodelist:THISNODE:node# + if [ "$XCATDEBUGMODE" > "0" ]; then + msgutil_r "$MASTER_IP" "debug" "trying to download precreated mypostscript file http://$i$TFTPDIR/mypostscripts/mypostscript.$NODE" "/var/log/xcat/xcat.log" + fi + wget -N --waitretry=10 --random-wait -T 60 http://$i$TFTPDIR/mypostscripts/mypostscript.$NODE -P /xcatpost 2> /tmp/wget.log + mv /xcatpost/mypostscript.$NODE /xcatpost/mypostscript - # 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)$'` - /xcatpost/getpostscript.awk |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 - RETRY=$(($RETRY+1)) - if [ $RETRY -eq $MAX_RETRIES ] - then - break - fi + if [ ! -x /usr/bin/openssl ]; then #Stop if no openssl to help the next bit + if [ "$XCATDEBUGMODE" > "0" ]; then + msgutil_r "$MASTER_IP" "err" "/usr/bin/openssl does not exist,exit ..." "/var/log/xcat/xcat.log" + fi + exit 1 + 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=$i:3001 + export XCATSERVER - let SLI=$RANDOM%10+10 - sleep $SLI - /xcatpost/getpostscript.awk |sed -e 's/<[^>]*>//g'|egrep -v '^ *$'|sed -e 's/^ *//' | sed -e 's/<//g' -e 's/&/\&/g' -e 's/"/"/g' -e "s/'/'/g" > /xcatpost/mypostscript + # If mypostscript doesn't exist, we will get it through getpostscript.awk + if [ ! -x /xcatpost/mypostscript ]; then + if [ "$XCATDEBUGMODE" > "0" ]; then + msgutil_r "$MASTER_IP" "info" "failed to download precreated mypostscript, trying to generate with getpostscript.awk" "/var/log/xcat/xcat.log" + fi - MYCONT=`grep MASTER /xcatpost/mypostscript` - done + # 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)$'` + /xcatpost/getpostscript.awk |sed -e 's/<[^>]*>//g'|egrep -v '^ *$'|sed -e 's/^ *//' | sed -e 's/<//g' -e 's/&/\&/g' -e 's/"/"/g' -e "s/'/'/g" > /xcatpost/mypostscript + - fi - - chmod +x /xcatpost/mypostscript - GOTIT=1 - break - fi + MYCONT=`grep MASTER /xcatpost/mypostscript` + MAX_RETRIES=10 + RETRY=0 + while [ -z "$MYCONT" ]; do + RETRY=$(($RETRY+1)) + if [ $RETRY -eq $MAX_RETRIES ] + then + break + fi + + let SLI=$RANDOM%10+10 + sleep $SLI + /xcatpost/getpostscript.awk |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 + + chmod +x /xcatpost/mypostscript + GOTIT=1 + break + fi done if [ "$GOTIT" = "1" ] then @@ -87,6 +115,9 @@ do sleep $RAND done echo "INSTALLDIR=$INSTALLDIR" >> /opt/xcat/xcatinfo +if [ "$XCATDEBUGMODE" > "0" ]; then + msgutil_r "$MASTER_IP" "debug" "/opt/xcat/xcatinfo generated" "/var/log/xcat/xcat.log" +fi #echo "REBOOT=TRUE" >> /opt/xcat/xcatinfo cd /xcatpost @@ -98,29 +129,35 @@ export PATH=$PATH:/xcatpost # use the run_ps subroutine to run the postscripts TMP=`sed "/^#\s*postscripts-start-here/,/^#\s*postscripts-end-here/ s/\(.*\)/run_ps \1/;s/run_ps\s*#/#/;s/run_ps\s*$//" /xcatpost/mypostscript` 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 run_ps () { local ret_local=0 - logdir=\"/var/log/xcat\" - mkdir -p \$logdir - logfile=\"/var/log/xcat/xcat.log\" - - if [ -f \$1 ]; then - echo "\"\`date\` Running postscript: \$@\"" | tee -a \$logfile - #./\$@ 2>&1 1> /tmp/tmp4xcatlog - #cat /tmp/tmp4xcatlog | tee -a \$logfile - ./\$@ 2>&1 | tee -a \$logfile - ret_local=\${PIPESTATUS[0]} + local logfile=\"/var/log/xcat/xcat.log\" + + if [ -f \$1 ]; then + msgutil_r \"\$MASTER_IP\" \"info\" "\"\`date\` Running postscript: \$@\"" \"\$logfile\" + if [ \"\$XCATDEBUGMODE\" = \"1\" ]; then + bash -x ./\$@ 2>&1 | tee -a \$logfile + ret_local=\${PIPESTATUS[0]} + else + ./\$@ 2>&1 | tee -a \$logfile + ret_local=\${PIPESTATUS[0]} + fi + msgutil_r \"\$MASTER_IP\" \"info\" "\"\`date\` postscript \$@ return with \$ret_local\"" \"\$logfile\" if [ \"\$ret_local\" -ne \"0\" ]; then return_value=\$ret_local fi + else - echo "\"\`date\` Postscript \$1 does NOT exist.\"" | tee -a \$logfile + msgutil_r \"\$MASTER_IP\" \"info\" "\"\`date\` Postscript \$1 does NOT exist.\"" \"\$logfile\" return_value=-1 fi - + return 0 } # subroutine end @@ -135,7 +172,10 @@ echo "$TMP" > /xcatpost/mypostscript TMP=`sed "/^#\s*postscripts-start-here/,/^#\s*postscripts-end-here/ d" /xcatpost/mypostscript` echo "$TMP" > /xcatpost/mypostscript.post chmod 755 /xcatpost/mypostscript.post - +if [ "$XCATDEBUGMODE" > "0" ]; then + msgutil_r "$MASTER_IP" "debug" "mypostscript.post generated" "/var/log/xcat/xcat.log" +fi + #create the post init cat >/etc/init.d/xcatpostinit1 << 'EOF' #INCLUDE:#TABLE:site:key=installdir:value#/postscripts/xcatpostinit1# @@ -144,15 +184,23 @@ chmod 755 /etc/init.d/xcatpostinit1 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 + mkdir -p /opt/xcat cat >/opt/xcat/xcatinstallpost << 'EOF' + #INCLUDE:#TABLE:site:key=installdir:value#/postscripts/xcatinstallpost# + if [ -f /xcatpost/mypostscript.post ]; then RUNBOOTSCRIPTS=`grep 'RUNBOOTSCRIPTS=' /xcatpost/mypostscript.post |cut -d= -f2` fi + if [ "$RUNBOOTSCRIPTS" != "'yes'" ]; then chkconfig xcatpostinit1 off fi + +if [ "$XCATDEBUGMODE" > "0" ]; then + msgutil_r "$MASTER_IP" "debug" "service xcatpostinit1 disabled" "/var/log/xcat/xcat.log" +fi #echo "REBOOT=TRUE" >> /opt/xcat/xcatinfo EOF chmod 755 /opt/xcat/xcatinstallpost @@ -167,27 +215,53 @@ if [[ $OSVER == sles* ]]; then fi #chkconfig --add xcatpostinit1 chkconfig xcatpostinit1 on +if [ "$XCATDEBUGMODE" > "0" ]; then + msgutil_r "$MASTER_IP" "debug" "service xcatpostinit1 enabled" "/var/log/xcat/xcat.log" +fi #create the dskls post cat >/opt/xcat/xcatdsklspost << 'EOF' #INCLUDE:#TABLE:site:key=installdir:value#/postscripts/xcatdsklspost# EOF chmod 755 /opt/xcat/xcatdsklspost +if [ "$XCATDEBUGMODE" > "0" ]; then + msgutil_r "$MASTER_IP" "debug" "/opt/xcat/xcatdsklspost created" "/var/log/xcat/xcat.log" +fi #only run the prebooot scripts here TMP=`sed "/^#\s*postbootscripts-start-here/,/^#\s*postbootscripts-end-here/ d" /xcatpost/mypostscript` echo "$TMP" > /xcatpost/mypostscript +if [ "$XCATDEBUGMODE" > "0" ]; then + msgutil_r "$MASTER_IP" "debug" "mypostscript generated" "/var/log/xcat/xcat.log" +fi export NODE=#TABLE:nodelist:THISNODE:node# export ARCH=#TABLE:nodetype:THISNODE:arch# addsiteyum +if [ "$XCATDEBUGMODE" > "0" ]; then + msgutil_r "$MASTER_IP" "info" "running mypostscript" "/var/log/xcat/xcat.log" +fi /xcatpost/mypostscript +if [ "$XCATDEBUGMODE" > "0" ]; then + msgutil_r "$MASTER_IP" "info" "mypostscript returned" "/var/log/xcat/xcat.log" +fi + + sed -i 's/^serial/#serial/' /boot/grub/grub.conf sed -i 's/^terminal/#terminal/' /boot/grub/grub.conf +if [ "$XCATDEBUGMODE" > "0" ]; then + msgutil_r "$MASTER_IP" "debug" "/boot/grub/grub.conf updated" "/var/log/xcat/xcat.log" +fi + +if [ "$XCATDEBUGMODE" > "0" ]; 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 / #rm -Rf /xcatpost #rm -f /xcatpost/mypostscript + + diff --git a/xCAT-server/share/xcat/install/scripts/scriptlib b/xCAT-server/share/xcat/install/scripts/scriptlib new file mode 100644 index 000000000..e6bd8ba4c --- /dev/null +++ b/xCAT-server/share/xcat/install/scripts/scriptlib @@ -0,0 +1,29 @@ +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 + + logger -n $logserver -t xcat -p local4.$msgtype "$msgstr" + + if [ -n "$logfile" ]; then + local logdir="$(dirname $logfile)" + if [ ! -d "$logdir" ]; then + mkdir -p "$logdir" + touch "$logfile" + fi + + # echo "$msgstr" | tee -a $logfile + #else + echo "$msgstr" >> $logfile + fi + +} + +declare -F msgutil &>/dev/null || function msgutil { + msgutil_r "localhost" "$@" +} diff --git a/xCAT/postscripts/xcatdsklspost b/xCAT/postscripts/xcatdsklspost index a3808279c..986c17d87 100755 --- a/xCAT/postscripts/xcatdsklspost +++ b/xCAT/postscripts/xcatdsklspost @@ -19,11 +19,65 @@ # ##################################################### + +[ -f "/xcatpost/xcatlib.sh" ] && . /xcatpost/xcatlib.sh + + +if [ -f /xcatpost/mypostscript.post ]; then + XCATDEBUGMODE=`grep 'XCATDEBUGMODE=' /xcatpost/mypostscript.post |cut -d= -f2|sed s/\'//g` + 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}'` + fi + + if [ "$key" = "LOGSERVER" ]; then + MASTER_IP=`echo $param|awk -F= '{print $2}'` + fi + done +fi + + +#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 + + if [ "$msgtype" = "debug" ];then + if [ "$VERBOSE" = "1" ]; then + echo "$msgstr" + fi + if [ "$XCATDEBUGMODE" = "1" ]; 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 + +} + + + + + update_VPD() { if [ -f /usr/sbin/vpdupdate ]; then vpdupdate - logger -t xcat -p local4.info "xcatdsklspost: updating VPD database" + #logger -t xCAT -p local4.info "xcatdsklspost: updating VPD database" + echolog "info" "xcatdsklspost: updating VPD database" fi } @@ -52,6 +106,8 @@ download_postscripts() 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 @@ -69,14 +125,16 @@ download_postscripts() 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 + if [ $rc1 -eq 1 ] && [ $rc2 -eq 1 ]; then + echolog "debug" "$0 : download_postscripts return successfully " return 0 fi fi retry=$(($retry+1)) - logger -t xcat -p local4.err "download_postscripts retry $retry" + echolog "debug" "download_postscripts retry $retry" if [ $retry -eq $max_retries ]; then + echolog "debug" "$0 : download_postscripts failed" break fi @@ -103,18 +161,21 @@ download_mypostscript() 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 @@ -198,6 +259,9 @@ fi 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" @@ -272,9 +336,10 @@ if [ "$MODE" = "4" ]; then # for statelite mode 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..."; + #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 @@ -325,8 +390,9 @@ else # for common mode MODE=1,2,3,5 (updatenode,moncfg,node deployment) # 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." + #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 @@ -403,9 +469,12 @@ else # for common mode MODE=1,2,3,5 (updatenode,moncfg,node deployment) #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" - exit + #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 @@ -454,7 +523,7 @@ else node_short=`hostname -s` fi fi - + max_retries=2 # try short hostname first if [ -n "$node_short" ]; then @@ -498,14 +567,18 @@ fi # 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" + #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" + #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" + #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 @@ -531,12 +604,15 @@ if [ ! -x /$xcatpost/mypostscript ]; then if [ $useflowcontrol = "1" ]; then # contact daemon xcatflowrequest 3001 - logger -t xcat -p local4.info "xcatdsklspost: sending xcatflowrequest $SIP 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" + #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" + #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 @@ -739,6 +815,8 @@ fi # use the run_ps subroutine to run the postscripts TMP=`sed "/# postscripts-start-here/,/# postscripts-end-here/ s/\(.*\)/run_ps \1/;s/run_ps\s*#/#/;s/run_ps\s*$//" /$xcatpost/mypostscript` 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 @@ -749,15 +827,24 @@ run_ps () { logfile=\"/var/log/xcat/xcat.log\" if [ -f \$1 ]; then - echo \"\`date\` Running postscript: \$@\" | tee -a \$logfile - ./\$@ 2>&1 | tee -a \$logfile - ret_local=\${PIPESTATUS[0]} + echo \"\`date\` Running postscript: \$@\" + msgutil_r \$MASTER_IP \"debug\" \"\`date\` Running postscript: \$@\" \"\$logfile\" + if [ \"\$XCATDEBUGMODE\" = \"1\" ]; then + bash -x ./\$@ 2>&1 | tee -a \$logfile + ret_local=\${PIPESTATUS[0]} + else + ./\$@ 2>&1 | tee -a \$logfile + ret_local=\${PIPESTATUS[0]} + fi + if [ \"\$ret_local\" -ne \"0\" ]; then return_value=\$ret_local fi - echo \"Postscript: \$@ exited with code \$ret_local\" | tee -a \$logfile + echo \"Postscript: \$@ exited with code \$ret_local\" + msgutil_r \$MASTER_IP \"debug\" \"\`date\` Postscript: \$@ exited with code \$ret_local\" \"\$logfile\" else - echo \"\`date\` Postscript \$1 does NOT exist.\" | tee -a \$logfile + echo \"\`date\` Postscript \$1 does NOT exist.\" + msgutil_r \$MASTER_IP \"debug\" \"\`date\` Postscript: \$@ exited with code \$ret_local\" \"\$logfile\" return_value=-1 fi @@ -778,8 +865,10 @@ if [ $NODE_DEPLOYMENT -eq 1 ] || [ "$MODE" = "4" ] || [ "$MODE" = "6" ]; then # echo "$TMP"> /$xcatpost/mypostscript 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 @@ -804,13 +893,15 @@ fi chmod +x /$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 - echo "returned from postscript" + echolog "info" "returned from postscript" fi exit $VRET_POST diff --git a/xCAT/postscripts/xcatinstallpost b/xCAT/postscripts/xcatinstallpost index 47a2214ee..7ad5766c0 100755 --- a/xCAT/postscripts/xcatinstallpost +++ b/xCAT/postscripts/xcatinstallpost @@ -4,10 +4,16 @@ # # 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|sed s/\'//g` + MASTER_IP=`grep '^MASTER_IP=' /xcatpost/mypostscript.post |cut -d= -f2|sed s/\'//g` +fi + if [ ! `uname` = Linux ]; then - logger -t xcat -p local4.err "$0: the OS name is not Linux" + 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)}') @@ -23,9 +29,8 @@ do sleep 2 RETRY=$[ $RETRY + 1 ] if [ $RETRY -eq 90 ];then - logger -t xcat -p local4.err "Network not configured, please check..." - echo `date` "xcatinstallpost: Network not configured, please check..." >> /var/log/xcat/xcat.log - exit 1 + msgutil_r "$MASTER_IP" "err" `date`" xcatinstallpost: Network not configured, please check..." "/var/log/xcat/xcat.log" + exit 1 fi done @@ -64,9 +69,16 @@ if [ -z "$CNS" ] || [ "$CNS" != "'0'" -a "$CNS" != "'N'" -a "$CNS" != "'n'" #echo "$TMP"> /xcatpost/mypostscript.post echo " + if [ \"\$return_value\" -eq \"0\" ]; then + if [ \"\$XCATDEBUGMODE\" > \"0\" ]; then + msgutil_r \"\$MASTER_IP\" \"info\" \"node booted, reporting status...\" \"/var/log/xcat/xcat.log\" + fi updateflag.awk \$MASTER 3002 \"installstatus booted\" else + if [ \"\$XCATDEBUGMODE\" > \"0\" ]; 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 @@ -79,8 +91,9 @@ stopservice NetworkManager-wait-online disableservice NetworkManager disableservice NetworkManager-dispatcher disableservice NetworkManager-wait-online - 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 diff --git a/xCAT/postscripts/xcatlib.sh b/xCAT/postscripts/xcatlib.sh index 8bf01cb13..074c328f8 100755 --- a/xCAT/postscripts/xcatlib.sh +++ b/xCAT/postscripts/xcatlib.sh @@ -611,84 +611,59 @@ function disableservice { eval $cmd } -declare -a array_nic_params -declare -a array_extra_param_names -declare -a array_extra_param_values -# This function parse the NICEXTRAPARAMS into an array. -# Each arry element contains all the extra params for an ip -# For example: -# -# NICEXTRAPARAMS="eth0!MTU=1500 sonething=x|MTU=1460,ib0!MTU=65520 CONNECTED_MODE=yes" -# get_nic_extra_params $eth0 $NICEXTRAPARAMS -# After the function is called: -# array_nic_param[0]="MTU=1500 sonething=x" -# array_nic_param[1]="MTU=1460" -function get_nic_extra_params() { - nic=$1 - nic_extra=$2 - unset array_nic_params - if [ ! "$nic_extra" ];then - return - fi - old_ifs=$IFS - IFS=$',' - array_conf_temp=($nic_extra) - IFS=$old_ifs - #echo "nic_extra=$nic_extra" - i=0 - while [ $i -lt ${#array_conf_temp[@]} ] - do - token="${array_conf_temp[$i]}" - D= - if echo "$token" | grep "!"; then - D="!" - else - D=":" - fi - key=`echo "$token" | cut -d"$D" -f 1` - #echo "key=$key nic=$nic" - if [ "$key" == "$nic" ]; then - str_temp_value=`echo "$token" | cut -d"$D" -f 2` - #echo "token=$token, str_temp_value=$str_temp_value" - old_ifs=$IFS - IFS=$'|' - array_nic_params=($str_temp_value) - IFS=$old_ifs - return - fi - i=$((i+1)) - done + +##################################################################### +#msgutil_r : process messages from xcat postscripts +#description : for a specified message, call this function to echo, +# append to specified log file and log it remotely +#args : +# logserver: the hostname or ip addr of log server +# msgtype: the type of the message, +# valid values(debug,info,warning,err) +# msgstr: the string of the message to process +# logfile: the path of the file to append the log +#################################################################### +function msgutil_r { + local logserver=$1 + local msgtype=$2 + local msgstr=$3 + local logfile=$4 + + if [ -z "$msgtype" ]; then + msgtype="debug" + fi + + logger -n $logserver -t xcat -p local4.$msgtype "$msgstr" + + if [ -n "$logfile" ]; then + local logdir="$(dirname $logfile)" + if [ ! -d "$logdir" ]; then + mkdir -p "$logdir" + touch "$logfile" + fi + + # echo "$msgstr" | tee -a $logfile + #else + echo "$msgstr" >> $logfile + fi + } -# This functions parse the extra parameters for an ip address of a nic -# Input is like this: -# MTU=65520 something=yes -# After the function is called: -# array_extra_param_names[0]="MTU" -# array_extra_param_values[0]="65520" -# array_extra_param_names[1]="something" -# array_extra_param_values[0]="yes" -# -function parse_nic_extra_params() { - str_extra=$1 - - unset array_extra_param_names - unset array_extra_param_values - old_ifs=$IFS - IFS=$' ' - params_temp=($str_extra) - IFS=$old_ifs - k=0 - while [ $k -lt ${#params_temp[@]} ] - do - token2="${params_temp[$k]}" - array_extra_param_names[$k]=`echo "$token2" | cut -d'=' -f 1` - array_extra_param_values[$k]=`echo "$token2" | cut -d'=' -f 2` - k=$((k+1)) - done +##################################################################### +#msgutil : process messages from xcat postscripts +#description : for a specified message, call this function to +# echo,append to the specified file and log it +#args : +# msgtype: the type of the message, +# valid values(debug,info,warning,err) +# msgstr: the string of the message to process +# logfile: the path of the file to append the log +#################################################################### +function msgutil { + msgutil_r "localhost" "$@" }