From 39cf499532ec221a2e42ea4535dbbc890a4aef99 Mon Sep 17 00:00:00 2001 From: Casandra Qiu Date: Thu, 9 Jul 2015 10:49:45 -0400 Subject: [PATCH] bugs#4720 makentp should supports synch MN's hwclock --- xCAT-server/lib/xcat/plugins/makentp.pm | 67 ++++++++++++++++++++++--- xCAT/postscripts/setupntp | 8 +-- 2 files changed, 65 insertions(+), 10 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/makentp.pm b/xCAT-server/lib/xcat/plugins/makentp.pm index c32ac744f..ac8ce5102 100755 --- a/xCAT-server/lib/xcat/plugins/makentp.pm +++ b/xCAT-server/lib/xcat/plugins/makentp.pm @@ -345,7 +345,62 @@ sub process_request { return 1; } } - + + #setup the hardware clock + my $hwcmd = "/sbin/hwclock --systohc --utc"; + if ($verbose) { + send_msg(\%request, 0, " ...updating the hwclock now. $hwcmd"); + } + my $hwresult = xCAT::Utils->runcmd($hwcmd, 0); + if ($verbose) { + send_msg(\%request, 0, " $hwresult"); + } + if ($::RUNCMD_RC != 0) { + send_msg(\%request, 1, "Error from command $hwcmd\n $hwresult."); + return 1; + } + + my $grep_cmd; + my $rc; + #setup the RTC is UTC format, which will be used by os + if ($os =~ /sles/) { + `sed -i 's/.*HWCLOCK.*/HWCLOCK="-u"/' /etc/sysconfig/clock`; + } elsif ( -f "/etc/debian_version" ){ + `sed -i "s/.*UTC.*/UTC=yes/" /etc/default/rcS`; + } else { + if ( -f "/etc/sysconfig/clock" ) { + $grep_cmd = "grep -i utc /etc/sysconfig/clock"; + $rc = xCAT::Utils->runcmd($grep_cmd, 0); + if ($::RUNCMD_RC != 0){ + `sed -i 's/.*UTC.*/UTC=yes/' /etc/sysconfig/clock`; + } else { + `echo "UTC=yes" >> /etc/sysconfig/clock`; + } + } else { + `type -P timedatectl >/dev/null 2>&1`; + `timedatectl set-local-rtc 0`; + } + } + + #update the hardware clock automaticly + if ( -f "/etc/sysconfig/ntpd" ) { + $grep_cmd = "grep -i SYNC_HWCLOCK /etc/sysconfig/ntpd"; + $rc = xCAT::Utils->runcmd($grep_cmd, 0); + if ($::RUNCMD_RC != 0) { + `sed -i "s/.*SYNC_HWCLOCK.*/SYNC_HWCLOCK=yes/" /etc/sysconfig/ntpd`; + } else { + `echo "SYNC_HWCLOCK=yes" >> /etc/sysconfig/ntpd`; + } + } else { + my $cron_file="/etc/cron.daily/xcatsethwclock"; + if ( ! -f "$cron_file" ) { + `echo "#!/bin/sh" > $cron_file` ; + `echo "/sbin/hwclock --systohc --utc" >> $cron_file`; + `chmod a+x $cron_file`; + #service cron restart + xCAT::Utils->startservice("cron"); + } + } #start ntpd if ($verbose) { send_msg(\%request, 0, " ...starting $ntp_service" ); @@ -377,13 +432,11 @@ sub process_request { }, $sub_req, -1, 1 ); - if ($verbose) { - send_msg(\%request, 0, " ...updatnode returns the following result: @$ret" ); - } - if ($::RUNCMD_RC != 0) { - send_msg(\%request, 1, "Error in updatenode: $ret" ); - + my $msg; + foreach my $line (@$ret) { + $msg .= "$line\n"; } + send_msg(\%request, 1, "$msg"); } } diff --git a/xCAT/postscripts/setupntp b/xCAT/postscripts/setupntp index 6b74fd656..e017c5ae7 100755 --- a/xCAT/postscripts/setupntp +++ b/xCAT/postscripts/setupntp @@ -119,10 +119,12 @@ restrict 127.0.0.1" >>$conf_file fi echo "$cmd" logger -t xcat "$cmd" - eval $cmd - if [ "$?" != "0" ];then - echo " $cmd failed" + output=`eval $cmd 2>&1` + rc=$? + if [ "$rc" != "0" ] || (pmatch "$output" "Time could not*");then + echo "$cmd failed, NTP maynot be synchronized, please wait for NTP synchronized then run updatenode nodename -P setupntp" logger -t xcat "$cmd failed" + exit 1 fi else logger -t xcat "ntpdate -t5 $master "