2008-02-19 13:38:14 +00:00
|
|
|
#!/usr/bin/perl
|
2007-10-26 22:44:33 +00:00
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
#(C)IBM Corp
|
|
|
|
|
2008-02-19 13:38:14 +00:00
|
|
|
#
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2008-02-19 13:38:14 +00:00
|
|
|
#-----------------------------------------------------------------------------
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2008-02-19 13:38:14 +00:00
|
|
|
=head1 servicenode
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2011-12-07 17:40:24 +00:00
|
|
|
On AIX and Linux :
|
2008-02-19 13:38:14 +00:00
|
|
|
This updates the service node with files necessary to access the
|
|
|
|
database on the MasterNode and restarts the xcat daemon
|
2011-12-07 17:40:24 +00:00
|
|
|
If uses multiple environment variables setup by postage.pm from
|
|
|
|
the site table.
|
|
|
|
For Linux:
|
|
|
|
It calls xcatserver and xcatclient script to get the ssh keys, ssl
|
|
|
|
redentials and cfgloc file and transfer from the MN to the SN
|
|
|
|
to be able to access the
|
|
|
|
database, setup ssh keys on the nodes and have daemon to daemon
|
|
|
|
commmunication between the SN and MN and have the SN access the DB.
|
|
|
|
For AIX:
|
|
|
|
The same function in xcatserver and xcatclient is in this script for
|
|
|
|
AIX and thus it does not call xcatserver and xcatclient.
|
|
|
|
We get the ssh keys, ssl
|
|
|
|
credentials and cfgloc file for the SN to be able to access the
|
|
|
|
database, setup ssh keys on the nodes and have daemon to daemon
|
|
|
|
commmunication between the SN and MN and have the SN access the DB.
|
|
|
|
|
2008-08-22 15:02:13 +00:00
|
|
|
|
2008-02-19 13:38:14 +00:00
|
|
|
=cut
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2008-02-19 13:38:14 +00:00
|
|
|
#-----------------------------------------------------------------------------
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2009-03-10 13:56:52 +00:00
|
|
|
BEGIN
|
|
|
|
{
|
|
|
|
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
|
|
|
|
}
|
2009-08-03 13:07:06 +00:00
|
|
|
|
|
|
|
# if AIX - make sure we include perl 5.8.2 in INC path.
|
|
|
|
# Needed to find perl dependencies shipped in deps tarball.
|
|
|
|
if ($^O =~ /^aix/i) {
|
2012-08-08 17:37:51 +00:00
|
|
|
unshift(@INC, qw(/usr/opt/perl5/lib/5.8.2/aix-thread-multi /usr/opt/perl5/lib/5.8.2 /usr/opt/perl5/lib/site_perl/5.8.2/aix-thread-multi /usr/opt/perl5/lib/site_perl/5.8.2));
|
2009-08-03 13:07:06 +00:00
|
|
|
}
|
|
|
|
|
2009-03-10 13:56:52 +00:00
|
|
|
use lib "$::XCATROOT/lib/perl";
|
2011-04-20 11:23:15 +00:00
|
|
|
use strict;
|
2009-03-10 13:56:52 +00:00
|
|
|
# MAIN
|
|
|
|
use IO::Socket;
|
|
|
|
|
2009-04-08 14:51:04 +00:00
|
|
|
my $useSocketSSL=eval { require IO::Socket::SSL; };
|
|
|
|
if ($useSocketSSL) {
|
2009-04-13 19:30:53 +00:00
|
|
|
require IO::Socket::SSL;
|
2009-04-08 14:51:04 +00:00
|
|
|
}
|
|
|
|
|
2008-04-24 13:29:36 +00:00
|
|
|
# MAIN
|
2008-08-22 15:02:13 +00:00
|
|
|
|
2008-04-24 13:29:36 +00:00
|
|
|
my $rc=0;
|
2009-03-10 13:56:52 +00:00
|
|
|
my $msg="";
|
2008-04-24 13:29:36 +00:00
|
|
|
|
2008-08-22 15:02:13 +00:00
|
|
|
$::osname = `uname`;
|
|
|
|
chomp $::osname;
|
|
|
|
|
|
|
|
$::sdate = `/bin/date`;
|
|
|
|
chomp $::sdate;
|
|
|
|
|
|
|
|
$::hname = `hostname`;
|
|
|
|
chomp $::hname;
|
|
|
|
|
2010-04-21 19:03:49 +00:00
|
|
|
my $installdir = $ENV{'INSTALLDIR'};
|
|
|
|
if (!$installdir) {
|
|
|
|
$installdir="/install";
|
|
|
|
}
|
|
|
|
chomp $installdir;
|
|
|
|
$installdir =~ s/^(\'|\")(.*)(\"|\')$/$2/; # remove any surrounding quotes
|
|
|
|
|
2010-03-21 13:11:47 +00:00
|
|
|
# update security certificates keys for service node
|
2011-12-07 17:40:24 +00:00
|
|
|
# This section is used for the updatenode -k function, which sets the
|
|
|
|
# UPDATESECURITY env variable
|
2010-03-21 13:11:47 +00:00
|
|
|
if ($ENV{UPDATESECURITY} && $ENV{UPDATESECURITY} eq "1") {
|
|
|
|
$::servnode = $ENV{'MASTER'};
|
|
|
|
|
|
|
|
# only run for service node
|
|
|
|
if (! -f "/etc/xCATSN") {
|
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
|
2011-12-15 19:02:44 +00:00
|
|
|
# copy the postscripts to /install/postscripts, if not mounted
|
2012-02-06 17:48:20 +00:00
|
|
|
require xCAT::Utils;
|
2011-12-15 19:02:44 +00:00
|
|
|
my $mounted = xCAT::Utils->isMounted($installdir);
|
|
|
|
if ($mounted == 0) { # not mounted
|
|
|
|
if (&runcmd("mkdir -p $installdir/postscripts; cp -p -R /xcatpost/* $installdir/postscripts > /dev/null 2>&1") != 0 ) {
|
2010-04-21 19:03:49 +00:00
|
|
|
$msg = "$::sdate servicenode: Could not copy postscripts to $installdir/postscripts.\n";
|
2012-05-15 06:55:19 +00:00
|
|
|
`logger -t xcat -p local4.warning $msg`;
|
2011-12-15 19:02:44 +00:00
|
|
|
}
|
2010-03-21 13:11:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# copy the certificates
|
2010-12-03 12:27:02 +00:00
|
|
|
©certs;
|
2010-03-21 13:11:47 +00:00
|
|
|
if ($::osname eq 'AIX') {
|
|
|
|
# get the xCAT credentials from the server
|
|
|
|
&getcreds;
|
2011-12-07 17:40:24 +00:00
|
|
|
} else { # Linux
|
|
|
|
# call xcatserver,xcatclient to transfer the SSL credentials and cfgloc
|
2012-05-15 06:55:19 +00:00
|
|
|
`logger -t xcat -p local4.info $::sdate servicenode: running xcatserver -d`;
|
2011-12-07 17:40:24 +00:00
|
|
|
&runcmd("xcatserver -d");
|
2012-05-15 06:55:19 +00:00
|
|
|
`logger -t xcat -p local4.info $::sdate servicenode: running xcatclient -d`;
|
2011-12-07 17:40:24 +00:00
|
|
|
&runcmd("xcatclient -d");
|
2010-03-21 13:11:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-08-22 15:02:13 +00:00
|
|
|
if ($::osname eq 'AIX')
|
|
|
|
{
|
|
|
|
# AIX service node setup
|
|
|
|
$rc = &setupAIXsn;
|
|
|
|
if ( $rc != 0) {
|
|
|
|
my $msg="$::sdate servicenode: One or more errors occurred when attempting to configure node $::hname as an xCAT service node.\n";
|
2009-03-10 13:56:52 +00:00
|
|
|
# print "$msg\n";
|
2012-05-15 06:55:19 +00:00
|
|
|
`logger -t xcat -p local4.warning $msg`;
|
2008-08-22 15:02:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2008-04-24 13:29:36 +00:00
|
|
|
{
|
2008-08-22 15:02:13 +00:00
|
|
|
# Linux setup
|
2012-02-06 11:41:49 +00:00
|
|
|
# remove OpenIPMI-tools
|
2008-08-22 15:02:13 +00:00
|
|
|
# install xcat from /install/xcat
|
|
|
|
# Copy Certificates, and config file to apprpriate directories
|
|
|
|
# from /install and restart xcatd
|
|
|
|
&runcmd("rpm -e OpenIPMI-tools");
|
|
|
|
|
2010-12-03 12:27:02 +00:00
|
|
|
©certs;
|
2011-12-07 17:40:24 +00:00
|
|
|
|
2012-05-15 06:55:19 +00:00
|
|
|
`logger -t xcat -p local4.info $::sdate servicenode: running xcatserver -d`;
|
2011-12-07 17:40:24 +00:00
|
|
|
&runcmd("xcatserver -d");
|
2012-05-15 06:55:19 +00:00
|
|
|
`logger -t xcat -p local4.info $::sdate servicenode: running xcatclient -d`;
|
2011-12-07 17:40:24 +00:00
|
|
|
&runcmd("xcatclient -d");
|
2008-04-15 19:44:32 +00:00
|
|
|
}
|
2008-08-22 15:02:13 +00:00
|
|
|
|
2012-05-15 06:55:19 +00:00
|
|
|
`logger -t xcat -p local4.info $::sdate servicenode: rc=$rc`;
|
2008-08-22 15:02:13 +00:00
|
|
|
exit $rc;
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2008-04-24 13:29:36 +00:00
|
|
|
#
|
2008-08-22 15:02:13 +00:00
|
|
|
# Subroutines
|
2008-04-24 13:29:36 +00:00
|
|
|
#
|
2008-08-22 15:02:13 +00:00
|
|
|
|
|
|
|
# run the command
|
2008-04-24 13:29:36 +00:00
|
|
|
sub runcmd
|
|
|
|
{
|
|
|
|
my ($cmd) = @_;
|
2008-10-07 17:48:44 +00:00
|
|
|
my $rc=0;
|
2008-08-22 15:02:13 +00:00
|
|
|
|
2008-04-24 13:29:36 +00:00
|
|
|
$cmd .= ' 2>&1' ;
|
2010-06-03 12:57:43 +00:00
|
|
|
|
|
|
|
# my $outref = [];
|
|
|
|
# @$outref = `$cmd`;
|
|
|
|
|
|
|
|
$::outref = [];
|
|
|
|
$::outref = `$cmd`;
|
2008-04-24 13:29:36 +00:00
|
|
|
if ($?)
|
|
|
|
{
|
|
|
|
$rc = $? >> 8;
|
|
|
|
if ($rc > 0)
|
|
|
|
{
|
2012-02-08 17:02:58 +00:00
|
|
|
my $msg="$::sdate servicenode: $cmd returned rc=$rc \n";
|
2012-05-15 06:55:19 +00:00
|
|
|
`logger -t xcat -p local4.info $msg`;
|
2009-05-01 17:12:18 +00:00
|
|
|
return 1;
|
2008-04-24 13:29:36 +00:00
|
|
|
}
|
|
|
|
}
|
2009-03-10 13:56:52 +00:00
|
|
|
return 0;
|
2008-04-24 13:29:36 +00:00
|
|
|
}
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2008-08-22 15:02:13 +00:00
|
|
|
# do AIX service node setup
|
|
|
|
sub setupAIXsn
|
|
|
|
{
|
|
|
|
my $error=0;
|
2008-10-07 17:48:44 +00:00
|
|
|
|
2009-03-10 13:56:52 +00:00
|
|
|
# get the name of my service node/NIM master from the MASTER env var
|
|
|
|
$::servnode = $ENV{'MASTER'};
|
|
|
|
|
|
|
|
# makes it a service node
|
|
|
|
if (&runcmd("touch /etc/xCATSN") != 0 ) {
|
|
|
|
$msg = "$::sdate servicenode: Could not touch /etc/xCATSN\n";
|
2012-05-15 06:55:19 +00:00
|
|
|
`logger -t xcat -p local4.warning $msg`;
|
2009-03-10 13:56:52 +00:00
|
|
|
}
|
2008-10-07 17:48:44 +00:00
|
|
|
|
2009-04-13 19:30:53 +00:00
|
|
|
# copy the postscripts to /install/postscripts
|
2010-04-21 19:03:49 +00:00
|
|
|
if (&runcmd("mkdir -p $installdir/postscripts; cp -p -R /xcatpost/* $installdir/postscripts > /dev/null 2>&1") != 0 ) {
|
|
|
|
$msg = "$::sdate servicenode: Could not copy postscripts to $installdir/postscripts.\n";
|
2012-05-15 06:55:19 +00:00
|
|
|
`logger -t xcat -p local4.warning $msg`;
|
2009-04-13 19:30:53 +00:00
|
|
|
}
|
|
|
|
|
2009-04-28 14:56:41 +00:00
|
|
|
# check if /install/postscripts is in /etc/exports
|
2010-06-03 12:57:43 +00:00
|
|
|
if (&runcmd("/bin/cat /etc/exports 2>/dev/null | grep '$installdir/postscripts ' >/dev/null 2>&1") != 0) {
|
2009-04-28 14:56:41 +00:00
|
|
|
# if not add it and make sure it is exported
|
2012-09-18 12:07:55 +00:00
|
|
|
my $res;
|
|
|
|
if ($ENV{'USENFSV4ONAIX'} && ($ENV{'USENFSV4ONAIX'} =~ /1|Yes|yes|YES|Y|y/))
|
|
|
|
{
|
|
|
|
$res = &runcmd("echo '$installdir/postscripts -vers=3:4,ro' >> /etc/exports; exportfs -a");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$res = &runcmd("echo '$installdir/postscripts -ro' >> /etc/exports; exportfs -a");
|
|
|
|
}
|
|
|
|
if ($res != 0)
|
|
|
|
{
|
2009-04-28 14:56:41 +00:00
|
|
|
$msg = "$::sdate servicenode: Could not update the /etc/exports file.\n";
|
2012-05-15 06:55:19 +00:00
|
|
|
`logger -t xcat -p local4.warning $msg`;
|
2009-04-28 14:56:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-10 13:56:52 +00:00
|
|
|
# make sure we don't have xCATMN file
|
|
|
|
if (-f "/etc/xCATMN") {
|
|
|
|
if (&runcmd("rm /etc/xCATMN") != 0 ) {
|
|
|
|
$msg = "$::sdate servicenode: Could not remove /etc/xCATMN\n";
|
2012-05-15 06:55:19 +00:00
|
|
|
`logger -t xcat -p local4.warning $msg`;
|
2008-10-07 17:48:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-16 12:49:33 +00:00
|
|
|
# call copycerts
|
2010-12-03 12:27:02 +00:00
|
|
|
©certs;
|
2009-12-03 08:01:33 +00:00
|
|
|
# get the xCAT credentials from the server
|
2009-03-10 13:56:52 +00:00
|
|
|
&getcreds;
|
|
|
|
|
2009-12-03 08:01:33 +00:00
|
|
|
# Add the xcatd subsystem to the AIX
|
2010-06-03 12:57:43 +00:00
|
|
|
my $mkssys_cmd = "mkssys -p $::XCATROOT/sbin/xcatd -s xcatd -u 0 -S -n 15 -f 15 -a '-f' ";
|
|
|
|
|
2009-12-03 08:01:33 +00:00
|
|
|
if (&runcmd($mkssys_cmd) != 0) {
|
|
|
|
$msg = "$::sdate servicenode: Could not create subsystem for xcatd. It maybe already have been added.\n";
|
2012-05-15 06:55:19 +00:00
|
|
|
`logger -t xcat -p local4.warning $msg`;
|
2009-12-03 08:01:33 +00:00
|
|
|
}
|
|
|
|
|
2009-03-10 13:56:52 +00:00
|
|
|
# start xcatd
|
2010-05-04 09:31:57 +00:00
|
|
|
if (&runcmd("$::XCATROOT/sbin/restartxcatd") != 0) {
|
2010-06-03 12:57:43 +00:00
|
|
|
$msg = "$::sdate servicenode: Could not start xcatd.\n\n $::outref \n";
|
2012-05-15 06:55:19 +00:00
|
|
|
`logger -t xcat -p local4.warning $msg`;
|
2010-06-03 12:57:43 +00:00
|
|
|
}
|
2008-10-07 17:48:44 +00:00
|
|
|
|
2009-03-10 13:56:52 +00:00
|
|
|
# add xcatd to /etc/inittab???
|
2010-06-03 12:57:43 +00:00
|
|
|
my $mkitab_cmd = qq~/usr/sbin/mkitab "xcatd:2:once:$::XCATROOT/sbin/restartxcatd > /dev/console 2>&1"~;
|
2008-10-07 17:48:44 +00:00
|
|
|
|
2009-03-10 13:56:52 +00:00
|
|
|
if (&runcmd($mkitab_cmd) != 0) {
|
|
|
|
# error might just mean that the entry is already there!
|
2008-10-07 17:48:44 +00:00
|
|
|
|
2009-03-10 13:56:52 +00:00
|
|
|
# $msg = "$::sdate servicenode: Could not add xcatd to /etc/inittab.\n";
|
2009-12-03 08:01:33 +00:00
|
|
|
# `logger -t xcat $msg`;
|
|
|
|
}
|
2008-10-07 17:48:44 +00:00
|
|
|
|
2009-03-25 14:38:16 +00:00
|
|
|
# set ulimit - so we can copy over large files - like spot
|
|
|
|
if (&runcmd("/usr/bin/chuser fsize=-1 root") != 0) {
|
|
|
|
$msg = "$::sdate servicenode: Could not change ulimit\n";
|
2012-05-15 06:55:19 +00:00
|
|
|
`logger -t xcat -p local4.warning $msg`;
|
2009-03-25 14:38:16 +00:00
|
|
|
}
|
|
|
|
|
2009-04-13 19:30:53 +00:00
|
|
|
# stop inetd, make sure bootp & tftp are in /etc/inetd.conf and restart
|
|
|
|
if (&runcmd("stopsrc -s inetd") != 0) {
|
|
|
|
$msg = "$::sdate servicenode: Could not stop inetd.\n";
|
2012-05-15 06:55:19 +00:00
|
|
|
`logger -t xcat -p local4.warning $msg`;
|
2009-04-13 19:30:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
my $tmp_inetd_file = "/etc/inetd.conf.tmp";
|
|
|
|
unless (open(TMPINETD, ">>$tmp_inetd_file")) {
|
|
|
|
$msg = "$::sdate servicenode: Could not open $tmp_inetd_file.\n";
|
2012-05-15 06:55:19 +00:00
|
|
|
`logger -t xcat -p local4.warning $msg`;
|
2009-04-13 19:30:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
my $inetd_file_name = "/etc/inetd.conf";
|
|
|
|
unless (open(INETDFILE, "<$inetd_file_name")) {
|
|
|
|
$msg = "$::sdate servicenode: Could not open $inetd_file_name.\n";
|
2012-05-15 06:55:19 +00:00
|
|
|
`logger -t xcat -p local4.warning $msg`;
|
2009-04-13 19:30:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while (my $l = <INETDFILE>) {
|
|
|
|
chomp $l;
|
|
|
|
if (($l =~ /bootps/) || ($l =~ /tftp/)) {
|
|
|
|
$l =~ s/^\s*#/$1/;
|
|
|
|
print TMPINETD $l . "\n";
|
|
|
|
} else {
|
|
|
|
print TMPINETD $l . "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close (TMPINETD);
|
|
|
|
close (INETDFILE);
|
|
|
|
|
|
|
|
if (&runcmd("mv $tmp_inetd_file $inetd_file_name > /dev/null 2>&1") != 0) {
|
|
|
|
$msg = "$::sdate servicenode: Could not update /etc/inetd.conf.\n";
|
2012-05-15 06:55:19 +00:00
|
|
|
`logger -t xcat -p local4.warning $msg`;
|
2009-04-13 19:30:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (&runcmd("startsrc -s inetd") != 0) {
|
|
|
|
$msg = "$::sdate servicenode: Could not restart inetd.\n";
|
2012-05-15 06:55:19 +00:00
|
|
|
`logger -t xcat -p local4.warning $msg`;
|
2009-04-13 19:30:53 +00:00
|
|
|
}
|
|
|
|
|
2009-03-10 13:56:52 +00:00
|
|
|
# do nim master setup - master fileset already installed
|
2009-03-25 14:38:16 +00:00
|
|
|
if (&runcmd("/usr/sbin/nim_master_setup -a mk_resource=no") != 0) {
|
|
|
|
$msg = "$::sdate servicenode: Could not run nim_master_setup.\n";
|
2012-05-15 06:55:19 +00:00
|
|
|
`logger -t xcat -p local4.warning $msg`;
|
2008-10-07 17:48:44 +00:00
|
|
|
}
|
|
|
|
|
2009-03-10 13:56:52 +00:00
|
|
|
#
|
|
|
|
# TODO - can configure NIM to use SSL - "nimconfig -c"
|
|
|
|
# !!!!! can't do diskless nodes w/ nimsh & SSL enabled!!!!
|
|
|
|
#
|
2008-10-07 17:48:44 +00:00
|
|
|
|
2009-10-17 13:07:48 +00:00
|
|
|
# restore the original .rhosts that was removed by NIM setup
|
|
|
|
if (&runcmd("cp /.rhosts.prev /.rhosts ") != 0 ) {
|
|
|
|
$msg = "$::sdate servicenode: Could not restore the .rhosts file.\n";
|
2012-05-15 06:55:19 +00:00
|
|
|
`logger -t xcat -p local4.warning $msg`;
|
2009-10-17 13:07:48 +00:00
|
|
|
}
|
|
|
|
|
2009-03-10 13:56:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2008-08-22 15:02:13 +00:00
|
|
|
|
2009-03-10 13:56:52 +00:00
|
|
|
#####################################################
|
|
|
|
#
|
2011-12-07 17:40:24 +00:00
|
|
|
# getcreds ( For AIX) .
|
|
|
|
# Same function in xcatserver,xcatclient for Linux
|
|
|
|
# Get xCAT SSL credentials and DB cfgloc file
|
2009-03-10 13:56:52 +00:00
|
|
|
#
|
|
|
|
#####################################################
|
|
|
|
sub getcreds
|
|
|
|
{
|
|
|
|
my $response=&getresponse("xcat_client_cred");
|
|
|
|
if (defined ($response) ) {
|
|
|
|
my $fd;
|
|
|
|
my $filename = "/.xcat/client-cred.pem";
|
|
|
|
&runcmd("mkdir -p /.xcat");
|
|
|
|
&runcmd("chmod 700 /.xcat > /dev/null 2>&1");
|
|
|
|
open($fd, '>',$filename);
|
|
|
|
print $fd $response;
|
|
|
|
close($fd);
|
|
|
|
|
|
|
|
# set the permissions
|
|
|
|
my $cmd = "chmod 600 $filename > /dev/null 2>&1";
|
|
|
|
&runcmd($cmd);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$msg = "$::sdate servicenode: Could not get client-cred.pem file.\n";
|
2012-05-15 06:55:19 +00:00
|
|
|
`logger -t xcat -p local4.warning $msg`;
|
2008-08-22 15:02:13 +00:00
|
|
|
}
|
|
|
|
|
2010-06-03 12:57:43 +00:00
|
|
|
$response=&getresponse("xcat_server_cred");
|
2009-03-10 13:56:52 +00:00
|
|
|
if (defined ($response) ) {
|
|
|
|
my $fd;
|
|
|
|
my $filename = "/etc/xcat/cert/server-cred.pem";
|
|
|
|
&runcmd("mkdir -p /etc/xcat/cert");
|
|
|
|
open($fd, '>',$filename);
|
|
|
|
print $fd $response;
|
|
|
|
close($fd);
|
|
|
|
|
|
|
|
# set the permissions
|
|
|
|
my $cmd = "chmod 600 /etc/xcat/cert/* > /dev/null 2>&1";
|
|
|
|
&runcmd($cmd);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$msg = "$::sdate servicenode: Could not get server-cred.pem file.\n";
|
2012-05-15 06:55:19 +00:00
|
|
|
`logger -t xcat -p local4.warning $msg`;
|
2008-08-22 15:02:13 +00:00
|
|
|
}
|
|
|
|
|
2010-06-03 12:57:43 +00:00
|
|
|
$response=&getresponse("xcat_cfgloc");
|
2009-03-10 13:56:52 +00:00
|
|
|
if (defined ($response) ) {
|
2011-12-07 17:40:24 +00:00
|
|
|
# need to change entry to use the name of the server as
|
|
|
|
# know by this node
|
2010-09-29 13:08:45 +00:00
|
|
|
# except for db2 which has a different format, no host
|
|
|
|
my $newstr;
|
|
|
|
if ($response =~ /^DB2:/){
|
|
|
|
$newstr = $response;
|
|
|
|
} else {
|
2011-12-07 17:40:24 +00:00
|
|
|
my ($begin, $tmp) = split(';', $response);
|
|
|
|
my ($tmp2, $end, $end2) = split('\|', $tmp);
|
|
|
|
my ($tmp3, $oldserv) = split('=', $tmp2);
|
2010-09-29 13:08:45 +00:00
|
|
|
$newstr = "$begin;$tmp3=$::servnode|$end|$end2";
|
|
|
|
}
|
2009-03-10 13:56:52 +00:00
|
|
|
my $fd;
|
|
|
|
my $filename = "/etc/xcat/cfgloc";
|
|
|
|
&runcmd("mkdir -p /etc/xcat");
|
|
|
|
open($fd, '>',$filename);
|
|
|
|
print $fd $newstr;
|
|
|
|
close($fd);
|
|
|
|
|
|
|
|
# set the permissions
|
|
|
|
my $cmd = "chmod 600 $filename > /dev/null 2>&1";
|
|
|
|
&runcmd($cmd);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$msg = "$::sdate servicenode: Could not get cfgloc file.\n";
|
2012-05-15 06:55:19 +00:00
|
|
|
`logger -t xcat -p local4.warning $msg`;
|
2008-08-22 15:02:13 +00:00
|
|
|
}
|
|
|
|
|
2009-03-10 13:56:52 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2008-10-07 17:48:44 +00:00
|
|
|
|
2009-03-10 13:56:52 +00:00
|
|
|
#####################################################
|
|
|
|
#
|
|
|
|
# getresponse
|
|
|
|
# Request info from xcatd on the management node
|
|
|
|
#
|
|
|
|
# - uses SSL socket on port 3001 to connect to MN xcatd
|
|
|
|
# to make the request for info
|
|
|
|
#
|
|
|
|
#####################################################
|
|
|
|
sub getresponse
|
|
|
|
{
|
|
|
|
my ($req) = @_;
|
2008-08-22 15:02:13 +00:00
|
|
|
|
2009-03-10 13:56:52 +00:00
|
|
|
my $port = "3001";
|
2009-03-25 14:38:16 +00:00
|
|
|
my $node = $ENV{'NODE'};
|
2008-08-22 15:02:13 +00:00
|
|
|
|
2009-03-10 13:56:52 +00:00
|
|
|
# open listener connection to wait for check from management node
|
|
|
|
my $lpid = &openlistener();
|
2008-08-22 15:02:13 +00:00
|
|
|
|
2009-03-10 13:56:52 +00:00
|
|
|
# open a socket to request credentials
|
|
|
|
my $sock = IO::Socket::SSL->new(
|
|
|
|
PeerAddr => $::servnode,
|
|
|
|
PeerPort => $port,
|
|
|
|
Proto => 'tcp',
|
|
|
|
);
|
2008-08-22 15:02:13 +00:00
|
|
|
|
2009-03-25 14:38:16 +00:00
|
|
|
# try a few more times
|
|
|
|
my $times=1;
|
|
|
|
while (!$sock) {
|
|
|
|
sleep(2);
|
|
|
|
$times++;
|
|
|
|
$sock = IO::Socket::SSL->new(
|
|
|
|
PeerAddr => $::servnode,
|
|
|
|
PeerPort => $port,
|
|
|
|
Proto => 'tcp',
|
|
|
|
);
|
|
|
|
if ($times == 5) {
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-10 13:56:52 +00:00
|
|
|
unless ($sock) {
|
2011-12-07 17:40:24 +00:00
|
|
|
my $msg = "$::sdate servicenode: Cannot connect to host \'$::servnode\'\n";
|
2012-05-15 06:55:19 +00:00
|
|
|
`logger -t xcat -p local4.err $msg`;
|
2009-03-10 13:56:52 +00:00
|
|
|
print $msg;
|
|
|
|
return undef;
|
|
|
|
}
|
2008-08-22 15:02:13 +00:00
|
|
|
|
2009-03-10 13:56:52 +00:00
|
|
|
# request must be in XML format
|
|
|
|
print $sock "<xcatrequest>\n";
|
|
|
|
print $sock " <command>getcredentials</command>\n";
|
|
|
|
print $sock " <arg>$req</arg>\n";
|
|
|
|
print $sock " <callback_port>300</callback_port>\n";
|
|
|
|
print $sock "</xcatrequest>\n";
|
|
|
|
|
|
|
|
#TODO - do we have to try again after waiting for a bit????
|
|
|
|
my $response='';
|
|
|
|
my $line;
|
|
|
|
while (defined ($line = <$sock>)) {
|
|
|
|
# skip xml tags
|
|
|
|
next if ($line =~ /^\s*</);
|
|
|
|
|
|
|
|
# once we get to serverdone we have the whole response
|
|
|
|
if ($line =~ m/<\/serverdone>/) {
|
|
|
|
last:
|
|
|
|
}
|
|
|
|
$response .= $line;
|
2008-08-22 15:02:13 +00:00
|
|
|
}
|
|
|
|
|
2009-03-10 13:56:52 +00:00
|
|
|
close ($sock);
|
|
|
|
#print "resp = \'$response\'\n";
|
|
|
|
|
|
|
|
kill 2, $lpid;
|
|
|
|
if ($response) {
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
|
|
|
|
#####################################################
|
|
|
|
#
|
|
|
|
# openlistener
|
|
|
|
# - fork a child process to respond to a check from the MN
|
|
|
|
#
|
|
|
|
#####################################################
|
|
|
|
sub openlistener
|
|
|
|
{
|
|
|
|
my $node = $ENV{'NODE'};
|
|
|
|
|
2009-03-31 12:17:11 +00:00
|
|
|
require xCAT::Utils;
|
2009-03-10 13:56:52 +00:00
|
|
|
# fork a child process to open a socket to listen for communication
|
|
|
|
# from the server
|
|
|
|
my $pid = xCAT::Utils->xfork;
|
|
|
|
unless (defined $pid) {
|
|
|
|
# fork failed
|
2011-12-07 17:40:24 +00:00
|
|
|
$msg = "$::sdate servicenode: Could not fork process.\n";
|
2012-05-15 06:55:19 +00:00
|
|
|
`logger -t xcat -p local4.err $msg`;
|
2009-03-10 13:56:52 +00:00
|
|
|
#print $msg;
|
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($pid != 0) {
|
|
|
|
# This is the parent process, just return
|
|
|
|
return $pid;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $listener = IO::Socket::INET->new(
|
|
|
|
LocalPort => '300',
|
|
|
|
Proto => 'tcp',
|
|
|
|
Listen => '64',
|
|
|
|
Reuse => 1
|
|
|
|
);
|
|
|
|
|
|
|
|
unless ($listener) {
|
2011-12-07 17:40:24 +00:00
|
|
|
my $msg = "$::sdate servicenode: Cannot open socket on \'$node\'\n";
|
2012-05-15 06:55:19 +00:00
|
|
|
`logger -t xcat -p local4.err $msg`;
|
2009-03-10 13:56:52 +00:00
|
|
|
print $msg;
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
# xcatd sends a quick req to see if we are really asking
|
|
|
|
# for info - this listener checks for the req and says ok
|
|
|
|
my $client;
|
|
|
|
while ($client = $listener->accept()) {
|
|
|
|
# $client is the new connection
|
|
|
|
my $text=<$client>;
|
|
|
|
|
|
|
|
# see if we got "CREDOKBYYOU?"
|
|
|
|
if ($text =~ /CREDOKBYYOU?/) {
|
|
|
|
print $client "CREDOKBYME";
|
|
|
|
close($client);
|
|
|
|
close($listener);
|
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
close($client);
|
|
|
|
}
|
|
|
|
close($client);
|
|
|
|
close($listener);
|
|
|
|
exit 0;
|
2008-08-22 15:02:13 +00:00
|
|
|
}
|
2010-12-03 12:27:02 +00:00
|
|
|
#####################################################
|
|
|
|
#
|
|
|
|
# copycerts
|
2011-12-07 17:40:24 +00:00
|
|
|
# Setup the /etc/xcat/ca, /etc/xcat/cert, ~/.xcat directories with
|
|
|
|
# SSL certificates from the /xcatpost/_xcat directory
|
|
|
|
# These certificate are needed to access the Databases from the SN
|
2010-12-03 12:27:02 +00:00
|
|
|
#####################################################
|
|
|
|
|
|
|
|
sub copycerts
|
|
|
|
{
|
|
|
|
my $rc = 0;
|
|
|
|
`touch /etc/xCATSN`;
|
|
|
|
# get roots home directory
|
|
|
|
my @user= getpwuid($>);
|
2011-04-20 11:23:15 +00:00
|
|
|
my $homedir=$user[7];
|
2010-12-03 12:27:02 +00:00
|
|
|
if (-d "/xcatpost/_xcat")
|
|
|
|
{
|
|
|
|
if (!(-d "$homedir/.xcat"))
|
|
|
|
{
|
|
|
|
`mkdir -p $homedir/.xcat`;
|
|
|
|
`chmod 0600 $homedir/.xcat`;
|
|
|
|
}
|
|
|
|
`cp -f -rp /xcatpost/_xcat/* $homedir/.xcat`;
|
|
|
|
`chmod 0600 $homedir/.xcat/*`;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-07 17:40:24 +00:00
|
|
|
$msg = "$::sdate servicenode: /xcatpost/_xcat directory does not exist\n";
|
2012-05-15 06:55:19 +00:00
|
|
|
`logger -t xcat -p local4.warning $msg`;
|
2010-12-03 12:27:02 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
if (-d "/xcatpost/ca")
|
|
|
|
{
|
|
|
|
if (!(-d "/etc/xcat"))
|
|
|
|
{
|
|
|
|
mkdir("/etc/xcat", 0755);
|
|
|
|
}
|
|
|
|
if (!(-d "/etc/xcat/ca"))
|
|
|
|
{
|
|
|
|
mkdir("/etc/xcat/ca", 0755);
|
|
|
|
}
|
|
|
|
`cp -f -rp /xcatpost/ca/* /etc/xcat/ca`;
|
|
|
|
`chmod 0600 /etc/xcat/ca/*`;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-07 17:40:24 +00:00
|
|
|
$msg = "$::sdate servicenode: /xcatpost/ca directory does not exist\n";
|
2012-05-15 06:55:19 +00:00
|
|
|
`logger -t xcat -p local4.warning $msg`;
|
2010-12-03 12:27:02 +00:00
|
|
|
|
|
|
|
}
|
2011-12-07 17:40:24 +00:00
|
|
|
# if AIX, only need for AIX because xcatserver script does it for Linux
|
2010-12-03 12:27:02 +00:00
|
|
|
if ($^O =~ /^aix/i) {
|
|
|
|
if (-d "/xcatpost/_xcat")
|
|
|
|
{
|
|
|
|
if (!(-d "/etc/xcat"))
|
|
|
|
{
|
|
|
|
mkdir("/etc/xcat", 0755);
|
|
|
|
}
|
|
|
|
if (!(-d "/etc/xcat/cert"))
|
|
|
|
{
|
|
|
|
mkdir("/etc/xcat/cert", 0755);
|
|
|
|
}
|
|
|
|
`cp -f -rp /xcatpost/_xcat/* /etc/xcat/cert`;
|
|
|
|
`chmod 0600 /etc/xcat/cert/*`;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-12-07 17:40:24 +00:00
|
|
|
$msg = "$::sdate servicenode: /xcatpost/_xcat directory does not exist\n";
|
2012-05-15 06:55:19 +00:00
|
|
|
`logger -t xcat -p local4.warning $msg`;
|
2010-12-03 12:27:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $rc;
|
|
|
|
}
|