merge all service node plugins into AAsn.pm and update Utils.pm for support

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@2817 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
lissav 2009-03-02 14:27:10 +00:00
parent 389ff14f64
commit d2cc1c69fd
11 changed files with 1012 additions and 1531 deletions

View File

@ -2024,43 +2024,44 @@ sub readSNInfo
Checks the service node table in the database to see
if the input Service should be setup on the
if input Service should be setup on the
input service node
Input: service nodename, service,ipaddres(s) and hostnames of service node
Input:servicenodename,ipaddres(s) and hostnames of service node
Output:
0 - no service required
1 - setup service
2 - service is setup, just start the daemon
-1 - error
array of services to setup for this service node
Globals:
none
$::RUNCMD_RC = 0; good
$::RUNCMD_RC = 1; error
Error:
none
Example:
if (xCAT::Utils->isServiceReq($servicenodename, $service, $serviceip) { blah; }
@servicestosetup=xCAT::Utils->isServiceReq($servicenodename, @serviceip) { blah; }
=cut
#-----------------------------------------------------------------------------
sub isServiceReq
{
my ($class, $servicenodename, $service, $serviceip) = @_;
my ($class, $servicenodename, $serviceip) = @_;
# list of all services from service node table
# note this must be updated if more services added
my @services = (
"nameserver", "dhcpserver", "tftpserver", "nfsserver",
"conserver", "monserver", "ldapserver", "ntpserver",
"ftpserver"
);
my @ips = @$serviceip; # list of service node ip addresses and names
my $rc = 0;
# check if service is already setup
#`grep $service /etc/xCATSN`;
#if ($? == 0)
#{ # service is already setup, just start daemon
# return 2;
#}
$rc = xCAT::Utils->exportDBConfig(); # export DB env
if ($rc != 0)
{
xCAT::MsgUtils->message('S', "Unable export DB environment.\n");
return -1;
$::RUNCMD_RC = 1;
return;
}
@ -2069,34 +2070,43 @@ sub isServiceReq
unless ($servicenodetab)
{
xCAT::MsgUtils->message('S', "Unable to open servicenode table.\n");
return 0; # do not setup anything
$::RUNCMD_RC = 1;
return; # do not setup anything
}
# read all the nodes from the table
my @snodelist = $servicenodetab->getAllNodeAttribs([$service]);
$servicenodetab->close;
foreach $serviceip (@ips) # check the table for this servicenode
{
foreach my $node (@snodelist)
my @process_service_list = ();
# read all the nodes from the table, for each service
foreach my $service (@services)
{
my @snodelist = $servicenodetab->getAllNodeAttribs([$service]);
foreach $serviceip (@ips) # check the table for this servicenode
{
if ($serviceip eq $node->{'node'})
{ # match table entry
if ($node->{$service})
{ # returns service, only if set
my $value = $node->{$service};
$value =~ tr/a-z/A-Z/; # convert to upper
# value 1 or yes then we setup the service
if (($value eq "1") || ($value eq "YES"))
{
return 1; # found service required for the node
foreach my $node (@snodelist)
{
if ($serviceip eq $node->{'node'})
{ # match table entry
if ($node->{$service})
{ # returns service, only if set
my $value = $node->{$service};
$value =~ tr/a-z/A-Z/; # convert to upper
# value 1 or yes then we setup the service
if (($value eq "1") || ($value eq "YES"))
{
push @process_service_list,
$service; # found service to setup
}
}
}
}
}
}
$servicenodetab->close;
return 0; # servicenode is not required to setup this service
$::RUNCMD_RC = 0;
return @process_service_list;
}
@ -2163,7 +2173,7 @@ sub update_xCATSN
#-----------------------------------------------------------------------------
=head3 gethost_ips
=head3 gethost_ips (AIX and Linux)
Will use ifconfig to determine all possible ip addresses for the
host it is running on and then gethostbyaddr to get all possible hostnames
@ -2189,9 +2199,20 @@ sub gethost_ips
}
foreach my $addr (@result)
{
my ($inet, $addr1, $Bcast, $Mask) = split(" ", $addr);
my @ip = split(":", $addr1);
push @ipaddress, $ip[1];
my @ip;
if (xCAT::Utils->isLinux())
{
my ($inet, $addr1, $Bcast, $Mask) = split(" ", $addr);
@ip = split(":", $addr1);
push @ipaddress, $ip[1];
}
else
{ #AIX
my ($inet, $addr1, $netmask, $mask1, $Bcast, $bcastaddr) =
split(" ", $addr);
push @ipaddress, $addr1;
}
}
my @names = @ipaddress;
foreach my $ipaddr (@names)
@ -3163,6 +3184,173 @@ sub logEventsToDatabase
#-------------------------------------------------------------------------------
=head3 startService
Supports AIX and Linux as long as the service is registered with
lssrc or startsrc.
Used by the service node plugin (AAsn.pm) to start requested services.
Checks to see if the input service is already started. If it is started
and the force flag is not set, it does not start the service. Otherwise
it starts the service.
Note we are using the system command on the start of the services to see
the output when the xcatd is started on Service Nodes. Do not change this.
Arguments:
servicename
force flag
Returns:
0 - service started or already started
1 - could not start the service
Globals:
none
Error:
1 error
Example:
my $forceflag=1;
if (xCAT::Utils->startService("named",$forceflag)) { ...}
Comments:
none
=cut
#-------------------------------------------------------------------------------
sub startService
{
my ($class, $service, $force) = @_;
my $rc = 0;
my @output;
my $cmd;
if (xCAT::Utils->isAIX())
{
if (!($force))
{ # if don't force, check to see if started, and exit if started
@output =
xCAT::Utils->runcmd("LANG=C /usr/bin/lssrc -s $service", 0);
if ($::RUNCMD_RC != 0)
{ # error so start it
$cmd = "/usr/bin/stopsrc -s $service";
system $cmd; # note using system here to see output when
# daemon comes up
if ($? > 0)
{ # error
xCAT::MsgUtils->message("S", "Error on command: $cmd\n");
}
$cmd = "/usr/bin/startsrc -s $service";
system $cmd;
if ($? > 0)
{ # error
xCAT::MsgUtils->message("S", "Error on command: $cmd\n");
return 1;
}
}
else # check if already running
{
my ($subsys, $group, $pid, $status) = split(' ', $output[1]);
if (defined($status) && $status eq 'active')
{ # already running
return 0;
}
else
{ # not running, start it
$cmd = "/usr/bin/startsrc -s $service";
system $cmd; # note using system here to see output when
# daemon comes up
if ($? > 0)
{
xCAT::MsgUtils->message("S",
"Error on command: $cmd\n");
return 1;
}
}
}
}
else # force start
{
$cmd = "/usr/bin/stopsrc -s $service";
system $cmd; # note using system here to see output when
# daemon comes up
if ($? > 0)
{
xCAT::MsgUtils->message("S", "Error on command: $cmd\n");
}
$cmd = "/usr/bin/startsrc -s $service";
system $cmd;
if ($? > 0)
{
xCAT::MsgUtils->message("S", "Error on command: $cmd\n");
return 1;
}
}
}
else # linux
{
if (!($force))
{ # check to see if started, and exit if started
my @output = xCAT::Utils->runcmd("service $service status", -1);
if ($::RUNCMD_RC == 0)
{ # no error, means running for some
# services
if (($service ne "conserver") && ($service ne "nfs"))
{
return 0;
}
if (($service eq "conserver") || ($service eq "nfs"))
{
# must check output
if (grep(/running/, @output))
{
return 0;
}
}
}
# not running start
$cmd = "service $service start";
system $cmd;
if ($? > 0)
{ # error
xCAT::MsgUtils->message("S", "Error on command: $cmd\n");
return 1;
}
else
{
if ($service eq "conserver")
{ # does not give bad return
my @output =
xCAT::Utils->runcmd("service $service status", -1);
if (!(grep(/running/, @output)))
{
xCAT::MsgUtils->message("S",
"Error on command: $cmd\n");
return 1;
}
}
}
}
else
{ # force stop and start
$cmd = "service $service stop";
system $cmd;
if ($? > 0)
{ # error
xCAT::MsgUtils->message("S", "Error on command: $cmd\n");
}
$cmd = "service $service start";
system $cmd;
if ($? > 0)
{ # error
xCAT::MsgUtils->message("S", "Error on command: $cmd\n");
return 1;
}
}
}
return $rc;
}
#-------------------------------------------------------------------------------
=head3 CheckVersion
Checks the two versions numbers to see which one is greater.
Arguments:
@ -3202,5 +3390,4 @@ sub CheckVersion {
}
1;

View File

@ -7,12 +7,23 @@ use xCAT::Table;
use xCAT::Utils;
use xCAT::MsgUtils;
use xCAT_plugin::dhcp;
use xCAT_plugin::conserver;
use File::Path;
use Getopt::Long;
#-------------------------------------------------------
=head1
=head1 AAsn
This is the Service Node Plugin, although it does perform a few functions on
the Management Node.
It reads the servicenode table for the service node it is running on,
and run the appropriate
setup routine for each service that is designated to be setup in the
servicenode table for this service node. Some functions are only done for
Linux.
A few functions are done not based on the servicenode table. For example:
mounts /install if site.installloc set
on a Linux Service Node
@ -21,8 +32,18 @@ use Getopt::Long;
=head3 handled_commands
If bypassmode then exit
If xcat daemon reload then exit
Check to see if on a Service Node
Call mountInstall
If Linux
Call mountInstall
If this is a service Node
Read Service Node Table
For each service returned to be setup
Call the appropriate setup_service routine
else if on the Management Node
Do any Management Node setup of services needed
=cut
@ -31,14 +52,18 @@ Call mountInstall
sub handled_commands
{
# If called in XCATBYPASS mode, don't do any setup
if ($ENV{'XCATBYPASS'}) {
return 0;
}
if (xCAT::Utils->isAIX()) { # do not run on AIX
return 0;
if ($ENV{'XCATBYPASS'})
{
return 0;
}
# If a xcat daemon reload, don't do any setup
if ($ENV{'XCATRELOAD'})
{
return 0;
}
my $rc = 0;
@ -47,13 +72,163 @@ sub handled_commands
my @nodeinfo = xCAT::Utils->determinehostname;
my $nodename = pop @nodeinfo; # get hostname
my @nodeipaddr = @nodeinfo; # get ip addresses
my $service = "mountInstall";
my $service;
# service needed on this Service Node
$rc = &mountInstall($nodename); # setup NFS
if ($rc == 0)
if (xCAT::Utils->isLinux())
{
xCAT::Utils->update_xCATSN($service);
# service needed on Linux Service Node
$service = "mountInstall";
$rc = &mountInstall($nodename); # mount install
if ($rc == 0)
{
xCAT::Utils->update_xCATSN($service);
}
$service = "ssh";
$rc = &setup_SSH(); # setup SSH
if ($rc == 0)
{
xCAT::Utils->update_xCATSN($service);
}
}
# read the service node table
# for a list of all functions to setup for this service node
#
my @servicelist = xCAT::Utils->isServiceReq($nodename, \@nodeipaddr);
if ($::RUNCMD_RC == 0)
{
if (xCAT::Utils->isLinux())
{ #run only the following only on Linux
my $service = "conserver";
if (grep(/$service/, @servicelist))
{
$rc = &setup_CONS($nodename); # setup conserver
if ($rc == 0)
{
xCAT::Utils->update_xCATSN($service);
}
}
$service = "dhcpserver";
if (grep(/$service/, @servicelist))
{
$rc = &setup_DHCP($nodename); # setup DHCP
if ($rc == 0)
{
xCAT::Utils->update_xCATSN($service);
}
}
$service = "ftpserver";
if (grep(/$service/, @servicelist))
{
# make sure ftpserver not tftpserver
my $match = 0;
foreach my $service (@servicelist)
{
if ($service eq "ftpserver")
{
$match = 1;
}
}
if ($match == 1)
{ # it was ftpserver
$rc = &setup_FTP(); # setup vsftpd
if ($rc == 0)
{
xCAT::Utils->update_xCATSN($service);
}
}
}
$service = "ldapserver";
if (grep(/$service/, @servicelist))
{
$rc = &setup_LDAP(); # setup LDAP
if ($rc == 0)
{
xCAT::Utils->update_xCATSN($service);
}
}
$service = "tftpserver";
if (grep(/$service/, @servicelist))
{
$rc = &setup_TFTP($nodename); # setup TFTP
if ($rc == 0)
{
xCAT::Utils->update_xCATSN($service);
}
}
} # end Linux only
#
# setup these services for AIX or Linux
#
my $service = "nameserver";
if (grep(/$service/, @servicelist))
{
$rc = &setup_DNS(); # setup DNS
if ($rc == 0)
{
xCAT::Utils->update_xCATSN($service);
}
}
$service = "nfsserver";
if (grep(/$service/, @servicelist))
{
$rc = &setup_NFS($nodename); # setup NFS
if ($rc == 0)
{
xCAT::Utils->update_xCATSN($service);
}
}
# done now in setupntp postinstall script, but may change
#$service = "ntpserver";
#if (grep(/$service/, @servicelist))
#{
# $rc = &setup_NTPsn($nodename); # setup NTP on SN
# if ($rc == 0)
# {
# xCAT::Utils->update_xCATSN($service);
# }
#}
}
else
{ # error from servicenode tbl read
xCAT::MsgUtils->message("S",
"AAsn.pm:Error reading the servicenode table.");
}
}
else # management node
{
# $rc = &setup_NTPmn(); # setup NTP on the Management Node
if (xCAT::Utils->isLinux())
{
$rc = &setup_FTP(); # setup FTP
}
}
return $rc;
@ -88,7 +263,7 @@ sub mountInstall
my ($nodename) = @_;
my $rc = 0;
my $installdir = "/install"; # default
my $installloc = "/install"; # default
my $installloc = "/install"; # default
# read DB for nodeinfo
my $master;
@ -105,19 +280,22 @@ sub mountInstall
# read install directory and install location from database,
# if they exists
my @installlocation= xCAT::Utils->get_site_attribute("installloc");
my @installlocation = xCAT::Utils->get_site_attribute("installloc");
my $hostname;
my $path;
if ($installlocation[0])
{
if (grep /:/, $installlocation[0]){
my ($hostname, $installloc) = split ":",$installlocation[0];
if ($hostname)
{ # hostname set in /installloc attribute
$master = $hostname; # set name for mount
}
} else {
$installloc=$installlocation[0];
if (grep /:/, $installlocation[0])
{
my ($hostname, $installloc) = split ":", $installlocation[0];
if ($hostname)
{ # hostname set in /installloc attribute
$master = $hostname; # set name for mount
}
}
else
{
$installloc = $installlocation[0];
}
}
else
@ -144,7 +322,7 @@ sub mountInstall
{ # not mounted
# need to mount the directory
my $cmd= "mount -o rw,nolock $master:$installloc $installdir";
my $cmd = "mount -o rw,nolock $master:$installloc $installdir";
system $cmd;
if ($? > 0)
{ # error
@ -173,4 +351,588 @@ sub mountInstall
return $rc;
}
#-----------------------------------------------------------------------------
=head3 setup_CONS
Sets up Conserver
=cut
#-----------------------------------------------------------------------------
sub setup_CONS
{
my ($nodename) = @_;
my $rc = 0;
# read DB for nodeinfo
my $master;
my $os;
my $arch;
my $cmd;
my $retdata = xCAT::Utils->readSNInfo($nodename);
if ($retdata->{'arch'})
{ # no error
$master = $retdata->{'master'};
$os = $retdata->{'os'};
$arch = $retdata->{'arch'};
# make the consever 8 configuration file
my $cmdref;
$cmdref->{command}->[0] = "makeconservercf";
$cmdref->{cwd}->[0] = "/opt/xcat/sbin";
$cmdref->{svboot}->[0] = "yes";
my $modname = "conserver";
${"xCAT_plugin::" . $modname . "::"}{process_request}
->($cmdref, \&xCAT::Client::handle_response);
# start conserver. conserver needs 2 CA files to start
my $ca_file1 = "/etc/xcat/ca/ca-cert.pem";
my $ca_file2 = "/etc/xcat/cert/server-cred.pem";
if (!-e $ca_file1)
{
print
"conserver cannot be started because the file $ca_file1 cannot be found\n";
}
elsif (!-e $ca_file2)
{
print
"conserver cannot be started because the file $ca_file2 cannot be found\n";
}
else
{
my $rc = xCAT::Utils->startService("conserver");
if ($rc != 0)
{
return 1;
}
}
}
else
{ # error reading Db
$rc = 1;
}
return $rc;
}
#-----------------------------------------------------------------------------
=head3 setup_DHCP
Sets up DHCP services
=cut
#-----------------------------------------------------------------------------
sub setup_DHCP
{
my ($nodename) = @_;
my $rc = 0;
my $cmd;
# run makedhcp
$XCATROOT = "/opt/xcat"; # default
if ($ENV{'XCATROOT'})
{
$XCATROOT = $ENV{'XCATROOT'};
}
my $cmdref;
$cmdref->{command}->[0] = "makedhcp";
$cmdref->{cwd}->[0] = "/opt/xcat/sbin";
$cmdref->{arg}->[0] = "-n";
my $modname = "dhcp";
${"xCAT_plugin::" . $modname . "::"}{process_request}
->($cmdref, \&xCAT::Client::handle_response);
my $rc = xCAT::Utils->startService("dhcpd");
if ($rc != 0)
{
return 1;
}
$cmdref;
$cmdref->{command}->[0] = "makedhcp";
$cmdref->{cwd}->[0] = "/opt/xcat/sbin";
$cmdref->{arg}->[0] = "-a";
my $modname = "dhcp";
${"xCAT_plugin::" . $modname . "::"}{process_request}
->($cmdref, \&xCAT::Client::handle_response);
return $rc;
}
#-----------------------------------------------------------------------------
=head3 setup_FTP
Sets up FTP services (vstftp)
=cut
#-----------------------------------------------------------------------------
sub setup_FTP
{
my $rc = 0;
my $cmd;
$XCATROOT = "/opt/xcat"; # default
if ($ENV{'XCATROOT'})
{
$XCATROOT = $ENV{'XCATROOT'};
}
# change ftp user id home directory to installdir
# link installdir
# restart the daemon
my $installdir = "/install"; # default
# read from database
my @installdir1 = xCAT::Utils->get_site_attribute("installdir");
if ($installdir1[0]) # if exists
{
$installdir = $installdir1[0];
}
if (!(-e $installdir)) # make it
{
mkpath($installdir);
}
$cmd = "usermod -d $installdir ftp";
my $outref = xCAT::Utils->runcmd($cmd, 0);
if ($::RUNCMD_RC)
{
xCAT::MsgUtils->message("S", "Error from command:$cmd");
}
# start tftp
my $rc = xCAT::Utils->startService("vsftpd");
if ($rc != 0)
{
return 1;
}
return $rc;
}
#-----------------------------------------------------------------------------
=head3 setup_DNS
Sets up Domain Name service
http://www.adminschoice.com/docs/domain_name_service.htm#Introduction
=cut
#-----------------------------------------------------------------------------
sub setup_DNS
{
# setup the named.conf file
system("/opt/xcat/sbin/makenamed.conf");
# turn DNS on
my $rc = xCAT::Utils->startService("named");
if ($rc != 0)
{
return 1;
}
return 0;
}
#-----------------------------------------------------------------------------
=head3 setup_LDAP
Sets up LDAP
=cut
#-----------------------------------------------------------------------------
sub setup_LDAP
{
my $rc = xCAT::Utils->startService("ldap");
if ($rc != 0)
{
return 1;
}
return 0;
}
#-----------------------------------------------------------------------------
=head3 setup_NFS
Sets up NFS services on Service Node for AIX and Linux
=cut
#-----------------------------------------------------------------------------
sub setup_NFS
{
my ($nodename) = @_;
my $rc = 0;
# make sure nfs is restarted
my $rc = 0;
if (xCAT::Utils->isLinux())
{
$rc = xCAT::Utils->startService("nfs");
}
else
{ #AIX
$rc = xCAT::Utils->startService("nfsd");
}
if ($rc != 0)
{
return 1;
}
return $rc;
}
#-----------------------------------------------------------------------------
=head3 setup_NTPsn
Sets up NTP services on service node
=cut
#-----------------------------------------------------------------------------
sub setup_NTPsn
{
my ($nodename) = @_;
my $rc = 0;
my $cmd;
my $master;
my $os;
my $arch;
my $ntpcfg = "/etc/ntp.conf";
# read DB for nodeinfo
my $retdata = xCAT::Utils->readSNInfo($nodename);
$master = $retdata->{'master'};
$os = $retdata->{'os'};
$arch = $retdata->{'arch'};
if (!($arch))
{ # error
xCAT::MsgUtils->message("S", " Error reading service node info.");
return 1;
}
# backup the existing config file
$rc = &backup_NTPconf();
if ($rc == 0)
{
# create config file
open(CFGFILE, ">$ntpcfg")
or xCAT::MsgUtils->message('SE',
"Cannot open $configfile for NTP update. \n");
print CFGFILE "server ";
print CFGFILE $master;
print CFGFILE "\n";
print CFGFILE "driftfile /var/lib/ntp/drift\n";
print CFGFILE "restrict 127.0.0.1\n";
close CFGFILE;
$rc = &start_NTP(); # restart ntp
}
return $rc;
}
#-----------------------------------------------------------------------------
=head3 setup_NTPmn
Sets up NTP services on Management Node
Get ntpservers from site table. If they do not exist, warn cannot setup NTP
=cut
#-----------------------------------------------------------------------------
sub setup_NTPmn
{
my $rc = 0;
my $ntpcfg = "/etc/ntp.conf";
# get timeservers from site table
my @ntpservers = xCAT::Utils->get_site_attribute("ntpservers");
if ($ntpservers[0])
{
# backup the existing config file
$rc = &backup_NTPconf();
if ($rc == 0)
{
# add server names
open(CFGFILE, ">$ntpcfg")
or xCAT::MsgUtils->message('SE',
"Cannot open $configfile for NTP update. \n");
my @servers = split ',', $ntpservers[0];
foreach my $addr (@servers)
{
print CFGFILE "server ";
print CFGFILE $addr;
print CFGFILE "\n";
}
print CFGFILE "driftfile /var/lib/ntp/drift\n";
print CFGFILE "restrict 127.0.0.1\n";
close CFGFILE;
$rc = &start_NTP(); # restart ntp
}
}
else
{ # no servers defined
xCAT::MsgUtils->message(
"S",
"No NTP servers defined in the ntpservers attribute in the site table.\n"
);
return 1;
}
return $rc;
}
#-----------------------------------------------------------------------------
=head3 start_NTP
Starts daemon
=cut
#-----------------------------------------------------------------------------
sub start_NTP
{
my $rc = xCAT::Utils->startService("ntpd");
if ($rc != 0)
{
return 1;
}
return 0;
}
#-----------------------------------------------------------------------------
=head3 backup_NTPconf
backup configuration
=cut
#-----------------------------------------------------------------------------
sub backup_NTPconf
{
my $ntpcfg = "/etc/ntp.conf";
my $ntpcfgbackup = "/etc/ntp.conf.orig";
my $ntpxcatcfgbackup = "/etc/ntp.conf.xcatbackup";
if (!-e $ntpcfgbackup)
{ # if original backup does not already exist
my $cmd = "mv $ntpcfg $ntpcfgbackup";
system $cmd;
if ($? > 0)
{
xCAT::MsgUtils->message("S", "Error from command:$cmd");
return 1;
}
}
else
{ # backup xcat cfg
my $cmd = "mv $ntpcfg $ntpxcatcfgbackup";
system $cmd;
if ($? > 0)
{
xCAT::MsgUtils->message("S", "Error from command:$cmd");
return 1;
}
}
return 0;
}
#-----------------------------------------------------------------------------
=head3 setup_SSH
Sets up SSH default configuration for root
Turns strict host checking off
=cut
#-----------------------------------------------------------------------------
sub setup_SSH
{
my $configfile;
my $cmd;
my $configinfo;
my $sshdir;
my $cmd;
# build the $HOMEROOT/.ssh/config
if (xCAT::Utils->isLinux())
{
$configfile = "/root/.ssh/config";
$sshdir = "/root/.ssh";
}
else
{ #AIX
$configfile = "/.ssh/config";
$sshdir = "/.ssh";
}
if (!(-e $sshdir))
{ # directory does not exits
mkdir($sshdir, 0700);
}
$configinfo = "StrictHostKeyChecking no";
if (-e $configfile)
{
$cmd = "grep StrictHostKeyChecking $configfile";
xCAT::Utils->runcmd($cmd, -1);
if ($::RUNCMD_RC != 0)
{ # not there
$cmd = "echo $configinfo >> $configfile";
my @output = xCAT::Utils->runcmd($cmd, 0);
if ($::RUNCMD_RC != 0)
{ # error
xCAT::MsgUtils->message("S", "Error on $cmd, @output");
return 1;
}
}
}
else # file does not exist
{
$cmd = "echo $configinfo >> $configfile";
my @output = xCAT::Utils->runcmd($cmd, 0);
if ($::RUNCMD_RC != 0)
{ # error
xCAT::MsgUtils->message("S", "Error on $cmd, @output");
return 1;
}
else
{
chmod 0600, $configfile;
}
}
return 0;
}
#-----------------------------------------------------------------------------
=head3 setup_TFTP
Sets up TFTP services (using atftp)
=cut
#-----------------------------------------------------------------------------
sub setup_TFTP
{
my ($nodename) = @_;
my $rc = 0;
my $tftpdir = "/tftpboot"; # default
my $cmd;
my $master;
my $os;
my $arch;
$XCATROOT = "/opt/xcat"; # default
if ($ENV{'XCATROOT'})
{
$XCATROOT = $ENV{'XCATROOT'};
}
# read DB for nodeinfo
my $retdata = xCAT::Utils->readSNInfo($nodename);
$master = $retdata->{'master'};
$os = $retdata->{'os'};
$arch = $retdata->{'arch'};
if (!($arch))
{ # error
xCAT::MsgUtils->message("S", " Error reading service node arch.");
return 1;
}
# check to see if atftp is installed
$cmd = "/usr/sbin/in.tftpd -V";
my @output = xCAT::Utils->runcmd($cmd, -1);
if ($::RUNCMD_RC != 0)
{ # not installed
xCAT::MsgUtils->message("S", "atftp is not installed");
return 1;
}
if ($output[0] =~ "atftp") # it is atftp
{
# read tftpdir directory from database
my @tftpdir1 = xCAT::Utils->get_site_attribute("tftpdir");
if ($tftpdir1[0])
{
$tftpdir = $tftpdir1[0];
}
if (!(-e $tftpdir))
{
mkdir($tftpdir);
}
# check to see if tftp directory already mounted
my $mounted = xCAT::Utils->isMounted($tftpdir);
if ($mounted == 0) # not already mounted
{
# need to mount the directory
my $cmd = " mount -o rw,nolock $master:$tftpdir $tftpdir";
system $cmd;
if ($? > 0)
{ # error
$rc = 1;
xCAT::MsgUtils->message("S", "Error $cmd");
}
}
# start atftp
my $rc = xCAT::Utils->startService("tftpd");
if ($rc != 0)
{
return 1;
}
}
else
{ # no ATFTP
xCAT::MsgUtils->message("S", "atftp is not installed");
return 1;
}
if ($rc == 0)
{
# update fstab so that it will restart on reboot
$cmd =
"fgrep \"$master:$tftpdir $tftpdir nfs timeo=14,intr 1 2\" /etc/fstab";
xCAT::Utils->runcmd($cmd, -1);
if ($::RUNCMD_RC != 0) # not already there
{
`echo "$master:$tftpdir $tftpdir nfs timeo=14,intr 1 2" >>/etc/fstab`;
}
}
return $rc;
}
1;

View File

@ -1,172 +0,0 @@
#!/usr/bin/env perl
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
#-------------------------------------------------------
package xCAT_plugin::CONSsn;
use xCAT::Table;
use xCAT::Utils;
use xCAT_plugin::conserver;
use xCAT::Client;
use xCAT::MsgUtils;
use Getopt::Long;
#-------------------------------------------------------
=head1
xCAT plugin package to setup conserver
#-------------------------------------------------------
=head3 handled_commands
Only for Linux now
Check to see if on a Service Node
Check database to see if this node is going to have Conserver setup
should be always
Call setup_CONS
=cut
#-------------------------------------------------------
sub handled_commands
{
# If called in XCATBYPASS mode, don't do any setup
if ($ENV{'XCATBYPASS'}) {
return 0;
}
if (xCAT::Utils->isAIX()) { # do not run on AIX
return 0;
}
my $rc = 0;
if (xCAT::Utils->isServiceNode())
{
my @nodeinfo = xCAT::Utils->determinehostname;
my $nodename = pop @nodeinfo; # get hostname
my @nodeipaddr = @nodeinfo; # get ip addresses
my $service = "conserver";
$rc = xCAT::Utils->isServiceReq($nodename, $service, \@nodeipaddr);
if ($rc == 1)
{
# service needed on this Service Node
$rc = &setup_CONS($nodename); # setup CONS
if ($rc == 0)
{
xCAT::Utils->update_xCATSN($service);
}
}
else
{
if ($rc == 2)
{
# already setup, just start the daemon
# start conserver
my $cmd;
if (-f "/var/run/conserver.pid") {
$cmd = "/etc/init.d/conserver restart";
} else {
$cmd = "/etc/init.d/conserver start";
}
xCAT::Utils->runcmd($cmd, -1);
}
}
}
return $rc;
}
#-------------------------------------------------------
=head3 process_request
Process the command
=cut
#-------------------------------------------------------
sub process_request
{
return;
}
#-----------------------------------------------------------------------------
=head3 setup_CONS
Sets up Conserver
=cut
#-----------------------------------------------------------------------------
sub setup_CONS
{
my ($nodename) = @_;
my $rc = 0;
# read DB for nodeinfo
my $master;
my $os;
my $arch;
my $cmd;
my $retdata = xCAT::Utils->readSNInfo($nodename);
if ($retdata->{'arch'})
{ # no error
$master = $retdata->{'master'};
$os = $retdata->{'os'};
$arch = $retdata->{'arch'};
# make the consever 8 configuration file
my $cmdref;
$cmdref->{command}->[0] = "makeconservercf";
$cmdref->{cwd}->[0] = "/opt/xcat/sbin";
$cmdref->{svboot}->[0] = "yes";
my $modname = "conserver";
${"xCAT_plugin::" . $modname . "::"}{process_request}
->($cmdref, \&xCAT::Client::handle_response);
my $cmd = "chkconfig conserver on";
xCAT::Utils->runcmd($cmd, 0);
if ($::RUNCMD_RC != 0)
{ # error
xCAT::MsgUtils->message("S", "Error chkconfig conserver on");
return 1;
}
# start conserver. conserver needs 2 CA files to start
my $ca_file1="/etc/xcat/ca/ca-cert.pem";
my $ca_file2="/etc/xcat/cert/server-cred.pem";
if (! -e $ca_file1) {
print "conserver cannot be started because the file $ca_file1 cannot be found\n";
} elsif (! -e $ca_file2) {
print "conserver cannot be started because the file $ca_file2 cannot be found\n";
} else {
my $cmd;
if (-f "/var/run/conserver.pid") {
$cmd = "/etc/init.d/conserver restart";
} else {
$cmd = "/etc/init.d/conserver start";
}
my @out = xCAT::Utils->runcmd($cmd, 0);
if ($::RUNCMD_RC != 0)
{ # error
xCAT::MsgUtils->message("S", "Error restarting conserver:".join("\n", @out));
} else { # Zero rc, but with the service cmds that does not mean they succeeded
my $output = join("\n", @out);
if (length($output)) { print "\n$output\n"; }
else { print "\nconserver restarted\n"; }
}
}
}
else
{ # error reading Db
$rc = 1;
}
return $rc;
}
1;

View File

@ -1,155 +0,0 @@
#!/usr/bin/env perl
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
#-------------------------------------------------------
package xCAT_plugin::DHCPsn;
use xCAT::Table;
use xCAT::Utils;
use xCAT_plugin::dhcp;
use xCAT::MsgUtils;
use xCAT::Client;
use Getopt::Long;
#-------------------------------------------------------
=head1
xCAT plugin package to setup of DHCP
#-------------------------------------------------------
=head3 handled_commands
Check to see if on a Linux Service Node
Check database to see if this node is a DHCP server
Call setup_DHCP
=cut
#-------------------------------------------------------
sub handled_commands
{
# If called in XCATBYPASS mode, don't do any setup
if ($ENV{'XCATBYPASS'}) {
return 0;
}
if (xCAT::Utils->isAIX()) { # do not run on AIX
return 0;
}
my $rc = 0;
if (xCAT::Utils->isServiceNode())
{
my @nodeinfo = xCAT::Utils->determinehostname;
my $nodename = pop @nodeinfo; # get hostname
my @nodeipaddr = @nodeinfo; # get ip addresses
my $service = "dhcpserver";
$rc = xCAT::Utils->isServiceReq($nodename, $service, \@nodeipaddr);
if ($rc == 1)
{
# service needed on this Service Node
$rc = &setup_DHCP($nodename); # setup DHCP
if ($rc == 0)
{
xCAT::Utils->update_xCATSN($service);
}
}
else
{
if ($rc == 2)
{ # setup, just start the daemon
$cmd = " service dhcpd restart";
system $cmd;
if ($? > 0)
{ # error
xCAT::MsgUtils->message("S", "Error on command: $cmd");
return 1;
}
}
}
}
return $rc;
}
#-------------------------------------------------------
=head3 process_request
Process the command
=cut
#-------------------------------------------------------
sub process_request
{
return;
}
#-----------------------------------------------------------------------------
=head3 setup_DHCP
Sets up DHCP services
=cut
#-----------------------------------------------------------------------------
sub setup_DHCP
{
my ($nodename) = @_;
my $rc = 0;
my $cmd;
# run makedhcp
$XCATROOT = "/opt/xcat"; # default
if ($ENV{'XCATROOT'})
{
$XCATROOT = $ENV{'XCATROOT'};
}
my $cmdref;
$cmdref->{command}->[0] = "makedhcp";
$cmdref->{cwd}->[0] = "/opt/xcat/sbin";
$cmdref->{arg}->[0] = "-n";
my $modname = "dhcp";
${"xCAT_plugin::" . $modname . "::"}{process_request}
->($cmdref, \&xCAT::Client::handle_response);
$cmd = "chkconfig dhcpd on";
system $cmd;
if ($? > 0)
{ # error
xCAT::MsgUtils->message("S", "Error from $cmd");
return 1;
}
$cmd = "service dhcpd restart";
system $cmd;
if ($? > 0)
{
xCAT::MsgUtils->message("S", "Error from $cmd");
return 1;
}
$cmdref;
$cmdref->{command}->[0] = "makedhcp";
$cmdref->{cwd}->[0] = "/opt/xcat/sbin";
$cmdref->{arg}->[0] = "-a";
my $modname = "dhcp";
${"xCAT_plugin::" . $modname . "::"}{process_request}
->($cmdref, \&xCAT::Client::handle_response);
return $rc;
}
1;

View File

@ -1,137 +0,0 @@
#!/usr/bin/env perl
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
#-------------------------------------------------------
package xCAT_plugin::DNSsn;
use xCAT::Table;
use xCAT::Utils;
use xCAT::MsgUtils;
use Getopt::Long;
#-------------------------------------------------------
=head1
xCAT plugin package to setup of DNS on Linux and AIX service nodes
#-------------------------------------------------------
=head3 handled_commands
Check to see if on a Service Node
Check database to see if this node is a DNS server
Call setup_DNS
=cut
#-------------------------------------------------------
sub handled_commands
{
# If called in XCATBYPASS mode, don't do any setup
if ($ENV{'XCATBYPASS'}) {
return 0;
}
my $rc = 0;
if (xCAT::Utils->isServiceNode())
{
my @nodeinfo = xCAT::Utils->determinehostname;
my $nodename = pop @nodeinfo; # get hostname
my @nodeipaddr = @nodeinfo; # get ip addresses
my $service = "nameserver";
$rc = xCAT::Utils->isServiceReq($nodename, $service, \@nodeipaddr);
if ($rc == 1)
{
# service needed on this Service Node
$rc = &setup_DNS(); # setup DNS
if ($rc == 0)
{
xCAT::Utils->update_xCATSN($service);
}
}
else
{
if ($rc == 2)
{ # service setup, just start the daemon
if (xCAT::Utils->isLinux()) {
system "service named restart";
} else { # AIX
system "stopsrc -s named";
system "startsrc -s named";
}
system $cmd;
if ($? > 0)
{ # error
xCAT::MsgUtils->message("S", "Error on command: $cmd");
return 1;
}
}
}
}
return $rc;
}
#-------------------------------------------------------
=head3 process_request
Process the command
=cut
#-------------------------------------------------------
sub process_request
{
return;
}
#-----------------------------------------------------------------------------
=head3 setup_DNS
Sets up Domain Name service
http://www.adminschoice.com/docs/domain_name_service.htm#Introduction
=cut
#-----------------------------------------------------------------------------
sub setup_DNS
{
# setup the named.conf file
system("/opt/xcat/sbin/makenamed.conf");
# turn DNS on
if (xCAT::Utils->isLinux()) {
$cmd = "chkconfig named on";
system $cmd;
if ($? > 0)
{
xCAT::MsgUtils->message("S", "Error from $cmd");
return 1;
}
}
if (xCAT::Utils->isLinux()) {
$cmd = "service named restart";
system $cmd;
} else {
$cmd = "stopsrc -s named";
system $cmd;
$cmd = "startsrc -s named";
system $cmd;
}
if ($? > 0)
{
xCAT::MsgUtils->message("S", "Error from $cmd");
return 1;
}
return 0;
}
1;

View File

@ -1,153 +0,0 @@
#!/usr/bin/env perl
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
#-------------------------------------------------------
package xCAT_plugin::FTPsn;
use xCAT::Table;
use xCAT::Utils;
use File::Basename;
use File::Path;
use xCAT::MsgUtils;
use Getopt::Long;
#-------------------------------------------------------
=head1
xCAT plugin package to setup vstftp on a Linux service node
#-------------------------------------------------------
=head3 handled_commands
This runs on Linux Service Node
Checks servicenode table ftpserver attribute
Call setup_TFTP (actually setting up vstftp)
=cut
#-------------------------------------------------------
sub handled_commands
{
# If called in XCATBYPASS mode, don't do any setup
if ($ENV{'XCATBYPASS'}) {
return 0;
}
if (xCAT::Utils->isAIX()) { # do not run on AIX
return 0;
}
my $rc = 0;
# setup vstftp
if (xCAT::Utils->isServiceNode())
{
my @nodeinfo = xCAT::Utils->determinehostname;
my $nodename = pop @nodeinfo; # get hostname
my @nodeipaddr = @nodeinfo; # get ip addresses
my $service = "ftpserver";
$rc = xCAT::Utils->isServiceReq($nodename, $service, \@nodeipaddr);
if ($rc == 1)
{
$rc = &setup_FTP(); # setup vsftpd
if ($rc == 0)
{
xCAT::Utils->update_xCATSN($service);
}
}
else
{
if ($rc == 2)
{ # just start the daemon
my $cmd = "service vsftpd restart";
system $cmd;
if ($? > 0)
{ # error
xCAT::MsgUtils->message("S", "Error on command: $cmd");
return 1;
}
}
}
} else { # Management Node
$rc = &setup_FTP(); # setup vsftpd
}
return $rc;
}
#-------------------------------------------------------
=head3 process_request
Process the command
=cut
#-------------------------------------------------------
sub process_request
{
return;
}
#-----------------------------------------------------------------------------
=head3 setup_FTP
Sets up FTP services (vstftp)
=cut
#-----------------------------------------------------------------------------
sub setup_FTP
{
my $rc = 0;
my $cmd;
$XCATROOT = "/opt/xcat"; # default
if ($ENV{'XCATROOT'})
{
$XCATROOT = $ENV{'XCATROOT'};
}
# change ftp user id home directory to installdir
# link installdir
# restart the daemon
my $installdir = "/install"; # default
# read from database
my @installdir1 = xCAT::Utils->get_site_attribute("installdir");
if ($installdir1[0]) # if exists
{
$installdir = $installdir1[0];
}
if (!(-e $installdir)) # make it
{
mkpath($installdir);
}
$cmd = "usermod -d $installdir ftp";
my $outref = xCAT::Utils->runcmd($cmd,0);
if ($::RUNCMD_RC) {
xCAT::MsgUtils->message("S", "Error from command:$cmd");
}
# restart tftp
my $cmd = "service vsftpd restart";
system $cmd;
if ($? > 0)
{
xCAT::MsgUtils->message("S", "Error from command:$cmd");
return 1;
}
my $cmd = "chkconfig vsftpd on";
system $cmd;
if ($? > 0)
{
xCAT::MsgUtils->message("S", "Error from command:$cmd");
return 1;
}
return $rc;
}
1;

View File

@ -1,119 +0,0 @@
#!/usr/bin/env perl
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
#-------------------------------------------------------
package xCAT_plugin::LDAPsn;
use xCAT::Table;
use xCAT::Utils;
use xCAT::MsgUtils;
use Getopt::Long;
#-------------------------------------------------------
=head1
xCAT plugin package to setup of LDAP on the Linux ServiceNode
#-------------------------------------------------------
=head3 handled_commands
Check to see if on a Service Node
Check database to see if this node is a LDAP server
Call setup_LDAP
=cut
#-------------------------------------------------------
sub handled_commands
{
# If called in XCATBYPASS mode, don't do any setup
if ($ENV{'XCATBYPASS'}) {
return 0;
}
if (xCAT::Utils->isAIX()) { # do not run on AIX
return 0;
}
my $rc = 0;
if (xCAT::Utils->isServiceNode())
{
my @nodeinfo = xCAT::Utils->determinehostname;
my $nodename = pop @nodeinfo; # get hostname
my @nodeipaddr = @nodeinfo; # get ip addresses
my $service = "ldapserver";
$rc = xCAT::Utils->isServiceReq($nodename, $service, \@nodeipaddr);
if ($rc == 1)
{
# service needed on this Service Node
$rc = &setup_LDAP();
if ($rc == 0)
{
xCAT::Utils->update_xCATSN($service);
}
}
else
{
if ($rc == 2)
{ # service setup, just start the daemon
$cmd = "service ldap restart";
system $cmd;
if ($? > 0)
{
xCAT::MsgUtils->message("S", "Error from $cmd");
return 1;
}
}
}
}
return $rc;
}
#-------------------------------------------------------
=head3 process_request
Process the command
=cut
#-------------------------------------------------------
sub process_request
{
return;
}
#-----------------------------------------------------------------------------
=head3 setup_LDAP
Sets up LDAP
=cut
#-----------------------------------------------------------------------------
sub setup_LDAP
{
$cmd = "chkconfig ldap on";
system $cmd;
if ($? > 0)
{
xCAT::MsgUtils->message("S", "Error from $cmd");
return 1;
}
$cmd = "service ldap restart";
system $cmd;
if ($? > 0)
{
xCAT::MsgUtils->message("S", "Error from $cmd");
return 1;
}
return 0;
}
1;

View File

@ -1,129 +0,0 @@
#!/usr/bin/env perl
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
#-------------------------------------------------------
package xCAT_plugin::NFSsn;
use xCAT::Table;
use xCAT::Utils;
use xCAT::MsgUtils;
use File::Path;
use Getopt::Long;
#-------------------------------------------------------
=head1
xCAT plugin package to start nfs on the Linux of AIX Service Node
#-------------------------------------------------------
=head3 handled_commands
Check to see if on a Service Node
Check database to see if this node is a NFS server
Call setup_NFS
=cut
#-------------------------------------------------------
sub handled_commands
{
# If called in XCATBYPASS mode, don't do any setup
if ($ENV{'XCATBYPASS'}) {
return 0;
}
my $rc = 0;
if (xCAT::Utils->isServiceNode())
{
my @nodeinfo = xCAT::Utils->determinehostname;
my $nodename = pop @nodeinfo; # get hostname
my @nodeipaddr = @nodeinfo; # get ip addresses
my $service = "nfsserver";
$rc = xCAT::Utils->isServiceReq($nodename, $service, \@nodeipaddr);
if ($rc == 1)
{
# service needed on this Service Node
$rc = &setup_NFS($nodename); # setup NFS
if ($rc == 0)
{
xCAT::Utils->update_xCATSN($service);
}
}
else
{
if ($rc == 2)
{ # just start the daemon
if (xCAT::Utils->isLinux()) {
system "service nfs restart";
} else { # AIX
system "stopsrc -s nfsd";
system "startsrc -s nfsd";
}
if ($? > 0)
{ # error
xCAT::MsgUtils->message("S", "Error on command: $cmd");
return 1;
}
}
}
}
return $rc;
}
#-------------------------------------------------------
=head3 process_request
Process the command
=cut
#-------------------------------------------------------
sub process_request
{
return;
}
#-----------------------------------------------------------------------------
=head3 setup_NFS
Sets up NFS services on Service Node for AIX and Linux
=cut
#-----------------------------------------------------------------------------
sub setup_NFS
{
my ($nodename) = @_;
my $rc = 0;
if (xCAT::Utils->isLinux()) {
system "chkconfig nfs on";
if ($? > 0)
{ # error
xCAT::MsgUtils->message("S", "Error on command:$cmd");
}
}
# make sure nfs is restarted
if (xCAT::Utils->isLinux()) {
system "service nfs restart";
} else { # AIX
system "stopsrc -s nfsd";
system "startsrc -s nfsd";
}
if ($? > 0)
{
xCAT::MsgUtils->message("S", "Error on command: $cmd");
return 1;
}
return $rc;
}
1;

View File

@ -1,267 +0,0 @@
#!/usr/bin/env perl
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
#-------------------------------------------------------
package xCAT_plugin::NTPsn;
use xCAT::Table;
use xCAT::Utils;
use xCAT::MsgUtils;
use File::Path;
#-------------------------------------------------------
=head1
xCAT plugin package to setup NTP on a Linux service node
#-------------------------------------------------------
=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 and Management node to setup NTP
Checks servicenode table ntpserver attribute
Call setup_NTP
=cut
#-------------------------------------------------------
sub handled_commands
{
# If called in XCATBYPASS mode, don't do any setup
if ($ENV{'XCATBYPASS'}) {
return 0;
}
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
#
# }
return $rc;
}
#-------------------------------------------------------
=head3 process_request
Process the command
=cut
#-------------------------------------------------------
sub process_request
{
return;
}
#-----------------------------------------------------------------------------
=head3 setup_NTPsn
Sets up NTP services on service node
=cut
#-----------------------------------------------------------------------------
sub setup_NTPsn
{
my ($nodename) = @_;
my $rc = 0;
my $cmd;
my $master;
my $os;
my $arch;
my $ntpcfg = "/etc/ntp.conf";
# read DB for nodeinfo
my $retdata = xCAT::Utils->readSNInfo($nodename);
$master = $retdata->{'master'};
$os = $retdata->{'os'};
$arch = $retdata->{'arch'};
if (!($arch))
{ # error
xCAT::MsgUtils->message("S", " Error reading service node info.");
return 1;
}
# backup the existing config file
$rc = &backup_NTPconf();
if ($rc == 0)
{
# create config file
open(CFGFILE, ">$ntpcfg")
or xCAT::MsgUtils->message('SE',
"Cannot open $configfile for NTP update. \n");
print CFGFILE "server ";
print CFGFILE $master;
print CFGFILE "\n";
print CFGFILE "driftfile /var/lib/ntp/drift\n";
print CFGFILE "restrict 127.0.0.1\n";
close CFGFILE;
$rc = &start_NTP(); # restart ntp
}
return $rc;
}
#-----------------------------------------------------------------------------
=head3 setup_NTPmn
Sets up NTP services on Management Node
Get ntpservers from site table. If they do not exist, warn cannot setup NTP
=cut
#-----------------------------------------------------------------------------
sub setup_NTPmn
{
my $rc = 0;
my $ntpcfg = "/etc/ntp.conf";
# get timeservers from site table
my @ntpservers = xCAT::Utils->get_site_attribute("ntpservers");
if ($ntpservers[0])
{
# backup the existing config file
$rc = &backup_NTPconf();
if ($rc == 0)
{
# add server names
open(CFGFILE, ">$ntpcfg")
or xCAT::MsgUtils->message('SE',
"Cannot open $configfile for NTP update. \n");
my @servers = split ',', $ntpservers[0];
foreach my $addr (@servers)
{
print CFGFILE "server ";
print CFGFILE $addr;
print CFGFILE "\n";
}
print CFGFILE "driftfile /var/lib/ntp/drift\n";
print CFGFILE "restrict 127.0.0.1\n";
close CFGFILE;
$rc = &start_NTP(); # restart ntp
}
}
else
{ # no servers defined
xCAT::MsgUtils->message(
"S",
"No NTP servers defined in the ntpservers attribute in the site table.\n"
);
return 1;
}
return $rc;
}
#-----------------------------------------------------------------------------
=head3 start_NTP
Starts daemon
=cut
#-----------------------------------------------------------------------------
sub start_NTP
{
# restart ntp
my $cmd = "service ntpd restart";
system $cmd;
if ($? > 0)
{
xCAT::MsgUtils->message("S", "Error from command:$cmd");
return 1;
}
my $cmd = "chkconfig ntpd on";
system $cmd;
if ($? > 0)
{
xCAT::MsgUtils->message("S", "Error from command:$cmd");
return 1;
}
return 0;
}
#-----------------------------------------------------------------------------
=head3 backup_NTPconf
Starts daemon
=cut
#-----------------------------------------------------------------------------
sub backup_NTPconf
{
my $ntpcfg = "/etc/ntp.conf";
my $ntpcfgbackup = "/etc/ntp.conf.orig";
my $ntpxcatcfgbackup = "/etc/ntp.conf.xcatbackup";
if (!-e $ntpcfgbackup)
{ # if original backup does not already exist
my $cmd = "mv $ntpcfg $ntpcfgbackup";
system $cmd;
if ($? > 0)
{
xCAT::MsgUtils->message("S", "Error from command:$cmd");
return 1;
}
}
else
{ # backup xcat cfg
my $cmd = "mv $ntpcfg $ntpxcatcfgbackup";
system $cmd;
if ($? > 0)
{
xCAT::MsgUtils->message("S", "Error from command:$cmd");
return 1;
}
}
return 0;
}
1;

View File

@ -1,134 +0,0 @@
#!/usr/bin/env perl
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
#-------------------------------------------------------
package xCAT_plugin::SSHsn;
use xCAT::Table;
use xCAT::Utils;
use xCAT::MsgUtils;
use Getopt::Long;
#-------------------------------------------------------
=head1
xCAT plugin package to setup of SSH on service node
#-------------------------------------------------------
=head3 handled_commands
Check to see if on a Service Node
Call setup_SSH
=cut
#-------------------------------------------------------
sub handled_commands
{
# If called in XCATBYPASS mode, don't do any setup
if ($ENV{'XCATBYPASS'}) {
return 0;
}
my $rc = 0;
if (xCAT::Utils->isServiceNode())
{
my $service = "ssh";
$rc = &setup_SSH(); # setup SSH
if ($rc == 0)
{
xCAT::Utils->update_xCATSN($service);
}
}
return $rc;
}
#-------------------------------------------------------
=head3 process_request
Process the command
=cut
#-------------------------------------------------------
sub process_request
{
return;
}
#-----------------------------------------------------------------------------
=head3 setup_SSH
Sets up SSH default configuration for root
Turns strict host checking off
=cut
#-----------------------------------------------------------------------------
sub setup_SSH
{
my $configfile;
my $cmd;
my $configinfo;
my $sshdir;
my $cmd;
# build the $HOMEROOT/.ssh/config
if (xCAT::Utils->isLinux())
{
$configfile = "/root/.ssh/config";
$sshdir="/root/.ssh";
}
else
{ #AIX
$configfile = "/.ssh/config";
$sshdir="/.ssh";
}
if (!(-e $sshdir)){ # directory does not exits
mkdir($sshdir, 0700);
}
$configinfo = "StrictHostKeyChecking no";
if (-e $configfile)
{
$cmd = "grep StrictHostKeyChecking $configfile";
xCAT::Utils->runcmd($cmd, -1);
if ($::RUNCMD_RC != 0)
{ # not there
$cmd = "echo $configinfo >> $configfile";
my @output = xCAT::Utils->runcmd($cmd, 0);
if ($::RUNCMD_RC != 0)
{ # error
xCAT::MsgUtils->message("S", "Error on $cmd, @output");
return 1;
}
}
}
else # file does not exist
{
$cmd = "echo $configinfo >> $configfile";
my @output = xCAT::Utils->runcmd($cmd, 0);
if ($::RUNCMD_RC != 0)
{ # error
xCAT::MsgUtils->message("S", "Error on $cmd, @output");
return 1;
}
else
{
chmod 0600, $configfile;
}
}
return 0;
}
1;

View File

@ -1,202 +0,0 @@
#!/usr/bin/env perl
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
#-------------------------------------------------------
package xCAT_plugin::TFTPsn;
use xCAT::Table;
use xCAT::Utils;
use xCAT::MsgUtils;
use Getopt::Long;
#-------------------------------------------------------
=head1
xCAT plugin package to setup atftp on a service node
#-------------------------------------------------------
=head3 handled_commands
This runs on Service Node ( only sets up for Linux)
Checks servicenode table tfpserver attribute
Call setup_TFTP (actually setting up atftp)
=cut
#-------------------------------------------------------
sub handled_commands
{
# If called in XCATBYPASS mode, don't do any setup
if ($ENV{'XCATBYPASS'}) {
return 0;
}
if (xCAT::Utils->isAIX()) { # do not run on AIX
return 0;
}
my $rc = 0;
# setup atftp
if (xCAT::Utils->isServiceNode())
{
my @nodeinfo = xCAT::Utils->determinehostname;
my $nodename = pop @nodeinfo; # get hostname
my @nodeipaddr = @nodeinfo; # get ip addresses
my $service = "tftpserver";
$rc = xCAT::Utils->isServiceReq($nodename, $service, \@nodeipaddr);
if ($rc == 1)
{
$rc = &setup_TFTP($nodename); # setup TFTP (ATFTP)
if ($rc == 0)
{
xCAT::Utils->update_xCATSN($service);
}
}
else
{
if ($rc == 2)
{ # just start the daemon
my $cmd = "service tftpd start";
system $cmd;
if ($? > 0)
{ # error
xCAT::MsgUtils->message("S", "Error on command: $cmd");
return 1;
}
}
}
}
return $rc;
}
#-------------------------------------------------------
=head3 process_request
Process the command
=cut
#-------------------------------------------------------
sub process_request
{
return;
}
#-----------------------------------------------------------------------------
=head3 setup_TFTP
Sets up TFTP services (using atftp)
=cut
#-----------------------------------------------------------------------------
sub setup_TFTP
{
my ($nodename) = @_;
my $rc = 0;
my $tftpdir = "/tftpboot"; # default
my $cmd;
my $master;
my $os;
my $arch;
$XCATROOT = "/opt/xcat"; # default
if ($ENV{'XCATROOT'})
{
$XCATROOT = $ENV{'XCATROOT'};
}
# read DB for nodeinfo
my $retdata = xCAT::Utils->readSNInfo($nodename);
$master = $retdata->{'master'};
$os = $retdata->{'os'};
$arch = $retdata->{'arch'};
if (!($arch))
{ # error
xCAT::MsgUtils->message("S", " Error reading service node arch.");
return 1;
}
# check to see if atftp is installed
$cmd = "/usr/sbin/in.tftpd -V";
my @output = xCAT::Utils->runcmd($cmd, -1);
if ($::RUNCMD_RC != 0)
{ # not installed
xCAT::MsgUtils->message("S", "atftp is not installed");
return 1;
}
if ($output[0] =~ "atftp") # it is atftp
{
# read tftpdir directory from database
my @tftpdir1 = xCAT::Utils->get_site_attribute("tftpdir");
if ($tftpdir1[0])
{
$tftpdir = $tftpdir1[0];
}
if (!(-e $tftpdir))
{
mkdir($tftpdir);
}
# check to see if tftp directory already mounted
my $mounted = xCAT::Utils->isMounted($tftpdir);
if ($mounted == 0) # not already mounted
{
# need to mount the directory
my $cmd = " mount -o rw,nolock $master:$tftpdir $tftpdir";
system $cmd;
if ($? > 0)
{ # error
$rc = 1;
xCAT::MsgUtils->message("S", "Error $cmd");
}
}
# start atftp
$cmd = "service tftpd stop";
system $cmd;
if ($? > 0)
{
xCAT::MsgUtils->message("S", "Error from command:$cmd");
}
$cmd = "service tftpd start";
system $cmd;
if ($? > 0)
{
xCAT::MsgUtils->message("S", "Error from command:$cmd");
return 1;
}
}
else
{ # no ATFTP
xCAT::MsgUtils->message("S", "atftp is not installed");
return 1;
}
if ($rc == 0)
{
# update fstab so that it will restart on reboot
$cmd =
"fgrep \"$master:$tftpdir $tftpdir nfs timeo=14,intr 1 2\" /etc/fstab";
xCAT::Utils->runcmd($cmd, -1);
if ($::RUNCMD_RC != 0) # not already there
{
`echo "$master:$tftpdir $tftpdir nfs timeo=14,intr 1 2" >>/etc/fstab`;
}
}
return $rc;
}
1;