2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-05-30 01:26:38 +00:00

diff postscript and postbootscript log (#1832)

This commit is contained in:
penguhyang 2016-09-27 10:20:00 +08:00 committed by yangsong
parent 59dbe911e5
commit e4c0d8c367
7 changed files with 118 additions and 68 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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