From: davidplunkett Date: Fri, 3 Aug 2018 07:03:21 +0000 (-0400) Subject: cleanup dhcp, exit, buffering and log filename X-Git-Tag: 0.0.1~5 X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=commitdiff_plain;h=e8acd2844843bd235da1c043c8fb2e47c6e2eff1;p=redfish.git cleanup dhcp, exit, buffering and log filename Change-Id: I6d3f883a79fd2e47cc777b771f9387a2750c9343 Signed-off-by: davidplunkett --- diff --git a/apply_dellxml.sh b/apply_dellxml.sh index 318d481..da19185 100755 --- a/apply_dellxml.sh +++ b/apply_dellxml.sh @@ -115,7 +115,7 @@ else fi echo "Beginning create and apply xlm file to server at" `date` -STARTTIME=$(date +%s) +STIME=$(date +%s) ## CREATE HARDWARE CONFIG XML FILE FOR USE WITH REDFISH echo "Creating server BIOS/RAID settings file [$BUILD_ROOT/$XMLFILE] for server [$SRV_NAME]" @@ -153,7 +153,7 @@ else fi ## DONE -ENDTIME=$(date +%s) +ETIME=$(date +%s) echo "SUCCESS: Completed update of BIOS/RAID settings on [$SRV_NAME] at" `date` -echo "Elapsed time was $(( ($ENDTIME - $STARTTIME) / 60 )) minutes and $(( ($ENDTIME - $STARTTIME) % 60 )) seconds" +echo "Elapsed time was $(( ($ETIME - $STIME) / 60 )) minutes and $(( ($ETIME - $STIME) % 60 )) seconds" diff --git a/buildrc b/buildrc index 1d80de4..f3cca76 100644 --- a/buildrc +++ b/buildrc @@ -33,5 +33,5 @@ export REGION_ROOT=${REGION_ROOT:-$WEB_ROOT/region} export BUILD_ROOT=${BUILD_ROOT:-$REDFISH_ROOT/server-config} export IPXE_ROOT=${IPXE_ROOT:-$REDFISH_ROOT/ipxe} -export UBUNTU_URL=${UBUNTU_URL:-http://releases.ubuntu.com/16.04/ubuntu-16.04.4-server-amd64.iso} +export UBUNTU_URL=${UBUNTU_URL:-http://releases.ubuntu.com/16.04/ubuntu-16.04.5-server-amd64.iso} diff --git a/install_server_os.sh b/install_server_os.sh index 69e9b08..da854ab 100755 --- a/install_server_os.sh +++ b/install_server_os.sh @@ -27,6 +27,12 @@ # SET DEFAULT VALUES UBUNTU_ISO=${UBUNTU_ISO:-} ## IF NOT SET, UBUNTU_URL WILL BE USED TO DOWNLOAD DEFAULT ISO +# SETUP LOGGING +#MYLOGFILE="`basename $0`-${RCFILE##*/}-`date -Im`.log" +MYLOGFILE="`basename $0`"; MYLOGFILE="${MYLOGFILE%.*}-`date -Im | sed -e 's/[+:]/-/g'`.log" +exec 1> >(tee -a "$MYLOGFILE") 2>&1 +echo "Logging to $PWD/$MYLOGFILE" + echo "Beginning $0 as user [$USER] in pwd [$PWD] with home [$HOME]" # default behavior will require confirmation before starting @@ -72,11 +78,6 @@ export NO_CONFIRM; export NO_APPLY_HW; export RCFILE; -# SETUP LOGGING -MYLOGFILE="`basename $0`-${RCFILE##*/}-`date -Im`.log" -exec 1> >(tee -a "$MYLOGFILE") 2>&1 -echo "Logging to $MYLOGFILE" - # SETUP TOOLS AND LOAD DEFAULT BUILD VARIABLES BASEDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" . $BASEDIR/setup_tools.sh 1>&2 @@ -86,12 +87,18 @@ if [ -n "$RCFILE" ] && [ -f "$RCFILE" ]; then source $RCFILE fi -if [ -z "$SRV_NAME" ] || [ -z "$SRV_OOB_IP" ] || [ -z "$SRV_OOB_USR" ] || [ -z "$SRV_OOB_PWD" ] || [ -z "$SRV_IPXE_INF" ] || [ -z "$BUILD_WEBIP" ]; then +if [ -z "$SRV_NAME" ] || [ -z "$SRV_OOB_IP" ] || [ -z "$SRV_OOB_USR" ] || [ -z "$SRV_OOB_PWD" ] || [ -z "$SRV_IPXE_INF" ] ; then echo "ERROR: Invalid or missing variables in rcfile [$RCFILE]" echo "usage: ./install_regionserver.sh [--rc settingsfile] [--no-confirm] [--no-apply-hw] [--help]" exit 1 fi +## FIND BUILD_WEBIP IF NOT PROVIDED +if [ -z "$BUILD_WEBIP" ]; then + BUILD_WEBIP=$(ip route get $SRV_IP | grep -o "src .*$" | cut -f 2 -d ' ') + echo "Using Build Web ip address [$BUILD_WEBIP]" +fi + # SET ADDITIONAL VARIABLES BASED ON RC FILE IPXE_VLAN=$SRV_VLAN IPXE_INTF=$SRV_IPXE_INF @@ -253,7 +260,7 @@ host $SRV_NAME { } EOF -## START DHCP SERVICE +## START/RESTART DHCP SERVICE echo "Starting dhcp server using folder [$DHCP_ROOT] on interface [$BUILD_INTERFACE]" docker stop boot-dhcp-server &> /dev/null docker rm boot-dhcp-server &> /dev/null @@ -282,14 +289,14 @@ if [ -z "$NO_APPLY_HW" ]; then echo "This step could take up to 15 minutes" WEBLOG_START=$(date +%FT%T) # ONLY CHECK ENTRIES AFTER WEBLOG_START TO AVOID PAST BUILDS, CHECK UP TO LAST 10 ENTRIES TO AVOID MISSING MESSAGES AFTER RESTART - while ( ! (docker logs --since "$WEBLOG_START" --tail 10 -f boot-www-server &) | awk "// {print \$0;} /^$SRV_IP.*GET \/$SRV_NAME.firstboot.sh/ {exit;}" ); do + while ( ! (docker logs --since "$WEBLOG_START" --tail 10 -f boot-www-server &) | awk "{print \$0; fflush();} /^$SRV_IP.*GET \/$SRV_NAME.firstboot.sh/ {exit;}" ); do echo "WARNING: Web server was restarted..." done ## WAIT FOR SERVER TO START REBOOT echo "Waiting for server [$SRV_IP] to reboot" `date` echo "Waiting for server to shutdown..." - (ping -i 5 $SRV_IP &) | awk '// {print $0;} /Destination Host Unreachable/ {x++; if (x>3) {exit;}}' + (ping -i 5 $SRV_IP &) | awk '{print $0; fflush();} /Destination Host Unreachable/ {x++; if (x>3) {exit;}}' # wait for previous ping to abort sleep 10 @@ -300,7 +307,7 @@ fi ## WAIT FOR SERVER TO FINISH REBOOT - PING SUCCEEDS 4 TIMES echo "Waiting for server to come back up..." -(ping -i 5 $SRV_IP &) | awk '// {print $0;} /time=/ {x++; if (x>3) {exit;}}' +(ping -i 5 $SRV_IP &) | awk '{print $0; fflush();} /time=/ {x++; if (x>3) {exit;}}' ## SETUP SSH KEYS echo "Setting up ssh keys for user [$USER] with home [$HOME]" @@ -337,10 +344,24 @@ if [ "$?" -ne 0 ]; then exit 1 fi +## DELETE HOST ENTRY FROM DHCP +echo "Removing dhcp configuration for server [$SRV_NAME] from [$DHCP_ROOT/dhcpd.conf]" +perl -i -p0e "s/^host.*?$SRV_MAC.*?\n\}\n//gms" $DHCP_ROOT/dhcpd.conf + +## START/RESTART DHCP SERVICE +echo "Restarting dhcp server using folder [$DHCP_ROOT] on interface [$BUILD_INTERFACE]" +docker stop boot-dhcp-server &> /dev/null +docker rm boot-dhcp-server &> /dev/null +docker run -dit --name boot-dhcp-server --rm --net=host -v "$DHCP_ROOT":/data networkboot/dhcpd $BUILD_INTERFACE + ## DONE ENDTIME=$(date +%s) echo "SUCCESS: Completed bare metal install of regional server [$SRV_NAME] at" `date` echo "SUCCESS: Try connecting with 'ssh root@$SRV_IP' as user $USER" echo "Elapsed time was $(( ($ENDTIME - $STARTTIME) / 60 )) minutes and $(( ($ENDTIME - $STARTTIME) % 60 )) seconds" + +# WORKAROUND TO GET TEE REDIRECTION TO TERMINATE +ps -af + exit 0