2008-05-14 16:43:41 +00:00
|
|
|
#!/bin/sh
|
2007-10-26 22:44:33 +00:00
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
#
|
2008-05-14 16:43:41 +00:00
|
|
|
#---------------------------------------------------------------------------
|
|
|
|
# setup NTP configuration on the compute nodes
|
|
|
|
#
|
|
|
|
#---------------------------------------------------------------------------
|
2014-06-10 15:54:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
str_dir_name=`dirname $0`
|
|
|
|
|
|
|
|
. $str_dir_name/xcatlib.sh
|
|
|
|
|
2012-10-23 19:18:52 +00:00
|
|
|
# if on the Management Node, exit
|
|
|
|
if [ -e /etc/xCATMN ]; then
|
|
|
|
logger -t xcat -p local4.info "setupntp:Running on the Management Node , exiting "
|
|
|
|
exit 0
|
|
|
|
fi
|
2008-05-14 16:43:41 +00:00
|
|
|
master=$MASTER
|
2008-05-28 16:38:49 +00:00
|
|
|
setup=0
|
|
|
|
sitemaster=$SITEMASTER
|
2008-05-14 16:43:41 +00:00
|
|
|
conf_file="/etc/ntp.conf"
|
2008-05-28 16:38:49 +00:00
|
|
|
conf_file_org="/etc/ntp.conf.org"
|
2008-05-14 16:43:41 +00:00
|
|
|
conf_file_backup="/etc/ntp.conf.postbackup"
|
2011-09-08 03:22:49 +00:00
|
|
|
|
|
|
|
# pmatch determines if 1st argument string is matched by 2nd argument pattern
|
|
|
|
|
|
|
|
pmatch ()
|
|
|
|
{
|
|
|
|
case $1 in
|
|
|
|
$2) return 0;; # zero return code means string matched by pattern
|
|
|
|
esac
|
|
|
|
|
|
|
|
return 1 # non-zero return code means string not matched by pattern
|
|
|
|
}
|
|
|
|
|
2011-10-06 17:45:08 +00:00
|
|
|
# is_lsb_ubuntu exit status indicates whether system appears to be Ubuntu.
|
|
|
|
# Using required /etc/lsb-release file, instead of optional lsb_release command.
|
|
|
|
|
|
|
|
is_lsb_ubuntu ()
|
|
|
|
{
|
|
|
|
awk '
|
|
|
|
(match($0, "^[ \t]*DISTRIB_ID=") == 1) { # A DISTRIB_ID line
|
|
|
|
id = substr($0, RLENGTH + 1) # Save its value
|
|
|
|
}
|
|
|
|
|
|
|
|
END {
|
|
|
|
# Examine last DISTRIB_ID value to see if Ubuntu indicated
|
|
|
|
|
|
|
|
if (match(id, "^(Ubuntu|\"Ubuntu\")[ \t]*$") == 1) {
|
|
|
|
exit 0 # Ubuntu
|
|
|
|
}
|
|
|
|
exit 1 # Not Ubuntu
|
|
|
|
}
|
|
|
|
|
|
|
|
' /etc/lsb-release >/dev/null 2>&1
|
|
|
|
|
|
|
|
# Routine exit status is exit status of the last command -- the awk script.
|
|
|
|
#
|
|
|
|
# Note: if /etc/lsb-release does not exist, the exit status indicates
|
|
|
|
# failure (not Ubuntu), which is the correct outcome.
|
|
|
|
}
|
|
|
|
|
2007-10-26 22:44:33 +00:00
|
|
|
logger -t xcat "Install: Setup NTP"
|
2008-05-28 16:38:49 +00:00
|
|
|
# if master is the sitemaster, then use the ntpservers defined in the site
|
|
|
|
# table, if they exist. If they don't exist, do not setup ntp
|
|
|
|
# else use the master which should be a service node
|
2011-09-08 03:22:49 +00:00
|
|
|
if [ "$master" = "$sitemaster" ]; then
|
2008-05-28 16:38:49 +00:00
|
|
|
if [ $NTPSERVERS ]; then
|
2012-02-09 11:34:05 +00:00
|
|
|
if [ "$NODESETSTATE" = "statelite" ]; then
|
2010-06-02 06:50:38 +00:00
|
|
|
cp -a $conf_file $conf_file_org
|
|
|
|
echo "" > $conf_file
|
2008-05-28 16:38:49 +00:00
|
|
|
else
|
2010-06-02 06:50:38 +00:00
|
|
|
if [ ! -f $conf_file_org ]; then
|
|
|
|
mv -f $conf_file $conf_file_org
|
|
|
|
else
|
|
|
|
mv -f $conf_file $conf_file_backup
|
|
|
|
fi
|
2008-05-28 16:38:49 +00:00
|
|
|
fi
|
2012-02-09 11:34:05 +00:00
|
|
|
if [ "$NTPSERVERS" = "<xcatmaster>" ] || [ "$NTPSERVERS" = "<xcatmaster>" ]; then
|
2012-02-09 11:28:02 +00:00
|
|
|
echo "server $master" >>$conf_file
|
|
|
|
else
|
|
|
|
for i in $(echo $NTPSERVERS | tr ',' ' ')
|
|
|
|
do
|
|
|
|
echo "server $i" >>$conf_file
|
|
|
|
master=$i
|
|
|
|
done
|
|
|
|
fi
|
2008-05-28 16:38:49 +00:00
|
|
|
else
|
2012-02-09 11:28:02 +00:00
|
|
|
echo "server $master" >$conf_file
|
2008-05-28 16:38:49 +00:00
|
|
|
|
|
|
|
fi
|
|
|
|
else
|
2011-09-08 03:22:49 +00:00
|
|
|
if [ "$NODESETSTATE" = "statelite" ]; then
|
2010-06-02 06:50:38 +00:00
|
|
|
cp -a $conf_file $conf_file_org
|
|
|
|
echo "" > $conf_file
|
|
|
|
else
|
|
|
|
if [ ! -f $conf_file_org ]; then
|
|
|
|
mv -f $conf_file $conf_file_org
|
|
|
|
else
|
|
|
|
mv -f $conf_file $conf_file_backup
|
|
|
|
fi
|
|
|
|
fi
|
2012-02-13 06:35:33 +00:00
|
|
|
|
|
|
|
if [ $NTPSERVERS ]; then
|
|
|
|
if [ "$NTPSERVERS" = "<xcatmaster>" ] || [ "$NTPSERVERS" = "<xcatmaster>" ]; then
|
|
|
|
echo "server $master" >>$conf_file
|
|
|
|
else
|
|
|
|
for i in $(echo $NTPSERVERS | tr ',' ' ')
|
|
|
|
do
|
|
|
|
echo "server $i" >>$conf_file
|
|
|
|
master=$i
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "server $master" >$conf_file
|
|
|
|
fi
|
|
|
|
|
2008-05-28 16:38:49 +00:00
|
|
|
fi
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2011-09-08 03:22:49 +00:00
|
|
|
OS_TYPE=`uname`
|
|
|
|
if [ $OS_TYPE = Linux ]; then
|
2013-09-11 10:10:15 +00:00
|
|
|
mkdir -p /var/lib/ntp
|
|
|
|
chown ntp /var/lib/ntp
|
|
|
|
echo "driftfile /var/lib/ntp/drift
|
2008-06-02 16:45:22 +00:00
|
|
|
disable auth
|
2013-09-13 09:06:14 +00:00
|
|
|
restrict 127.0.0.1" >>$conf_file
|
2013-09-11 10:10:15 +00:00
|
|
|
# default service for redhat/fedora
|
2014-06-10 15:54:31 +00:00
|
|
|
#SERVICE=ntpd
|
|
|
|
#if ( pmatch $OSVER "sles*" ) || ( pmatch $OSVER "suse*" ) || [ -f /etc/SuSE-release ] || ( pmatch $OSVER "ubuntu*" ) || ( is_lsb_ubuntu ); then
|
|
|
|
# SERVICE=ntp
|
|
|
|
#fi
|
2008-05-27 13:33:14 +00:00
|
|
|
|
2013-09-11 10:10:15 +00:00
|
|
|
#ntpdate/sntp conflict with ntpd, stop the service first
|
2014-06-10 15:54:31 +00:00
|
|
|
# service $SERVICE status
|
|
|
|
checkservicestatus ntpserver
|
2013-09-11 10:10:15 +00:00
|
|
|
if [ $? -eq 0 ];then
|
2014-06-10 15:54:31 +00:00
|
|
|
# service $SERVICE stop
|
|
|
|
stopservice ntpserver
|
2013-09-11 10:10:15 +00:00
|
|
|
fi
|
|
|
|
#ntpdate program is deprecated on SuSE
|
|
|
|
if ( pmatch $OSVER "sles*" ) || ( pmatch $OSVER "suse*" ) || [ -f /etc/SuSE-release ]; then
|
|
|
|
logger -t xcat "sntp -P no -r $master"
|
|
|
|
sntp -P no -r $master
|
|
|
|
if [ "$?" != "0" ];then
|
|
|
|
echo " sntp -P no -r $master failed"
|
|
|
|
logger -t xcat "sntp -P no -r $master failed"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
logger -t xcat "ntpdate -t5 $master "
|
|
|
|
ntpdate -t5 $master
|
|
|
|
if [ "$?" != "0" ];then
|
|
|
|
echo " ntpdate -t5 $master failed"
|
2008-05-30 13:52:38 +00:00
|
|
|
logger -t xcat "ntpdate -t5 $master failed"
|
2013-09-11 10:10:15 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
#setup the hardware clock
|
|
|
|
hwclock --systohc --utc
|
2008-06-13 12:22:20 +00:00
|
|
|
|
2013-09-11 10:10:15 +00:00
|
|
|
#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
|
|
|
|
elif [ -f "/etc/debian_version" ];then
|
|
|
|
sed -i 's/.*UTC.*/UTC=yes/' /etc/default/rcS
|
|
|
|
else
|
|
|
|
grep -i "utc" /etc/sysconfig/clock
|
|
|
|
if [ $? -eq 0 ];then
|
|
|
|
sed -i 's/.*UTC.*/UTC=yes/' /etc/sysconfig/clock
|
|
|
|
else
|
|
|
|
echo "UTC=yes" >> /etc/sysconfig/clock
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
#update the hardware clock automaticly
|
|
|
|
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
|
|
|
|
else
|
|
|
|
echo "SYNC_HWCLOCK=yes" >> /etc/sysconfig/ntpd
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
cron_file="/etc/cron.daily/xcatsethwclock"
|
|
|
|
if [ ! -f "$cron_file" ];then
|
|
|
|
echo "#!/bin/sh" > $cron_file
|
|
|
|
echo "/sbin/hwclock --systohc --utc" >> $cron_file
|
|
|
|
chmod a+x $cron_file
|
2014-06-10 15:54:31 +00:00
|
|
|
#service cron restart
|
|
|
|
restartservice cron
|
2013-09-11 10:10:15 +00:00
|
|
|
fi
|
|
|
|
fi
|
2014-06-10 15:54:31 +00:00
|
|
|
#service $SERVICE start
|
|
|
|
startservice ntpserver
|
2013-09-11 10:10:15 +00:00
|
|
|
|
|
|
|
#start ntp and crontab automaticlly
|
2014-06-10 15:54:31 +00:00
|
|
|
#if [ -f "/etc/debian_version" ];then
|
|
|
|
# update-rc.d cron defaults
|
|
|
|
# update-rc.d $SERVICE defaults
|
|
|
|
#else
|
|
|
|
# chkconfig --add $SERVICE >/dev/null 2>&1
|
|
|
|
# chkconfig --level 345 $SERVICE on >/dev/null 2>&1
|
|
|
|
# if ( pmatch $OSVER "sles*" ) || ( pmatch $OSVER "suse*" ) || [ -f /etc/SuSE-release ];then
|
|
|
|
# chkconfig --add cron >/dev/null 2>&1
|
|
|
|
# chkconfig --level 345 cron on >/dev/null 2>&1
|
|
|
|
# fi
|
|
|
|
#fi
|
|
|
|
enableservice cron
|
|
|
|
enableservice ntpserver
|
2008-06-13 12:22:20 +00:00
|
|
|
else
|
|
|
|
# stop and start AIX ntp
|
|
|
|
echo "driftfile /etc/ntp.drift
|
|
|
|
tracefile /etc/ntp.trace
|
|
|
|
disable auth
|
|
|
|
broadcastclient
|
|
|
|
restrict 127.0.0.1" >>$conf_file
|
2008-05-28 16:38:49 +00:00
|
|
|
|
2013-09-11 10:10:15 +00:00
|
|
|
stopsrc -s xntpd
|
|
|
|
logger -t xcat "ntpdate -t5 $master "
|
|
|
|
ntpdate -t5 $master
|
|
|
|
if [ "$?" != "0" ]
|
|
|
|
then
|
|
|
|
echo " ntpdate -t5 $master failed "
|
|
|
|
logger -t xcat "ntpdate -t5 $master failed"
|
|
|
|
fi
|
|
|
|
/usr/sbin/chrctcp -S -a xntpd
|
2008-06-13 12:22:20 +00:00
|
|
|
fi
|
2008-05-28 16:38:49 +00:00
|
|
|
exit $?
|