Change to support new design for NTP setup.

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@1511 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
lissav 2008-05-28 16:38:49 +00:00
parent aa38820f80
commit d835ef8a26
3 changed files with 117 additions and 52 deletions

View File

@ -28,7 +28,7 @@ This program module file is a set of utilities to support xCAT post scripts.
Error:
Example:
xCAT::Postage->writescript($node, "/install/postscripts/" . $node, $state);
xCAT::Postage->writescript($node, "/install/postscripts/" . $node, $state,$callback);
Comments:
@ -104,14 +104,19 @@ sub makescript {
xCAT::MsgUtils->message("E", $rsp, $callback);
return undef;
}
my $master;
# read the master node from the site table for the node
my $master; # may be the Management Node or Service Node
my $sitemaster; # Always the Management Node
my $sitetab = xCAT::Table->new('site');
(my $et) = $sitetab->getAttribs({key=>"master"},'value');
if ($et and $et->{value}) {
if ($et and defined($et->{value})) {
$master = $et->{value};
$sitemaster = $et->{value};
}
# if node has service node as master then override site master
$et = $noderestab->getNodeAttribs($node,['xcatmaster']);
if ($et and $et->{'xcatmaster'}) {
if ($et and defined($et->{'xcatmaster'})) {
$master = $et->{'xcatmaster'};
}
unless ($master) {
@ -121,10 +126,29 @@ sub makescript {
return undef;
}
# read the ntpservers
my $ntpservers;
(my $et) = $sitetab->getAttribs({key=>"ntpservers"},'value');
if ($et and defined($et->{value})) {
$ntpservers = $et->{value};
}
# set env variable $SITEMASTER for Management Node
push @scriptd, "SITEMASTER=".$sitemaster."\n";
push @scriptd, "export SITEMASTER\n";
# set env variable $MASTER for master of node (MN or SN)
push @scriptd, "MASTER=".$master."\n";
push @scriptd, "export MASTER\n";
push @scriptd, "NODE=$node\n";
push @scriptd, "export NODE\n";
# if ntpservers exist, export $NTPSERVERS
if (defined($ntpservers)) {
push @scriptd, "NTPSERVERS=".$ntpservers."\n";
push @scriptd, "export NTPSERVERS\n";
}
my $et = $typetab->getNodeAttribs($node,['os','arch','profile']);
if ($^O =~ /^linux/i) {
unless ($et and $et->{'os'} and $et->{'arch'}) {
@ -148,10 +172,8 @@ sub makescript {
}
push @scriptd, 'PATH=`dirname $0`:$PATH'."\n";
push @scriptd, "export PATH\n";
my $stab = xCAT::Table->new('site');
my $sent = $stab->getAttribs({key=>'svloglocal'},'value');
if ($sent and $sent->{value}) {
my $sent = $sitetab->getAttribs({key=>'svloglocal'},'value');
if ($sent and defined($sent->{value})) {
push @scriptd, "SVLOGLOCAL=".$sent->{'value'}."\n";
push @scriptd, "export SVLOGLOCAL\n";
}

View File

@ -16,8 +16,11 @@ use File::Path;
#-------------------------------------------------------
=head3 handled_commands
Note: Right now all function is commented out. May use in the future.
Service Node and Compute Node NTP is setup by setupntp scripts
Management Node is left to be setup by Admin
This runs on Service Node
This runs on Service Node and Management node to setup NTP
Checks servicenode table ntpserver attribute
Call setup_NTP
@ -33,41 +36,44 @@ sub handled_commands
}
my $rc = 0;
# Note all code is commented out now, setup done by setupntp
# postinstall script for the SN and compute nodes. Management Node
# is left up to the admin. This may change in the future.
if (xCAT::Utils->isServiceNode())
{
my @nodeinfo = xCAT::Utils->determinehostname;
my $nodename = pop @nodeinfo; # get hostname
my @nodeipaddr = @nodeinfo; # get ip addresses
my $service = "ntpserver";
$rc = xCAT::Utils->isServiceReq($nodename, $service, \@nodeipaddr);
if ($rc == 1)
{
$rc = &setup_NTPsn($nodename); #setup NTP on Service Node
if ($rc == 0)
{
xCAT::Utils->update_xCATSN($service);
}
}
else
{
if ($rc == 2)
{ # just start the daemon
my $cmd = "service ntpd restart";
system $cmd;
if ($? > 0)
{ # error
xCAT::MsgUtils->message("S", "Error on command: $cmd");
return 1;
}
}
}
}
else
{ # Management Node
$rc = &setup_NTPmn(); # setup NTP on Management Node
}
# if (xCAT::Utils->isServiceNode())
# {
# my @nodeinfo = xCAT::Utils->determinehostname;
# my $nodename = pop @nodeinfo; # get hostname
# my @nodeipaddr = @nodeinfo; # get ip addresses
# my $service = "ntpserver";
# $rc = xCAT::Utils->isServiceReq($nodename, $service, \@nodeipaddr);
# if ($rc == 1)
# {
# $rc = &setup_NTPsn($nodename); #setup NTP on Service Node
# if ($rc == 0)
# {
# xCAT::Utils->update_xCATSN($service);
# }
# }
# else
# {
# if ($rc == 2)
# { # just start the daemon
# my $cmd = "service ntpd restart";
# system $cmd;
# if ($? > 0)
# { # error
# xCAT::MsgUtils->message("S", "Error on command: $cmd");
# return 1;
# }
# }
# }
# }
# else
# { # Management Node
# $rc = &setup_NTPmn(); # setup NTP on Management Node
#
# }
return $rc;
}

View File

@ -6,24 +6,61 @@
#
#---------------------------------------------------------------------------
master=$MASTER
setup=0
sitemaster=$SITEMASTER
conf_file="/etc/ntp.conf"
conf_file_org="/etc/ntp.conf.org"
conf_file_backup="/etc/ntp.conf.postbackup"
# if backup does not exist, backup
if [ ! -f $conf_file_backup ]; then
mv -f $conf_file $conf_file_backup
logger -t xcat "Install: Setup NTP"
# 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
if [ "$master" == "$sitemaster" ]; then
if [ $NTPSERVERS ]; then
if [ ! -f $conf_file_org ]; then
mv -f $conf_file $conf_file_org
else
mv -f $conf_file $conf_file_backup
fi
for i in $(echo $NTPSERVERS | tr ',' ' ')
do
echo "server $i" >>$conf_file
master=$i
done
else
exit 0
fi
else
if [ ! -f $conf_file_org ]; then
mv -f $conf_file $conf_file_org
else
mv -f $conf_file $conf_file_backup
fi
echo "server $master" >$conf_file
fi
logger -t xcat "Install: Setup NTP"
echo "server $master" >$conf_file
mkdir -p /etc/ntp
chown ntp /etc/ntp
mkdir -p /var/lib/ntp
chown ntp /var/lib/ntp
echo "driftfile /var/lib/ntp/drift
restrict 127.0.0.1
authenticate no" >>$conf_file
#service ntpd restart
service ntpd stop
ntpdate $master
logger -t xcat "ntpdate -t5 $master "
ntpdate -t5 $master
if [ "$?" != "0" ]
then
echo_failure
echo
echo " ntpdate -t5 $master failed"
exit $?
fi
service ntpd start
exit $?