2008-06-12 12:55:29 +00:00
|
|
|
#!/usr/bin/env perl -w
|
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
#####################################################
|
|
|
|
#
|
|
|
|
# xCAT post script for AIX nodes
|
|
|
|
#
|
2013-02-28 20:45:45 +00:00
|
|
|
# This script is run from the /etc/inittab file on both
|
|
|
|
# diskless and diskfull AIX nodes as setup by xcataixscript
|
2009-03-25 14:38:16 +00:00
|
|
|
#
|
2013-02-28 20:45:45 +00:00
|
|
|
# It is run by the updatenode cmd -P by calling xcatdsklspost 1 -m/-M (mode 1)
|
|
|
|
# updatenode cmd -k by calling xcatdsklspost 5 (mode 5)
|
2013-06-12 12:59:11 +00:00
|
|
|
# moncfg command (-c 3) option c means refresh /xcatpost
|
2013-02-28 20:45:45 +00:00
|
|
|
# For full install called from aixinstall.pm plugin with no parameters
|
|
|
|
#
|
2008-06-12 12:55:29 +00:00
|
|
|
#####################################################
|
|
|
|
|
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
|
|
|
}
|
2012-08-08 17:37:51 +00:00
|
|
|
|
2011-11-02 14:04:33 +00:00
|
|
|
use strict;
|
2008-06-12 12:55:29 +00:00
|
|
|
use File::Path;
|
|
|
|
use IO::Socket;
|
2009-07-07 14:57:17 +00:00
|
|
|
my $useSocketSSL=eval { require IO::Socket::SSL; };
|
2009-03-25 14:38:16 +00:00
|
|
|
use Getopt::Long;
|
2009-07-07 14:57:17 +00:00
|
|
|
use XML::Simple;
|
2013-03-13 18:40:05 +00:00
|
|
|
use Sys::Hostname;
|
2008-11-22 04:03:24 +00:00
|
|
|
|
2008-06-12 12:55:29 +00:00
|
|
|
# since we don't have syslog set up yet we'll
|
|
|
|
# just save msgs in a local log file
|
2011-11-02 14:04:33 +00:00
|
|
|
my $logdir = "/var/log/xcat";
|
2008-06-12 12:55:29 +00:00
|
|
|
|
|
|
|
if (!-d $logdir) {
|
|
|
|
mkpath($logdir);
|
|
|
|
}
|
2012-05-23 18:17:11 +00:00
|
|
|
$::NOERROR=0; # used to control whether to display an error
|
2008-06-12 12:55:29 +00:00
|
|
|
$::sdate = `/bin/date`;
|
2009-03-10 13:56:52 +00:00
|
|
|
chomp $::sdate;
|
2008-06-12 12:55:29 +00:00
|
|
|
my $logfile = $logdir . "/xcat.log";
|
2013-02-28 20:45:45 +00:00
|
|
|
`logger -t xcat -p local4.info "my logfile is $logfile"`;
|
2008-06-12 12:55:29 +00:00
|
|
|
|
|
|
|
# this log should not contain much so it might be ok to let it grow?
|
|
|
|
# at least we'll have the errors preserved
|
|
|
|
open(LOGFILE,">>",$logfile);
|
|
|
|
$::LOG_FILE = \*LOGFILE;
|
|
|
|
|
2009-09-22 06:10:09 +00:00
|
|
|
unless ($useSocketSSL) {
|
2013-02-28 20:45:45 +00:00
|
|
|
`logger -t xcat -p local4.info "xcataixpost: Error: cannot load necessary library IO::Socket::SSL."`;
|
2009-09-22 06:10:09 +00:00
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: Error: cannot load necessary library IO::Socket::SSL.\n";
|
|
|
|
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
2009-03-25 14:38:16 +00:00
|
|
|
#
|
|
|
|
# Process the command line...
|
|
|
|
#
|
2013-02-28 20:45:45 +00:00
|
|
|
# the -c means get a fresh copy of the postscripts from the server
|
|
|
|
# -m means we are updating the node
|
|
|
|
# -M means we are updating the service node /etc/xcatinfo file
|
2012-12-04 20:40:11 +00:00
|
|
|
my $idir;
|
|
|
|
my $nfsv4;
|
2009-12-01 18:17:15 +00:00
|
|
|
Getopt::Long::Configure("no_pass_through");
|
|
|
|
$Getopt::Long::ignorecase = 0;
|
2012-12-04 20:40:11 +00:00
|
|
|
if (!GetOptions('copy|c' => \$::opt_c,
|
|
|
|
'm=s' => \$::opt_m,
|
|
|
|
'M=s' => \$::opt_M,
|
|
|
|
'tftp=s'=> \$::opt_tftpdir,
|
|
|
|
'installdir=s'=> \$idir,
|
|
|
|
'nfsv4=s'=> \$nfsv4))
|
2009-03-25 14:38:16 +00:00
|
|
|
{ # Gather options
|
|
|
|
exit 1;
|
2013-02-28 20:45:45 +00:00
|
|
|
}
|
|
|
|
my $mode;
|
|
|
|
if (@ARGV<1) { # not running updatenode
|
2009-03-25 14:38:16 +00:00
|
|
|
|
2013-02-28 20:45:45 +00:00
|
|
|
sleep int(rand(10)); # installing don't hit daemon with too many requests
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$mode= $ARGV[0];
|
|
|
|
`logger -t xcat -p local4.info "$::sdate xcataixpost: Running mode=$mode"`;
|
|
|
|
}
|
2012-11-23 07:11:52 +00:00
|
|
|
my $TFTPDIR=$::opt_tftpdir;
|
2009-03-10 13:56:52 +00:00
|
|
|
my $servnode;
|
2009-11-25 15:55:08 +00:00
|
|
|
|
2009-12-01 18:17:15 +00:00
|
|
|
# create new xcatinfo file if -M value is provided
|
|
|
|
if ($::opt_M) {
|
2013-03-11 19:34:21 +00:00
|
|
|
if(-f "/etc/xcatinfo") {
|
|
|
|
# backup the old file - or remove ???
|
|
|
|
my $cpcmd = "cp /etc/xcatinfo /etc/xcatinfo.orig 2>/dev/null";
|
|
|
|
if (&runcmd($cpcmd) != 0) {
|
|
|
|
`logger -t xcat -p local4.info "$::sdate xcataixpost: Could not copy /etc/xcatinfo file."`;
|
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: Could not copy /etc/xcatinfo file.\n";
|
|
|
|
}
|
|
|
|
}
|
2009-11-25 15:55:08 +00:00
|
|
|
|
2013-03-11 19:34:21 +00:00
|
|
|
# put the new server in the file
|
|
|
|
my $xcatinfo="/etc/xcatinfo";
|
|
|
|
open(XCATINFO,">",$xcatinfo);
|
2013-03-13 18:40:05 +00:00
|
|
|
print XCATINFO "XCATSERVER=$::opt_M\n";
|
2009-11-25 15:55:08 +00:00
|
|
|
close(XCATINFO);
|
2013-03-13 18:40:05 +00:00
|
|
|
|
|
|
|
chomp $::opt_M;
|
|
|
|
$servnode = $::opt_M;
|
|
|
|
$servnode =~ s/^\s*//;
|
2009-11-25 15:55:08 +00:00
|
|
|
}
|
|
|
|
|
2013-03-11 19:34:21 +00:00
|
|
|
if ($::opt_m) {
|
|
|
|
chomp $::opt_m;
|
|
|
|
$servnode = $::opt_m;
|
2009-06-08 17:08:10 +00:00
|
|
|
$servnode =~ s/^\s*//;
|
2013-03-11 19:34:21 +00:00
|
|
|
}
|
2009-06-08 17:08:10 +00:00
|
|
|
|
2013-03-11 19:34:21 +00:00
|
|
|
unless ($servnode) {
|
2011-10-28 20:23:51 +00:00
|
|
|
|
2013-03-11 19:34:21 +00:00
|
|
|
if (-f "/etc/xcatinfo") {
|
|
|
|
# if this file exists assume it has the correct server name
|
|
|
|
my $cmd = "cat /etc/xcatinfo | grep 'XCATSERVER'";
|
|
|
|
&runcmd($cmd);
|
|
|
|
my $SNline = $::outref;
|
|
|
|
my $junk;
|
|
|
|
($junk, $servnode) = split(/=/, $SNline);
|
|
|
|
chomp $servnode;
|
|
|
|
$servnode =~ s/^\s*//;
|
|
|
|
} elsif (-f "/etc/niminfo") {
|
|
|
|
# get the name of my service node (NIM master) from /etc/niminfo
|
2011-11-02 14:04:33 +00:00
|
|
|
my $cmd = "cat /etc/niminfo | grep 'NIM_NAME'";
|
2011-10-28 20:23:51 +00:00
|
|
|
&runcmd($cmd);
|
|
|
|
my $line = $::outref;
|
2013-03-13 18:40:05 +00:00
|
|
|
my $junk;
|
|
|
|
my $myname;
|
|
|
|
($junk, $myname) = split(/=/, $line);
|
2011-10-28 20:23:51 +00:00
|
|
|
chomp $myname;
|
|
|
|
if ($myname ne "master") {
|
|
|
|
$cmd = "cat /etc/niminfo | grep 'NIM_MASTER_HOSTNAME'";
|
|
|
|
&runcmd($cmd);
|
|
|
|
my $SNline = $::outref;
|
|
|
|
($junk, $servnode) = split(/=/, $SNline);
|
|
|
|
if ($servnode) {
|
|
|
|
chomp $servnode;
|
|
|
|
$servnode =~ s/^\s*//;
|
|
|
|
# save the servnode from niminfo in xcatinfo
|
|
|
|
my $xcatinfo="/etc/xcatinfo";
|
|
|
|
open(XCATINFO,">",$xcatinfo);
|
|
|
|
print XCATINFO "XCATSERVER=$servnode\n";
|
|
|
|
close(XCATINFO);
|
|
|
|
}
|
2009-06-08 17:08:10 +00:00
|
|
|
}
|
2009-03-10 13:56:52 +00:00
|
|
|
}
|
2008-06-12 12:55:29 +00:00
|
|
|
}
|
2009-06-08 17:08:10 +00:00
|
|
|
|
2013-03-11 19:34:21 +00:00
|
|
|
unless ($servnode) {
|
|
|
|
`logger -t xcat -p local4.info " $::sdate xcataixpost: Could not determine server name."`;
|
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: Could not determine server name.\n
|
|
|
|
";
|
|
|
|
exit 1;
|
2009-12-01 18:17:15 +00:00
|
|
|
}
|
|
|
|
|
2010-05-12 12:14:15 +00:00
|
|
|
# create the xcatpost dir
|
|
|
|
my $cmd = "mkdir -p /xcatpost";
|
|
|
|
if (&runcmd($cmd) != 0) {
|
2013-02-28 20:45:45 +00:00
|
|
|
`logger -t xcat -p local4.info "$::sdate xcataixpost: Could not create the /xcatpost directory."`;
|
2010-05-12 12:14:15 +00:00
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: Could not create the /xcatpost directory.\n";
|
2013-03-13 18:40:05 +00:00
|
|
|
exit 1;
|
2010-05-12 12:14:15 +00:00
|
|
|
}
|
|
|
|
|
2013-03-13 18:40:05 +00:00
|
|
|
# get the xCAT hostname and the mypostscript file
|
|
|
|
if (&getxcatname($servnode) != 0) {
|
|
|
|
`logger -t xcat -p local4.info "$::sdate xcataixpost: Could not determine xCAT node name."`;
|
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: Could not determine xCAT node name.\n";
|
|
|
|
exit 1;
|
2010-04-21 19:03:49 +00:00
|
|
|
}
|
2013-03-13 18:40:05 +00:00
|
|
|
my $xcatname=$::XCATNAME;
|
|
|
|
my $scriptname=$::SCRIPTNAME;
|
2010-04-21 19:03:49 +00:00
|
|
|
|
|
|
|
# get the installdir to use
|
|
|
|
my $installdir;
|
2011-11-01 11:10:06 +00:00
|
|
|
my $usenfsv4;
|
2010-04-21 19:03:49 +00:00
|
|
|
if (-f $scriptname) {
|
|
|
|
# set the timezone
|
|
|
|
my $cmd = "cat $scriptname | grep 'INSTALLDIR='";
|
|
|
|
&runcmd($cmd);
|
|
|
|
my $dline = $::outref;
|
|
|
|
my ($junk, $installdir) = split(/=/, $dline);
|
2013-06-10 19:55:27 +00:00
|
|
|
if ($installdir) {
|
|
|
|
chomp $installdir;
|
|
|
|
$installdir =~ s/^(\'|\")(.*)(\"|\')$/$2/; # remove any surrounding quotes
|
|
|
|
}
|
2011-11-01 11:10:06 +00:00
|
|
|
$cmd = "cat $scriptname | grep 'USENFSV4ONAIX='";
|
|
|
|
&runcmd($cmd);
|
|
|
|
$dline = $::outref;
|
|
|
|
($junk, $usenfsv4) = split(/=/, $dline);
|
2011-11-02 13:50:38 +00:00
|
|
|
if ($usenfsv4)
|
|
|
|
{
|
|
|
|
chomp $usenfsv4;
|
|
|
|
}
|
2010-04-21 19:03:49 +00:00
|
|
|
}
|
|
|
|
if (!$installdir) {
|
|
|
|
$installdir = "/install";
|
|
|
|
}
|
|
|
|
|
2009-03-25 14:38:16 +00:00
|
|
|
# if the /xcatpost dir has not been populated or the -c option is
|
|
|
|
# specified then do the mount and copy of /install/postscripts
|
|
|
|
if ( !(-f "/xcatpost/xcataixpost") || $::opt_c ) {
|
2008-06-12 12:55:29 +00:00
|
|
|
|
2009-03-25 14:38:16 +00:00
|
|
|
# get the contents of the /install/postscripts dir on the server
|
|
|
|
# - mount dir from server and copy files
|
2011-10-24 11:25:16 +00:00
|
|
|
my $mcmd;
|
2011-11-01 11:10:06 +00:00
|
|
|
if ($usenfsv4 && ($usenfsv4 =~ /1|Yes|yes|YES|Y|y/))
|
2011-10-24 11:25:16 +00:00
|
|
|
{
|
|
|
|
$mcmd = "mkdir -p /xcatmnt; mount -o vers=4 $servnode:$installdir/postscripts /xcatmnt";
|
|
|
|
} else {
|
|
|
|
$mcmd = "mkdir -p /xcatmnt; mount $servnode:$installdir/postscripts /xcatmnt";
|
|
|
|
}
|
2009-03-25 14:38:16 +00:00
|
|
|
if (&runcmd($mcmd) != 0) {
|
2013-02-28 20:45:45 +00:00
|
|
|
`logger -t xcat -p local4.info "$::sdate xcataixpost: Could not mount $installdir/postscripts from $servnode."`;
|
2010-04-21 19:03:49 +00:00
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: Could not mount $installdir/postscripts from $servnode.\n";
|
2009-03-25 14:38:16 +00:00
|
|
|
}
|
2009-03-10 13:56:52 +00:00
|
|
|
|
2009-11-25 15:55:08 +00:00
|
|
|
my $cpcmd;
|
|
|
|
|
2009-03-25 14:38:16 +00:00
|
|
|
if ((@ARGV==0) || ($ARGV[0] != 2)) {
|
2012-12-01 11:48:51 +00:00
|
|
|
#$cpcmd = "cp -p -R /xcatmnt/* /xcatpost 2>/dev/null";
|
|
|
|
$cpcmd = "/usr/bin/rsync -Lprogtz /xcatmnt/* /xcatpost 2>/dev/null";
|
2009-03-25 14:38:16 +00:00
|
|
|
} else {
|
|
|
|
# when argv[1]=2, there is only one postscript file,
|
|
|
|
# user wants only download it to save time
|
|
|
|
$cpcmd= "cp /xcatmnt/$ARGV[1] /xcatpost >/dev/null 2>&1";
|
|
|
|
}
|
2008-11-09 03:20:21 +00:00
|
|
|
|
2009-03-25 14:38:16 +00:00
|
|
|
if (&runcmd($cpcmd) != 0) {
|
|
|
|
# print "$::sdate xcataixpost: Could not copy postscripts to /xcatpost.\n";
|
|
|
|
# print $::LOG_FILE "$::sdate xcataixpost: Could not copy postscripts to /xcatpost.\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
my $ucmd = "umount /xcatmnt; rmdir /xcatmnt";
|
|
|
|
if (&runcmd($ucmd) != 0) {
|
2013-02-28 20:45:45 +00:00
|
|
|
`logger -t xcat -p local4.info "$::sdate xcataixpost: Could not unmount $installdir."`;
|
2010-04-21 19:03:49 +00:00
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: Could not unmount $installdir/postscripts.\n";
|
2009-03-25 14:38:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} # end recopy postscripts
|
2009-03-10 13:56:52 +00:00
|
|
|
|
2008-06-12 12:55:29 +00:00
|
|
|
# make sure all are executable
|
|
|
|
my $chcmd = "chmod +x /xcatpost/*";
|
|
|
|
if (&runcmd($chcmd) != 0) {
|
2013-02-28 20:45:45 +00:00
|
|
|
`logger -t xcat -p local4.info "$::sdate xcataixpost: Could not change /xcatpost file permissions."`;
|
2008-06-12 12:55:29 +00:00
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: Could not change /xcatpost file permissions.\n";
|
|
|
|
}
|
2012-08-21 11:11:58 +00:00
|
|
|
# set TZ only on install
|
|
|
|
if (@ARGV==0) {
|
|
|
|
if (-f $scriptname) {
|
2009-04-03 20:13:17 +00:00
|
|
|
# set the timezone
|
2012-08-20 20:52:20 +00:00
|
|
|
my $cmd = "cat $scriptname | grep 'TIMEZONE='";
|
|
|
|
&runcmd($cmd);
|
|
|
|
my $TZline = $::outref;
|
|
|
|
my ($junk, $tz) = split(/=/, $TZline);
|
|
|
|
if ($tz) {
|
2009-04-09 17:49:05 +00:00
|
|
|
chomp $tz;
|
2009-04-03 20:13:17 +00:00
|
|
|
my $tzcmd = qq~/usr/bin/chtz $tz >/dev/null 2>&1~;
|
|
|
|
if (&runcmd($tzcmd) != 0) {
|
2011-11-02 14:04:33 +00:00
|
|
|
my $msg = "$::sdate xcataixpost: Could not set timezone.\n";
|
2012-05-15 07:21:12 +00:00
|
|
|
`logger -t xcat -p local4.warning $msg`;
|
2009-04-03 20:13:17 +00:00
|
|
|
} else {
|
2012-08-21 11:11:58 +00:00
|
|
|
&runcmd("export TZ=$tz");
|
|
|
|
}
|
2009-04-03 20:13:17 +00:00
|
|
|
}
|
2012-08-21 11:11:58 +00:00
|
|
|
}
|
2009-04-03 20:13:17 +00:00
|
|
|
}
|
|
|
|
|
2008-06-12 12:55:29 +00:00
|
|
|
# check & run the postscript
|
2008-09-29 16:33:21 +00:00
|
|
|
my $nodesetstat="standalone";
|
2008-06-12 12:55:29 +00:00
|
|
|
if (-f $scriptname)
|
|
|
|
{
|
2009-07-15 13:08:51 +00:00
|
|
|
# when called by the updatenode command,
|
|
|
|
# modify the UPDATENODE flag to 1
|
2009-06-04 15:33:44 +00:00
|
|
|
if (@ARGV > 0) {
|
2010-03-21 13:11:47 +00:00
|
|
|
if ($ARGV[0] == 1 || $ARGV[0] == 2) {
|
2011-11-02 14:04:33 +00:00
|
|
|
my $TMP=`sed -e 's/UPDATENODE=0/UPDATENODE=1/g' $scriptname`;
|
2010-03-21 13:11:47 +00:00
|
|
|
`echo "$TMP" > $scriptname`;
|
|
|
|
} elsif ($ARGV[0] == 5) {
|
2011-11-02 14:04:33 +00:00
|
|
|
my $TMP=`sed -e 's/UPDATENODE=0/UPDATENODE=1\\\nUPDATESECURITY=1\\\nexport UPDATESECURITY/g' $scriptname`;
|
2010-03-21 13:11:47 +00:00
|
|
|
`echo "$TMP" > $scriptname`;
|
|
|
|
}
|
2009-06-04 15:33:44 +00:00
|
|
|
}
|
2013-06-10 19:55:27 +00:00
|
|
|
# see if any arguments and if there are script on the argument list
|
|
|
|
my $lengtharg1=0;
|
|
|
|
if (defined ($ARGV[1])) {
|
|
|
|
$lengtharg1= length ($ARGV[1]);
|
|
|
|
}
|
2013-02-28 20:45:45 +00:00
|
|
|
if ((@ARGV>1) && ($lengtharg1 != 0)) { # no postscript list
|
2008-09-26 23:07:45 +00:00
|
|
|
my $scripts=$ARGV[1];
|
2013-02-28 20:45:45 +00:00
|
|
|
`logger -t xcat -p local4.info "$::sdate xcataixpost: ARGV > 1."`;
|
2008-09-11 04:43:33 +00:00
|
|
|
my $POSTS=join('\n', split(',', $scripts));
|
|
|
|
#print "scripts=$scripts\n";
|
2009-12-28 03:25:36 +00:00
|
|
|
#remove all the postbootscripts
|
2013-02-28 20:45:45 +00:00
|
|
|
my $PSTMP=`sed "/# postbootscripts-start-here/,/# postbootscripts-end-here/ d" $scriptname`;
|
2009-12-28 03:25:36 +00:00
|
|
|
`echo "$PSTMP" > $scriptname`;
|
2008-09-11 04:43:33 +00:00
|
|
|
#remove all the postscripts
|
2013-02-11 19:07:08 +00:00
|
|
|
my $TMP=`sed "/# postscripts-start-here/,/# postscripts-end-here/ d" $scriptname`;
|
2008-09-11 04:43:33 +00:00
|
|
|
`echo "$TMP" > $scriptname`;
|
2009-09-18 11:28:34 +00:00
|
|
|
`echo "# postscripts-start-here" >> $scriptname`;
|
2008-09-11 04:43:33 +00:00
|
|
|
#add requested postscripts in
|
|
|
|
`echo "$POSTS" | tr "," "\n" >> $scriptname`;
|
2009-09-18 11:28:34 +00:00
|
|
|
`echo "# postscripts-end-here" >> $scriptname`;
|
2009-07-15 13:08:51 +00:00
|
|
|
}
|
|
|
|
|
2009-09-18 11:28:34 +00:00
|
|
|
# use the run_ps subroutine to run the postscripts
|
2013-02-11 19:07:08 +00:00
|
|
|
my $TMP1=`sed "/# postscripts-start-here/,/# postscripts-end-here/ s/\\(.*\\)/run_ps \\1/;s/run_ps *#/#/;s/run_ps *\$//" $scriptname`;
|
2009-12-28 03:25:36 +00:00
|
|
|
`echo "$TMP1" > $scriptname`;
|
2013-02-11 19:07:08 +00:00
|
|
|
my $TMP2=`sed "/# postbootscripts-start-here/,/# postbootscripts-end-here/ s/\\(.*\\)/run_ps \\1/;s/run_ps *#/#/;s/run_ps *\$//" $scriptname`;
|
2009-09-18 11:28:34 +00:00
|
|
|
`echo "
|
|
|
|
# subroutine used to run postscripts
|
|
|
|
run_ps () {
|
2010-04-09 06:12:40 +00:00
|
|
|
logdir=\\"/var/log/xcat\\"
|
2010-04-13 03:48:29 +00:00
|
|
|
mkdir -p \\\$logdir
|
2010-04-09 06:12:40 +00:00
|
|
|
logfile=\\"/var/log/xcat/xcat.log\\"
|
|
|
|
|
2009-09-18 11:28:34 +00:00
|
|
|
if [[ -f \\\$1 ]]; then
|
2012-04-01 03:57:47 +00:00
|
|
|
echo \\"\\\`date\\\` Running postscript: \\\$@\\" | tee -a \\\$logfile
|
2011-06-15 14:10:34 +00:00
|
|
|
./\\\$@ 2>&1 | tee -a \\\$logfile
|
2009-09-18 11:28:34 +00:00
|
|
|
else
|
2012-04-01 03:57:47 +00:00
|
|
|
echo \\"\\\`date\\\` Postscript \\\$1 does NOT exist.\\" | tee -a \\\$logfile
|
2009-09-18 11:28:34 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
# subroutine end
|
|
|
|
|
|
|
|
" > $scriptname`;
|
2009-12-28 03:25:36 +00:00
|
|
|
`echo "$TMP2" >> $scriptname`;
|
2009-09-18 11:28:34 +00:00
|
|
|
|
2009-07-15 13:08:51 +00:00
|
|
|
$nodesetstat=`grep "NODESETSTATE=" $scriptname|awk -F \= '{print \$2}'`;
|
|
|
|
chomp($nodesetstat);
|
2009-04-09 12:12:29 +00:00
|
|
|
$ENV{PATH}="/xcatpost:$ENV{PATH}";
|
2009-03-29 11:05:56 +00:00
|
|
|
&runcmd("cd /xcatpost;$scriptname");
|
2013-06-12 12:59:11 +00:00
|
|
|
if ($::outref) {
|
|
|
|
print "$::sdate xcataixpost: run: $cmd - $::outref\n";
|
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: run: $cmd - $::outref\n";
|
|
|
|
} else {
|
|
|
|
print "$::sdate xcataixpost: run: $cmd \n";
|
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: run: $cmd \n";
|
|
|
|
}
|
2008-06-12 12:55:29 +00:00
|
|
|
} else {
|
2013-03-11 19:34:21 +00:00
|
|
|
`logger -t xcat -p local4.info "$::sdate xcataixpost: Could not find post script for $xcatname."`;
|
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: Could not find post script for $xcatname.\n";
|
2008-06-12 12:55:29 +00:00
|
|
|
}
|
|
|
|
|
2013-02-28 20:45:45 +00:00
|
|
|
if (@ARGV<1) { # not running updatenode
|
2009-03-24 03:12:03 +00:00
|
|
|
my $update=1;
|
|
|
|
if (-f $scriptname) {
|
2009-03-24 19:44:23 +00:00
|
|
|
my $CNS=`grep NODESTATUS= $scriptname`;
|
|
|
|
if ((!$?) && ($CNS =~ /\'0\'|\'N\'|\'n\'/)) { $update=0;} #only update is nonodestatus is not set in the site table
|
2009-03-24 03:12:03 +00:00
|
|
|
}
|
|
|
|
if ($update) {
|
2011-08-26 03:40:55 +00:00
|
|
|
my $keywd="installstatus";
|
|
|
|
my $state="booted";
|
|
|
|
if (&updateflag($keywd, $state) != 0) {
|
2013-02-28 20:45:45 +00:00
|
|
|
`logger -t xcat -p local4.info "$::sdate xcataixpost: Failed to update the xCAT server."`;
|
2009-03-24 03:12:03 +00:00
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: Failed to update the xCAT server..\n";
|
|
|
|
}
|
2008-09-26 23:07:45 +00:00
|
|
|
}
|
2008-11-09 03:20:21 +00:00
|
|
|
} else {
|
2013-02-28 20:45:45 +00:00
|
|
|
#called by updatenode, tell user it is done
|
|
|
|
`logger -t xcat -p local4.info "xcataixpost finished running postscripts"`;
|
2010-04-06 08:17:04 +00:00
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: returned from postscript.\n";
|
2008-09-26 23:07:45 +00:00
|
|
|
}
|
|
|
|
|
2009-04-03 20:13:17 +00:00
|
|
|
if (-f $scriptname) {
|
|
|
|
|
2010-06-03 14:15:21 +00:00
|
|
|
if ($::ROOTPW) {
|
|
|
|
chomp $::ROOTPW;
|
|
|
|
my $pwcmd;
|
|
|
|
|
|
|
|
if ($::CRYPTMETHOD) {
|
|
|
|
$pwcmd = qq~echo "root:$::ROOTPW" | /bin/chpasswd -e -c >/dev/null 2>&1~;
|
|
|
|
} else {
|
|
|
|
$pwcmd = qq~echo "root:$::ROOTPW" | /bin/chpasswd -c >/dev/null 2>&1~;
|
|
|
|
}
|
2009-04-03 20:13:17 +00:00
|
|
|
if (&runcmd($pwcmd) != 0) {
|
2011-11-02 14:04:33 +00:00
|
|
|
my $msg = "$::sdate xcataixpost: Could not set root password.\n";
|
2012-05-15 07:21:12 +00:00
|
|
|
`logger -t xcat -p local4.warning $msg`;
|
2009-04-03 20:13:17 +00:00
|
|
|
}
|
2009-03-10 13:56:52 +00:00
|
|
|
}
|
|
|
|
}
|
2008-09-26 23:07:45 +00:00
|
|
|
|
2009-06-08 19:21:42 +00:00
|
|
|
# If this is a diskfull node then remove the xcat entry in the inittab file
|
2010-02-26 08:57:19 +00:00
|
|
|
$nodesetstat =~ s/'|"//g;
|
2009-06-08 19:21:42 +00:00
|
|
|
if ($nodesetstat eq 'standalone') {
|
|
|
|
# see if it is already there
|
|
|
|
my $lsicmd = "/usr/sbin/lsitab xcat > /dev/null 2>&1";
|
2010-08-30 07:57:46 +00:00
|
|
|
if (&runcmd($lsicmd, 0) == 0) {
|
2009-06-08 19:21:42 +00:00
|
|
|
# ok - remove the entry
|
|
|
|
my $rmitab_cmd = 'rmitab "xcat" > /dev/null 2>&1';
|
|
|
|
if (&runcmd($rmitab_cmd) != 0) {
|
2013-02-28 20:45:45 +00:00
|
|
|
`logger -t xcat -p local4.info "$::sdate xcataixpost: Could not remove xcataixpost from /etc/inittab."`;
|
2009-06-08 19:21:42 +00:00
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: Could not remove xcataixpost from /etc/inittab.\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-08-26 03:40:55 +00:00
|
|
|
|
|
|
|
if ($nodesetstat eq 'diskless') {
|
|
|
|
# see if BASECUST_REMOVAL is set in /etc/niminfo
|
|
|
|
if (-f "/etc/niminfo") {
|
2012-05-23 18:17:11 +00:00
|
|
|
$::NOERROR=1;
|
2011-08-26 03:40:55 +00:00
|
|
|
$cmd = "cat /etc/niminfo | grep 'BASECUST_REMOVAL'";
|
|
|
|
&runcmd($cmd);
|
|
|
|
my $line = $::outref;
|
|
|
|
my ($junk, $torm) = split(/=/, $line);
|
|
|
|
|
2012-05-23 18:17:11 +00:00
|
|
|
$::NOERROR=0;
|
2011-08-26 03:40:55 +00:00
|
|
|
$cmd = "cat /etc/niminfo | grep 'NIM_HOSTNAME'";
|
|
|
|
&runcmd($cmd);
|
|
|
|
$line = $::outref;
|
|
|
|
my ($junkn, $hostn) = split(/=/, $line);
|
|
|
|
|
|
|
|
if ($torm) {
|
|
|
|
chomp $hostn;
|
|
|
|
$hostn =~ s/^\s*//;
|
|
|
|
|
|
|
|
# notify the xcatd on nim master to remove this value
|
|
|
|
# so that it will not be present in the subsequent reboots
|
|
|
|
my $keywd = "basecustremv";
|
|
|
|
if (&updateflag($keywd, $hostn) != 0) {
|
2013-02-28 20:45:45 +00:00
|
|
|
`logger -t xcat -p local4.info "$::sdate xcataixpost: Failed to update the xCAT server."`;
|
2011-08-26 03:40:55 +00:00
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: Failed to update the xCAT server.\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-02 14:04:33 +00:00
|
|
|
my $cleanupxcatpost = `grep "CLEANUPXCATPOST=" $scriptname|awk -F \= '{print \$2}'`;
|
2011-07-04 08:58:30 +00:00
|
|
|
if ((!$?) && ($cleanupxcatpost =~ /\'1\'|\'yes\'/i)) {
|
|
|
|
&runcmd("cd /; rm -rf /xcatpost/*");
|
|
|
|
}
|
2008-06-12 12:55:29 +00:00
|
|
|
close($::LOG_FILE);
|
|
|
|
|
|
|
|
exit 0;
|
|
|
|
|
|
|
|
#####################################################
|
2013-05-31 18:33:47 +00:00
|
|
|
# This routine downloads the mypostscript from /tftpboot/mypostscripts
|
|
|
|
# First try and tftp the file
|
|
|
|
# If that does not get it, then connect to getpostscript.pm to send the
|
|
|
|
# data
|
|
|
|
# input xcatname - nodename as in the database
|
|
|
|
# scriptname is /xcatpost/mypostscript_<xcatname>
|
2008-06-12 12:55:29 +00:00
|
|
|
#
|
|
|
|
#####################################################
|
2009-07-07 14:57:17 +00:00
|
|
|
|
2013-05-31 18:33:47 +00:00
|
|
|
sub getmypost {
|
|
|
|
my $xcatname=shift;
|
|
|
|
my $scriptname=shift;
|
2009-07-07 14:57:17 +00:00
|
|
|
|
2013-05-31 18:33:47 +00:00
|
|
|
# If the tftpdir is not /tftpboot,
|
|
|
|
# should use the -s flag to specify the tftpdir.
|
|
|
|
# using gettab to get the tftpdir from MN/SN is not efficient
|
|
|
|
# and has problem with sending multiple commands through one socket connection
|
|
|
|
if( !defined($TFTPDIR) ) {
|
|
|
|
$TFTPDIR="/tftpboot";
|
2009-07-07 14:57:17 +00:00
|
|
|
}
|
2008-06-12 12:55:29 +00:00
|
|
|
|
2013-06-12 12:59:11 +00:00
|
|
|
# remove the mypostscript file, so make sure we get a new one
|
2013-05-31 18:33:47 +00:00
|
|
|
|
2013-06-12 12:59:11 +00:00
|
|
|
&runcmd("rm -rf $scriptname");
|
2013-05-31 18:33:47 +00:00
|
|
|
|
2013-06-10 19:55:27 +00:00
|
|
|
# try to get the file with tftp first it is normal the file is not available, do not report
|
|
|
|
# error
|
|
|
|
`tftp -o $scriptname $servnode $TFTPDIR/mypostscripts/mypostscript.$xcatname 2>&1`;
|
2013-06-12 12:59:11 +00:00
|
|
|
if ((-e $scriptname) && (! (-z $scriptname))) { # got the file and it is not empty
|
2013-05-31 18:33:47 +00:00
|
|
|
`logger -t xcat -p local4.info "$::sdate xcataixpost: tftp got $scriptname."`;
|
|
|
|
|
|
|
|
my $content;
|
|
|
|
if (!open($content, "<", $scriptname) ) {
|
2013-02-28 20:45:45 +00:00
|
|
|
`logger -t xcat -p local4.info "$::sdate xcataixpost: Could not open $scriptname."`;
|
2013-05-31 18:33:47 +00:00
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: Could not open $scriptname.\n";
|
|
|
|
close $content;
|
2009-07-07 14:57:17 +00:00
|
|
|
return 1;
|
2013-05-31 18:33:47 +00:00
|
|
|
}
|
|
|
|
while (<$content>) {
|
|
|
|
my $line = $_;
|
|
|
|
$line =~ s/^\s+//;
|
|
|
|
if ($line =~ /=/) {
|
|
|
|
my ($attr, $val) = $line =~ /^\s*(\S+?)\s*=\s*(\S*.*)$/;
|
|
|
|
if( defined( $attr ) ) {
|
|
|
|
if ($attr eq 'ROOTPW') {
|
|
|
|
$::ROOTPW=$val;
|
|
|
|
}
|
|
|
|
if ($attr eq 'CRYPTMETHOD') {
|
|
|
|
$::CRYPTMETHOD=$val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} # end while
|
|
|
|
close $content;
|
2009-08-24 09:35:33 +00:00
|
|
|
|
2013-05-31 18:33:47 +00:00
|
|
|
}
|
2013-06-12 12:59:11 +00:00
|
|
|
if (-z $scriptname) { # file is empty , get rid of it
|
|
|
|
&runcmd("rm -rf $scriptname");
|
|
|
|
}
|
|
|
|
|
2008-06-12 12:55:29 +00:00
|
|
|
|
2013-05-31 18:33:47 +00:00
|
|
|
# if could not get the file, then ask for the data
|
|
|
|
|
|
|
|
if(!( -f $scriptname)) {
|
|
|
|
my $port = "3001";
|
|
|
|
# open a socket to request credentials
|
|
|
|
my $remote = IO::Socket::SSL->new(
|
|
|
|
PeerAddr => $servnode,
|
|
|
|
PeerPort => $port,
|
|
|
|
Proto => 'tcp',
|
|
|
|
);
|
|
|
|
# get ready to create the file
|
|
|
|
if (!open(POSTSCRIPT, ">$scriptname") ) {
|
|
|
|
`logger -t xcat -p local4.info "$::sdate xcataixpost: Could not open $scriptname."`;
|
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: Could not open $scriptname.\n"
|
|
|
|
;
|
|
|
|
close $remote;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
# setup the perl library path for xcat-dep packages
|
|
|
|
# this is necessary for AIX 5.3V/61H and beyond
|
|
|
|
# but does not hurt old AIX versions
|
|
|
|
print POSTSCRIPT "PERL5LIB='/usr/opt/perl5/lib/5.8.2:/usr/opt/perl5/lib/5.8.2/aix-thread-multi:/usr/opt/perl5/lib/site_perl/5.8.2:/usr/opt/perl5/lib/site_perl/5.8.2/aix-thread-multi'\n";
|
|
|
|
print POSTSCRIPT "export PERL5LIB\n";
|
|
|
|
|
2009-07-07 14:57:17 +00:00
|
|
|
|
2013-05-31 18:33:47 +00:00
|
|
|
unless ($remote) {
|
|
|
|
`logger -t xcat -p local4.info "$::sdate xcataixpost: Cannot connect to host \'$servnode\'"`;
|
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: Cannot connect to host \'$servnode\'\n";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
# request must be in XML format
|
|
|
|
print $remote "<xcatrequest>\n";
|
|
|
|
print $remote " <command>getpostscript</command>\n";
|
|
|
|
print $remote "</xcatrequest>\n";
|
|
|
|
|
|
|
|
`logger -t xcat -p local4.info "$::sdate xcataixpost: calling getpostscript to get the data"`;
|
|
|
|
# get reponse in XML format
|
|
|
|
my $response='';
|
|
|
|
my $rsp;
|
|
|
|
while (<$remote>) {
|
|
|
|
$response .= $_;
|
|
|
|
if ($response =~ m/<\/xcatresponse>/) {
|
|
|
|
$rsp = eval { XMLin($response,SuppressEmpty=>undef,ForceArray=>1) };
|
|
|
|
if ($rsp->{serverdone}) {
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
# now create the mypostscript* files from the sent data
|
|
|
|
foreach my $line (@{$rsp->{data}}) {
|
2010-06-03 14:15:21 +00:00
|
|
|
$line =~ s/^\s+//;
|
|
|
|
if ($line =~ /=/) {
|
|
|
|
my ($attr, $val) = $line =~ /^\s*(\S+?)\s*=\s*(\S*.*)$/;
|
|
|
|
if ($attr eq 'ROOTPW') {
|
|
|
|
$::ROOTPW=$val;
|
|
|
|
}
|
|
|
|
if ($attr eq 'CRYPTMETHOD') {
|
|
|
|
$::CRYPTMETHOD=$val;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (($line =~ /ROOTPW/) || ($line =~ /CRYPTMETHOD/)) {
|
|
|
|
next;
|
|
|
|
}
|
2009-07-07 14:57:17 +00:00
|
|
|
print POSTSCRIPT "$line";
|
2013-05-31 18:33:47 +00:00
|
|
|
}
|
|
|
|
$response='';
|
2012-11-22 03:04:34 +00:00
|
|
|
|
2013-05-31 18:33:47 +00:00
|
|
|
}
|
|
|
|
} # end while
|
2012-11-22 03:04:34 +00:00
|
|
|
|
2013-05-31 18:33:47 +00:00
|
|
|
close(POSTSCRIPT);
|
2012-11-22 03:04:34 +00:00
|
|
|
close $remote;
|
2013-05-31 18:33:47 +00:00
|
|
|
}
|
2013-03-13 18:40:05 +00:00
|
|
|
|
2013-05-31 18:33:47 +00:00
|
|
|
return 0;
|
2012-11-22 03:04:34 +00:00
|
|
|
}
|
|
|
|
|
2008-09-26 23:07:45 +00:00
|
|
|
############################################################
|
|
|
|
#
|
|
|
|
# updateflag
|
|
|
|
# Tells xCAT on the server that the post scripts is done.
|
|
|
|
#
|
|
|
|
############################################################
|
|
|
|
sub updateflag {
|
2011-08-26 03:40:55 +00:00
|
|
|
my $keywd=shift;
|
|
|
|
my $state=shift;
|
2008-09-29 16:33:21 +00:00
|
|
|
|
2008-09-26 23:07:45 +00:00
|
|
|
my $port = "3002";
|
2010-08-18 01:34:22 +00:00
|
|
|
my $servip = `host $servnode | awk '{print \$3}'`;
|
|
|
|
chomp($servip);
|
2010-09-07 05:55:11 +00:00
|
|
|
$servip =~ s/,$//; # remove trailing comma
|
2010-08-18 01:34:22 +00:00
|
|
|
my $remote = IO::Socket::INET->new( Proto => "tcp", PeerAddr => $servip, PeerPort => $port, Timeout => 0);
|
|
|
|
|
|
|
|
my $try = 10;
|
|
|
|
while (!$remote && $try-- > 0) {
|
|
|
|
sleep 1;
|
|
|
|
$remote = IO::Socket::INET->new( Proto => "tcp", PeerAddr => $servip, PeerPort => $port, Timeout => 0);
|
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: Cannot connect to host \'$servip\'\n";
|
|
|
|
}
|
2008-09-26 23:07:45 +00:00
|
|
|
unless ($remote) {
|
2010-08-18 01:34:22 +00:00
|
|
|
print "$::sdate xcataixpost: Cannot connect to host \'$servip\'\n";
|
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: Cannot connect to host \'$servip\'\n";
|
2008-09-26 23:07:45 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
$remote->autoflush(1);
|
|
|
|
|
|
|
|
my $line;
|
|
|
|
while (defined ($line = <$remote>)) {
|
|
|
|
chomp $line;
|
|
|
|
if ($line eq "ready") {
|
2011-08-26 03:40:55 +00:00
|
|
|
print $remote "$keywd $state\n";
|
2008-09-26 23:07:45 +00:00
|
|
|
} elsif ($line eq "done") {
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close $remote;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-12 12:55:29 +00:00
|
|
|
#####################################################
|
|
|
|
#
|
|
|
|
# run the command
|
2010-08-30 07:57:46 +00:00
|
|
|
# the first argument is the command string
|
|
|
|
# the second argument is the log flag,
|
|
|
|
# 0 - does NOT log error message
|
|
|
|
# 1 - log error message
|
|
|
|
# if it is not specified, it equals to 1
|
2008-06-12 12:55:29 +00:00
|
|
|
#
|
|
|
|
#####################################################
|
|
|
|
sub runcmd
|
|
|
|
{
|
2010-08-30 07:57:46 +00:00
|
|
|
my ($cmd, $logerr) = @_;
|
|
|
|
|
|
|
|
if(! defined($logerr)) {
|
|
|
|
$logerr = 1;
|
|
|
|
}
|
2010-04-06 08:17:04 +00:00
|
|
|
my $rc=0;
|
2008-06-12 12:55:29 +00:00
|
|
|
$cmd .= ' 2>&1' ;
|
|
|
|
$::outref = [];
|
|
|
|
$::outref = `$cmd`;
|
|
|
|
if ($?)
|
|
|
|
{
|
|
|
|
$rc = $? >> 8;
|
2010-08-30 07:57:46 +00:00
|
|
|
if ($rc > 0 && $logerr)
|
2008-06-12 12:55:29 +00:00
|
|
|
{
|
2012-05-23 18:17:11 +00:00
|
|
|
if ($::NOERROR == 0) { # print the error message
|
2013-06-10 19:55:27 +00:00
|
|
|
if ($::outref) {
|
2010-08-30 07:57:46 +00:00
|
|
|
print "$::sdate xcataixpost: run: $cmd - $::outref\n";
|
2013-06-10 19:55:27 +00:00
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: run: $cmd - $::outref\n";
|
|
|
|
} else {
|
|
|
|
print "$::sdate xcataixpost: run: $cmd \n";
|
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: run: $cmd \n";
|
|
|
|
}
|
2012-05-23 18:17:11 +00:00
|
|
|
}
|
2008-06-12 12:55:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $rc;
|
|
|
|
}
|
2013-03-11 19:34:21 +00:00
|
|
|
|
|
|
|
############################################################
|
|
|
|
#
|
|
|
|
# getxcatname
|
|
|
|
# determines the name of this node as it is know by xCAT
|
2013-03-13 18:40:05 +00:00
|
|
|
# request the node mypostscript_* file from the server
|
2013-03-11 19:34:21 +00:00
|
|
|
#
|
|
|
|
############################################################
|
|
|
|
sub getxcatname
|
|
|
|
{
|
2013-03-13 18:40:05 +00:00
|
|
|
my $servnode=shift;
|
2013-03-11 19:34:21 +00:00
|
|
|
|
|
|
|
my $xcatname;
|
2013-03-13 18:40:05 +00:00
|
|
|
my $scriptname;
|
|
|
|
my $xcatshort;
|
|
|
|
my $xcatlong;
|
2013-05-31 18:33:47 +00:00
|
|
|
# updatenode will input the nodename as an ENV variable NODE
|
|
|
|
# if we have this name, need not try anything else.
|
|
|
|
if ($ENV{NODE} ) {
|
|
|
|
$xcatname=$ENV{NODE};
|
|
|
|
|
|
|
|
# put the nodename in /etc/xcatinfo TODO, need logic not to
|
|
|
|
# wipe out XCATSERVER or add multiple entries
|
|
|
|
|
|
|
|
`logger -t xcat -p local4.info "$::sdate xcataixpost:name=$xcatname"`;
|
|
|
|
$scriptname = "/xcatpost/myxcatpost_" . $xcatname;
|
|
|
|
if (&getmypost($xcatname,$scriptname) == 0) {
|
|
|
|
$::XCATNAME=$xcatname;
|
|
|
|
$::SCRIPTNAME=$scriptname;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-13 18:40:05 +00:00
|
|
|
# find out what interface we use to contact the server
|
|
|
|
my $NIP;
|
|
|
|
my $tcmd=qq~/bin/traceroute $servnode~;
|
|
|
|
if (&runcmd($tcmd) != 0) {
|
|
|
|
print "$::sdate xcataixpost: Could not run traceroute.\n";
|
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: Could not run traceroute\n";
|
|
|
|
} else {
|
2013-03-12 16:38:03 +00:00
|
|
|
my @lines = ( split(/\n/, $::outref));
|
|
|
|
foreach my $l (@lines)
|
|
|
|
{
|
|
|
|
if ($l =~ /^source should be/) {
|
|
|
|
my ($n1, $n2, $n3, $nip) = split(/\s+/, $l);
|
2013-03-13 18:40:05 +00:00
|
|
|
chomp $l;
|
|
|
|
$l =~ s/^\s+//;
|
2013-03-12 16:38:03 +00:00
|
|
|
$NIP=$nip;
|
|
|
|
}
|
|
|
|
}
|
2013-03-13 18:40:05 +00:00
|
|
|
}
|
2013-03-12 16:38:03 +00:00
|
|
|
|
2013-03-13 18:40:05 +00:00
|
|
|
if ($NIP) {
|
|
|
|
# traceroute gave us an ip
|
|
|
|
$xcatname=gethostbyaddr(inet_aton($NIP), AF_INET);
|
|
|
|
if ($xcatname =~ /\./) {
|
|
|
|
$xcatlong=$xcatname;
|
|
|
|
($xcatshort = $xcatname) =~ s/\..*//;
|
2013-03-12 16:38:03 +00:00
|
|
|
} else {
|
2013-03-13 18:40:05 +00:00
|
|
|
$xcatlong="";
|
|
|
|
$xcatshort=$xcatname;
|
2013-03-11 19:34:21 +00:00
|
|
|
}
|
|
|
|
|
2013-03-13 18:40:05 +00:00
|
|
|
# try short name
|
|
|
|
if ($xcatshort) {
|
|
|
|
$scriptname = "/xcatpost/myxcatpost_" . $xcatshort;
|
|
|
|
if (&getmypost($xcatshort,$scriptname) == 0) {
|
|
|
|
$::XCATNAME=$xcatshort;
|
|
|
|
$::SCRIPTNAME=$scriptname;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# try long name - if any
|
|
|
|
if ($xcatlong) {
|
|
|
|
$scriptname = "/xcatpost/myxcatpost_" . $xcatlong;
|
|
|
|
if (&getmypost($xcatlong,$scriptname) == 0) {
|
|
|
|
$::XCATNAME=$xcatlong;
|
|
|
|
$::SCRIPTNAME=$scriptname;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# couldn't find NIP so try the primary hostname
|
|
|
|
$xcatname=hostname();
|
|
|
|
if ($xcatname =~ /\./) {
|
|
|
|
$xcatlong=$xcatname;
|
|
|
|
($xcatshort = $xcatname) =~ s/\..*//;
|
|
|
|
} else {
|
|
|
|
$xcatlong="";
|
|
|
|
$xcatshort=$xcatname;
|
|
|
|
}
|
|
|
|
|
|
|
|
# try short hostname
|
|
|
|
if ($xcatshort) {
|
|
|
|
$scriptname = "/xcatpost/myxcatpost_" . $xcatshort;
|
|
|
|
if (&getmypost($xcatshort,$scriptname) == 0) {
|
|
|
|
$::XCATNAME=$xcatshort;
|
|
|
|
$::SCRIPTNAME=$scriptname;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# try long hostname - if any
|
|
|
|
if ($xcatlong) {
|
|
|
|
$scriptname = "/xcatpost/myxcatpost_" . $xcatlong;
|
|
|
|
if (&getmypost($xcatlong,$scriptname) == 0) {
|
|
|
|
$::XCATNAME=$xcatlong;
|
|
|
|
$::SCRIPTNAME=$scriptname;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# if we get here we've exhaused all possibilities
|
|
|
|
`logger -t xcat -p local4.info "$::sdate xcataixpost: Could not get the xCAT post script for this node."`;
|
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: Could not get the xCAT post script for this node.\n";
|
|
|
|
|
|
|
|
return 1;
|
2013-03-11 19:34:21 +00:00
|
|
|
}
|