From e4c0d8c3673e52b31e3068bc06021f6b0bba2a7a Mon Sep 17 00:00:00 2001 From: penguhyang Date: Tue, 27 Sep 2016 10:20:00 +0800 Subject: [PATCH] diff postscript and postbootscript log (#1832) --- .../share/xcat/install/scripts/post.debian | 14 ++- .../xcat/install/scripts/post.rhel5.s390x | 14 ++- .../xcat/install/scripts/post.rhel6.s390x | 14 ++- .../xcat/install/scripts/post.sles10.s390x | 14 ++- .../xcat/install/scripts/post.sles11.s390x | 14 ++- .../share/xcat/install/scripts/post.xcat | 86 ++++++++++--------- xCAT/postscripts/xcatdsklspost | 30 +++++-- 7 files changed, 118 insertions(+), 68 deletions(-) diff --git a/xCAT-server/share/xcat/install/scripts/post.debian b/xCAT-server/share/xcat/install/scripts/post.debian index 13c45fc78..461a93baf 100644 --- a/xCAT-server/share/xcat/install/scripts/post.debian +++ b/xCAT-server/share/xcat/install/scripts/post.debian @@ -112,28 +112,34 @@ export PATH=$PATH:/xcatpost # However, Ubuntu cleans /tmp on reboot. So, for Ubuntu, /var/tmp is used instead. # 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` +TMP=`sed "/postscripts-start-here/,/postscripts-end-here/ s/\(.*\)/run_ps \1 postscript/;s/run_ps\s*#/#/;s/-here\spostscript/-here/;s/run_ps\s*$//" /xcatpost/mypostscript` echo " # subroutine used to run postscripts +# $1 argument is the script name +# $2 argument is the script type run_ps () { logdir=\"/var/log/xcat\" mkdir -p \$logdir logfile=\"/var/log/xcat/xcat.log\" + + if [ -z \"\$2\"]; then + scriptype=\"postscript\" + fi if [ -f \$1 ]; then - echo "\"\`date\` Running postscript: \$@\"" | tee -a \$logfile + echo "\"\`date\` Running \$scriptype: \$1\"" | tee -a \$logfile #./\$@ 2>&1 1> /tmp/tmp4xcatlog #cat /tmp/tmp4xcatlog | tee -a \$logfile ./\$@ 2>&1 | tee -a $logfile else - echo "\"\`date\` Postscript \$1 does NOT exist.\"" | tee -a \$logfile + echo "\"\`date\` \$scriptype \$1 does NOT exist.\"" | tee -a \$logfile fi } # 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` +TMP=`sed "/postbootscripts-start-here/,/postbootscripts-end-here/ s/\(.*\)/run_ps \1 postbootscript/;s/run_ps\s*#/#/;s/-here\spostbootscript/-here/;s/run_ps\s*$//" /xcatpost/mypostscript` echo "$TMP" > /xcatpost/mypostscript diff --git a/xCAT-server/share/xcat/install/scripts/post.rhel5.s390x b/xCAT-server/share/xcat/install/scripts/post.rhel5.s390x index 9f30feaaf..b3e2f2357 100644 --- a/xCAT-server/share/xcat/install/scripts/post.rhel5.s390x +++ b/xCAT-server/share/xcat/install/scripts/post.rhel5.s390x @@ -93,26 +93,32 @@ cd /xcatpost 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` +TMP=`sed "/postscripts-start-here/,/postscripts-end-here/ s/\(.*\)/run_ps \1 postscript/;s/run_ps\s*#/#/;s/-here\spostscript/-here/;s/run_ps\s*$//" /xcatpost/mypostscript` echo " # Subroutine used to run postscripts +# $1 argument is the script name +# $2 argument is the script type run_ps () { logdir=\"/var/log/xcat\" mkdir -p \$logdir logfile=\"/var/log/xcat/xcat.log\" + + if [ -z \"\$2\"]; then + scriptype=\"postscript\" + fi if [ -f \$1 ]; then - echo \"Running postscript: \$@\" | tee -a \$logfile + echo \"Running \$scriptype: \$1\" | tee -a \$logfile ./\$@ 2>&1 | tee -a $logfile else - echo \"Postscript \$1 does NOT exist.\" | tee -a \$logfile + echo \"\$scriptype \$1 does NOT exist.\" | tee -a \$logfile fi } # 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` +TMP=`sed "/postbootscripts-start-here/,/postbootscripts-end-here/ s/\(.*\)/run_ps \1 postbootscript/;s/run_ps\s*#/#/;s/-here\spostbootscript/-here/;s/run_ps\s*$//" /xcatpost/mypostscript` echo "$TMP" > /xcatpost/mypostscript diff --git a/xCAT-server/share/xcat/install/scripts/post.rhel6.s390x b/xCAT-server/share/xcat/install/scripts/post.rhel6.s390x index 61ce1477a..91864a84b 100644 --- a/xCAT-server/share/xcat/install/scripts/post.rhel6.s390x +++ b/xCAT-server/share/xcat/install/scripts/post.rhel6.s390x @@ -92,26 +92,32 @@ cd /xcatpost 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` +TMP=`sed "/postscripts-start-here/,/postscripts-end-here/ s/\(.*\)/run_ps \1 postscript/;s/run_ps\s*#/#/;s/-here\spostscript/-here/;s/run_ps\s*$//" /xcatpost/mypostscript` echo " # Subroutine used to run postscripts +# $1 argument is the script name +# $2 argument is the script type run_ps () { logdir=\"/var/log/xcat\" mkdir -p \$logdir logfile=\"/var/log/xcat/xcat.log\" + + if [ -z \"\$2\"]; then + scriptype=\"postscript\" + fi if [ -f \$1 ]; then - echo \"Running postscript: \$@\" | tee -a \$logfile + echo \"Running \$scriptype: \$1\" | tee -a \$logfile ./\$@ 2>&1 | tee -a $logfile else - echo \"Postscript \$1 does NOT exist.\" | tee -a \$logfile + echo \"\$scriptype \$1 does NOT exist.\" | tee -a \$logfile fi } # 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` +TMP=`sed "/postbootscripts-start-here/,/postbootscripts-end-here/ s/\(.*\)/run_ps \1 postbootscript/;s/run_ps\s*#/#/;s/-here\spostbootscript/-here/;s/run_ps\s*$//" /xcatpost/mypostscript` echo "$TMP" > /xcatpost/mypostscript diff --git a/xCAT-server/share/xcat/install/scripts/post.sles10.s390x b/xCAT-server/share/xcat/install/scripts/post.sles10.s390x index 3902c8917..a51024a79 100644 --- a/xCAT-server/share/xcat/install/scripts/post.sles10.s390x +++ b/xCAT-server/share/xcat/install/scripts/post.sles10.s390x @@ -100,20 +100,26 @@ PATH=$PATH:/xcatpost export PATH # 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*$//" /tmp/mypostscript` +TMP=`sed "/postscripts-start-here/,/postscripts-end-here/ s/\(.*\)/run_ps \1 postscript/;s/run_ps\s*#/#/;s/-here\spostscript/-here/;s/run_ps\s*$//" /tmp/mypostscript` echo " # subroutine used to run postscripts +# $1 argument is the script name +# $2 argument is the script type run_ps () { logdir=\"/var/log/xcat\" mkdir -p \$logdir logfile=\"/var/log/xcat/xcat.log\" + + if [ -z \"\$2\"]; then + scriptype=\"postscript\" + fi if [ -f \$1 ]; then - echo \"Running postscript: \$@\" | tee -a \$logfile + echo \"Running \$scriptype: \$1\" | tee -a \$logfile ./\$@ 2>&1 1> /tmp/tmp4xcatlog cat /tmp/tmp4xcatlog | tee -a \$logfile else - echo \"Postscript \$1 does NOT exist.\" | tee -a \$logfile + echo \"\$scriptype \$1 does NOT exist.\" | tee -a \$logfile fi } # subroutine end @@ -121,7 +127,7 @@ run_ps () { " > /tmp/mypostscript echo "cd /xcatpost" >> /tmp/mypostscript echo "$TMP" >> /tmp/mypostscript -TMP=`sed "/postbootscripts-start-here/,/postbootscripts-end-here/ s/\(.*\)/run_ps \1/;s/run_ps\s*#/#/;s/run_ps\s*$//" /tmp/mypostscript` +TMP=`sed "/postbootscripts-start-here/,/postbootscripts-end-here/ s/\(.*\)/run_ps \1 postbootscript/;s/run_ps\s*#/#/;s/-here\spostbootscript/-here/;s/run_ps\s*$//" /tmp/mypostscript` echo "$TMP" > /tmp/mypostscript diff --git a/xCAT-server/share/xcat/install/scripts/post.sles11.s390x b/xCAT-server/share/xcat/install/scripts/post.sles11.s390x index 3e84ad99b..dbe653e50 100644 --- a/xCAT-server/share/xcat/install/scripts/post.sles11.s390x +++ b/xCAT-server/share/xcat/install/scripts/post.sles11.s390x @@ -101,20 +101,26 @@ PATH=$PATH:/xcatpost export PATH # 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*$//" /tmp/mypostscript` +TMP=`sed "/postscripts-start-here/,/postscripts-end-here/ s/\(.*\)/run_ps \1 postscript/;s/run_ps\s*#/#/;s/-here\spostscript/-here/;s/run_ps\s*$//" /tmp/mypostscript` echo " # subroutine used to run postscripts +# $1 argument is the script name +# $2 argument is the script type run_ps () { logdir=\"/var/log/xcat\" mkdir -p \$logdir logfile=\"/var/log/xcat/xcat.log\" + + if [ -z \"\$2\"]; then + scriptype=\"postscript\" + fi if [ -f \$1 ]; then - echo \"Running postscript: \$@\" | tee -a \$logfile + echo \"Running \$scriptype: \$1\" | tee -a \$logfile ./\$@ 2>&1 1> /tmp/tmp4xcatlog cat /tmp/tmp4xcatlog | tee -a \$logfile else - echo \"Postscript \$1 does NOT exist.\" | tee -a \$logfile + echo \"\$scriptype \$1 does NOT exist.\" | tee -a \$logfile fi } # subroutine end @@ -122,7 +128,7 @@ run_ps () { " > /tmp/mypostscript echo "cd /xcatpost" >> /tmp/mypostscript echo "$TMP" >> /tmp/mypostscript -TMP=`sed "/postbootscripts-start-here/,/postbootscripts-end-here/ s/\(.*\)/run_ps \1/;s/run_ps\s*#/#/;s/run_ps\s*$//" /tmp/mypostscript` +TMP=`sed "/postbootscripts-start-here/,/postbootscripts-end-here/ s/\(.*\)/run_ps \1 postbootscript/;s/run_ps\s*#/#/;s/-here\spostbootscript/-here/;s/run_ps\s*$//" /tmp/mypostscript` echo "$TMP" > /tmp/mypostscript diff --git a/xCAT-server/share/xcat/install/scripts/post.xcat b/xCAT-server/share/xcat/install/scripts/post.xcat index 6e573c979..cf4f253ee 100755 --- a/xCAT-server/share/xcat/install/scripts/post.xcat +++ b/xCAT-server/share/xcat/install/scripts/post.xcat @@ -153,9 +153,9 @@ if [ ! -x /xcatpost/mypostscript ]; then done fi -TMP=`sed "/^#\s*postscripts-start-here/,/^#\s*postscripts-end-here/ s/\(.*\)/run_ps \1/;s/run_ps\s*#/#/;s/run_ps\s*$//" /xcatpost/mypostscript` +TMP=`sed "/^#\s*postscripts-start-here/,/^#\s*postscripts-end-here/ s/\(.*\)/run_ps \1 postscript/;s/run_ps\s*#/#/;s/-here\spostscript/-here/;s/run_ps\s*$//" /xcatpost/mypostscript` echo "$TMP" > /xcatpost/mypostscript -TMP=`sed "/^#\s*postbootscripts-start-here/,/^#\s*postbootscripts-end-here/ s/\(.*\)/run_ps \1/;s/run_ps\s*#/#/;s/run_ps\s*$//" /xcatpost/mypostscript` +TMP=`sed "/^#\s*postbootscripts-start-here/,/^#\s*postbootscripts-end-here/ s/\(.*\)/run_ps \1 postbootscript/;s/run_ps\s*#/#/;s/-here\spostbootscript/-here/;s/run_ps\s*$//" /xcatpost/mypostscript` cd /xcatpost #gunzip xcatpost.tar.gz @@ -178,48 +178,54 @@ echo " # 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 name +# $2 argument is the script type 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 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\" - if [ -f \$1 ]; then - echo \"\`date\` Running postscript: \$*\" - msgutil_r \"\$MASTER_IP\" \"info\" "\"\`date\` Running postscript: \$*\"" \"\$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 | 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 [ -z \"\$2\"]; then + scriptype=\"postscript\" + fi - if [ \"\$ret_local\" -ne \"0\" ]; then - return_value=\$ret_local - fi - echo \"Postscript: \$* exited with code \$ret_local\" - msgutil_r \"\$MASTER_IP\" \"info\" "\"\`date\` postscript \$* return with \$ret_local\"" \"\$logfile\" - else - echo \"\`date\` Postscript \$1 does NOT exist.\" - msgutil_r \"\$MASTER_IP\" \"info\" "\"\`date\` Postscript \$1 does NOT exist.\"" \"\$logfile\" - return_value=-1 - 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 + ret_local=\$? + 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 - return 0 + 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 diff --git a/xCAT/postscripts/xcatdsklspost b/xCAT/postscripts/xcatdsklspost index 629df8630..5364f01a2 100755 --- a/xCAT/postscripts/xcatdsklspost +++ b/xCAT/postscripts/xcatdsklspost @@ -822,21 +822,31 @@ fi #echo "$MYCONT" # 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` +if [ $NODE_DEPLOYMENT -eq 1 ] || [ "$MODE" = "4" ] || [ "$MODE" = "6" ]; then + TMP=`sed "/# postscripts-start-here/,/# postscripts-end-here/ s/\(.*\)/run_ps \1 postbootscript/;s/run_ps\s*#/#/;s/-here\spostbootscript/-here/;s/run_ps\s*$//" /$xcatpost/mypostscript` +else + TMP=`sed "/# postscripts-start-here/,/# postscripts-end-here/ s/\(.*\)/run_ps \1 postscript/;s/run_ps\s*#/#/;s/-here\spostscript/-here/;s/run_ps\s*$//" /$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 name +# $2 argument is the script type run_ps () { local ret_local=0 mkdir -p "\"/var/log/xcat\"" local logfile=\"/var/log/xcat/xcat.log\" + if [ -z \"\$2\"]; then + scriptype=\"postscript\" + fi + if [ -f \$1 ]; then - echo \"\`date\` Running postscript: \$*\" - msgutil_r \"\$MASTER_IP\" \"info\" "\"\`date\` Running postscript: \$*\"" \"\$logfile\" + 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\" @@ -855,11 +865,11 @@ run_ps () { if [ \"\$ret_local\" -ne \"0\" ]; then return_value=\$ret_local fi - echo \"Postscript: \$* exited with code \$ret_local\" - msgutil_r \"\$MASTER_IP\" \"info\" "\"\`date\` postscript \$* return with \$ret_local\"" \"\$logfile\" + echo \"\$scriptype: \$1 exited with code \$ret_local\" + msgutil_r \"\$MASTER_IP\" \"info\" "\"\`date\` \$scriptype \$1 return with \$ret_local\"" \"\$logfile\" else - echo \"\`date\` Postscript \$1 does NOT exist.\" - msgutil_r \"\$MASTER_IP\" \"info\" "\"\`date\` Postscript \$1 does NOT exist.\"" \"\$logfile\" + echo \"\`date\` \$scriptype \$1 does NOT exist.\" + msgutil_r \"\$MASTER_IP\" \"info\" "\"\`date\` \$scriptype \$1 does NOT exist.\"" \"\$logfile\" return_value=-1 fi @@ -869,7 +879,11 @@ run_ps () { " > /$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` +if [ "$MODE" = "1" ] || [ "$MODE" = "2" ] || [ "$MODE" = "3" ] || [ "$MODE" = "5" ]; then + TMP=`sed "/# postbootscripts-start-here/,/# postbootscripts-end-here/ s/\(.*\)/run_ps \1 postscript/;s/run_ps\s*#/#/;s/-here\spostscript/-here/;s/run_ps\s*$//" /$xcatpost/mypostscript` +else + TMP=`sed "/# postbootscripts-start-here/,/# postbootscripts-end-here/ s/\(.*\)/run_ps \1 postbootscript/;s/run_ps\s*#/#/;s/-here\spostbootscript/-here/;s/run_ps\s*$//" /$xcatpost/mypostscript` +fi echo "$TMP" > /$xcatpost/mypostscript if [ $NODE_DEPLOYMENT -eq 1 ] || [ "$MODE" = "4" ] || [ "$MODE" = "6" ]; then