diff --git a/xCAT-server/lib/xcat/plugins/makentp.pm b/xCAT-server/lib/xcat/plugins/makentp.pm index 9f404ae1c..f60a73c55 100755 --- a/xCAT-server/lib/xcat/plugins/makentp.pm +++ b/xCAT-server/lib/xcat/plugins/makentp.pm @@ -309,11 +309,15 @@ sub process_request { } } + #for sles, /var/lib/ntp/drift is a dir if (xCAT::Utils->isAIX()) { print CFGFILE "driftfile /etc/ntp.drift\n"; print CFGFILE "tracefile /etc/ntp.trace\n"; print CFGFILE "disable auth\n"; print CFGFILE "broadcastclient\n"; + } elsif ($os =~ /sles/) { + print CFGFILE "driftfile /etc/ntp.drift\n"; + print CFGFILE "disable auth\n"; } else { print CFGFILE "driftfile /var/lib/ntp/drift\n"; print CFGFILE "disable auth\n"; @@ -384,14 +388,20 @@ sub process_request { #setup the RTC is UTC format, which will be used by os if ($os =~ /sles/) { - `sed -i 's/.*HWCLOCK.*/HWCLOCK="-u"/' /etc/sysconfig/clock`; + $grep_cmd = "grep -i HWCLOCK /etc/sysconfig/clock"; + $rc = xCAT::Utils->runcmd($grep_cmd, 0); + if ($::RUNCMD_RC == 0) { + `sed -i 's/.*HWCLOCK.*/HWCLOCK=\"-u\"/' /etc/sysconfig/clock`; + } else { + `echo 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) { + if ($::RUNCMD_RC == 0) { `sed -i 's/.*UTC.*/UTC=yes/' /etc/sysconfig/clock`; } else { `echo "UTC=yes" >> /etc/sysconfig/clock`; @@ -406,11 +416,15 @@ sub process_request { 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`; + if ($::RUNCMD_RC == 0) { + `sed -i 's/.*SYNC_HWCLOCK.*/SYNC_HWCLOCK=\"yes\"/' /etc/sysconfig/ntpd`; } else { - `echo "SYNC_HWCLOCK=yes" >> /etc/sysconfig/ntpd`; + `echo SYNC_HWCLOCK=\"yes\" >> /etc/sysconfig/ntpd`; } + } elsif (-f "/etc/sysconfig/ntp") { + `sed -i "s/.*SYNC_HWCLOCK.*/NTPD_FORCE_SYNC_HWCLOCK_ON_STARTUP=yes/" /etc/sysconfig/ntp`; + `sed -i "s/^NTPD_FORCE_SYNC_ON.*/NTPD_FORCE_SYNC_ON_STARTUP=yes/" /etc/sysconfig/ntp`; + `sed -i "s/.*RUN_CHROOTED.*/NTPD_RUN_CHROOTED=yes/" /etc/sysconfig/ntp`; } else { my $cron_file = "/etc/cron.daily/xcatsethwclock"; if (!-f "$cron_file") { diff --git a/xCAT/postscripts/setupntp b/xCAT/postscripts/setupntp index b45372705..8e6c71e9c 100755 --- a/xCAT/postscripts/setupntp +++ b/xCAT/postscripts/setupntp @@ -99,9 +99,13 @@ OS_TYPE=`uname` if [ $OS_TYPE = Linux ]; then mkdir -p /var/lib/ntp chown ntp /var/lib/ntp - echo "driftfile /var/lib/ntp/drift -disable auth -restrict 127.0.0.1" >>$conf_file + if ( pmatch $OSVER "sles*" ) || ( pmatch $OSVER "suse*" ) || [ -f /etc/SuSE-release ];then + echo "driftfile /etc/ntp.drift" >>$conf_file + else + echo "driftfile /var/lib/ntp/drift" >>$conf_file + fi + echo "disable auth" >>$conf_file + echo "restrict 127.0.0.1" >>$conf_file #ntpdate/sntp conflict with ntpd, stop the service first checkservicestatus ntpserver @@ -140,7 +144,12 @@ restrict 127.0.0.1" >>$conf_file #setup the RTC is UTC format, which will be used by os if ( pmatch $OSVER "sles*" ) || ( pmatch $OSVER "suse*" ) || [ -f /etc/SuSE-release ];then - sed -i 's/.*HWCLOCK.*/HWCLOCK="-u"/' /etc/sysconfig/clock + grep -i "HWCLOCK" /etc/sysconfig/clock + if [ $? -eq 0 ];then + sed -i 's/.*HWCLOCK.*/HWCLOCK=\"-u\"/' /etc/sysconfig/clock + else + echo "HWCLOCK=\"-u\"" >> /etc/sysconfig/clock + fi elif [ -f "/etc/debian_version" ];then sed -i 's/.*UTC.*/UTC=yes/' /etc/default/rcS else @@ -160,9 +169,9 @@ restrict 127.0.0.1" >>$conf_file if [ -f "/etc/sysconfig/ntpd" ];then grep -i "SYNC_HWCLOCK" /etc/sysconfig/ntpd if [ $? -eq 0 ];then - sed -i 's/.*SYNC_HWCLOCK.*/SYNC_HWCLOCK=yes/' /etc/sysconfig/ntpd + sed -i 's/.*SYNC_HWCLOCK.*/SYNC_HWCLOCK=\"yes\"/' /etc/sysconfig/ntpd else - echo "SYNC_HWCLOCK=yes" >> /etc/sysconfig/ntpd + echo "SYNC_HWCLOCK=\"yes\"" >> /etc/sysconfig/ntpd fi elif [ -f /etc/sysconfig/ntp ];then grep -i "NTPD_FORCE_SYNC_ON_STARTUP" /etc/sysconfig/ntp