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
|
|
|
|
#
|
|
|
|
#####################################################
|
|
|
|
|
|
|
|
use File::Path;
|
|
|
|
use IO::Socket;
|
|
|
|
|
|
|
|
# since we don't have syslog set up yet we'll
|
|
|
|
# just save msgs in a local log file
|
|
|
|
$logdir = "/var/log/xcat";
|
|
|
|
|
|
|
|
if (!-d $logdir) {
|
|
|
|
mkpath($logdir);
|
|
|
|
}
|
|
|
|
|
|
|
|
$::sdate = `/bin/date`;
|
|
|
|
chomp $sdate;
|
|
|
|
my $logfile = $logdir . "/xcat.log";
|
|
|
|
|
|
|
|
# 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;
|
|
|
|
|
2008-10-15 21:01:38 +00:00
|
|
|
|
2008-06-12 12:55:29 +00:00
|
|
|
# get hostname
|
|
|
|
$::shorthost = `hostname -s`;
|
|
|
|
chomp $::shorthost;
|
|
|
|
|
|
|
|
# get the name of my service node/NIM master from the /etc/niminfo file
|
|
|
|
if (-f "/etc/niminfo") {
|
|
|
|
$cmd = "cat /etc/niminfo | grep 'NIM_MASTER_HOSTNAME'";
|
|
|
|
&runcmd($cmd);
|
|
|
|
my $SNline = $::outref;
|
|
|
|
my $junk;
|
|
|
|
($junk, $servnode) = split(/=/, $SNline);
|
|
|
|
$servnode =~ s/^\s*//;
|
|
|
|
chomp $servnode;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
print "$::sdate xcataixpost: Could not find /etc/niminfo file.\n";
|
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: Could not find /etc/niminfo file.\n";
|
|
|
|
close($::LOG_FILE);
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
# create the xcatpost dir
|
|
|
|
my $cmd = "mkdir -p /xcatpost";
|
|
|
|
if (&runcmd($cmd) != 0) {
|
|
|
|
print "$::sdate xcataixpost: Could not make the /xcatpost directory.\n";
|
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: Could not make the /xcatpost directory.\n";
|
|
|
|
close($::LOG_FILE);
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
2008-10-07 17:45:21 +00:00
|
|
|
# save the name of the xCAT server in case the /etc/niminfo file
|
|
|
|
# gets overwritten
|
|
|
|
my $xcatinfo="/etc/xcatinfo";
|
|
|
|
open(XCATINFO,">",$xcatinfo);
|
|
|
|
print XCATINFO "XCATSERVER=$servnode\n";
|
|
|
|
close(XCATINFO);
|
|
|
|
|
2008-11-09 03:20:21 +00:00
|
|
|
|
2008-06-12 12:55:29 +00:00
|
|
|
# get the contents of the /install/postscripts dir on the server
|
2008-11-09 03:20:21 +00:00
|
|
|
my $rcpcmd;
|
|
|
|
if ((@ARGV==0) || ($ARGV[0] != 2)) {
|
|
|
|
$rcpcmd= "rcp -r $servnode:/install/postscripts/* /xcatpost";
|
|
|
|
} else {
|
|
|
|
#when argv[1]=2, there is only one postscript file, user wants only download it to save time
|
|
|
|
$rcpcmd= "rcp $servnode:/install/postscripts/$ARGV[1] /xcatpost";
|
|
|
|
}
|
|
|
|
|
2008-06-12 12:55:29 +00:00
|
|
|
if (&runcmd($rcpcmd) != 0) {
|
|
|
|
print "$::sdate xcataixpost: Could not rcp file from $servnode.\n";
|
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: Could not rcp file from $servnode.\n";
|
|
|
|
close($::LOG_FILE);
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
# request the xCAT postscript for this particular node
|
|
|
|
$scriptname = "/xcatpost/myxcatpost_" . $::shorthost;
|
|
|
|
if (&getmypost != 0) {
|
|
|
|
print "$::sdate xcataixpost: Could not get the xCAT post script for this node.\n";
|
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: Could not get the xCAT post script for this node.\n";
|
|
|
|
close($::LOG_FILE);
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
# make sure all are executable
|
|
|
|
my $chcmd = "chmod +x /xcatpost/*";
|
|
|
|
if (&runcmd($chcmd) != 0) {
|
|
|
|
print "$::sdate xcataixpost: Could not change /xcatpost file permissions.\n";
|
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: Could not change /xcatpost file permissions.\n";
|
|
|
|
close($::LOG_FILE);
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
# 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)
|
|
|
|
{
|
2008-10-15 21:01:38 +00:00
|
|
|
if (@ARGV>1) {
|
2008-09-26 23:07:45 +00:00
|
|
|
my $scripts=$ARGV[1];
|
2008-09-11 04:43:33 +00:00
|
|
|
my $POSTS=join('\n', split(',', $scripts));
|
|
|
|
#print "scripts=$scripts\n";
|
|
|
|
#remove all the postscripts
|
|
|
|
my $TMP=`sed "/postscripts-start-here/,/postscripts-end-here/ d" $scriptname`;
|
|
|
|
`echo "$TMP" > $scriptname`;
|
|
|
|
#add requested postscripts in
|
|
|
|
`echo "$POSTS" | tr "," "\n" >> $scriptname`;
|
|
|
|
}
|
|
|
|
|
2008-09-29 16:33:21 +00:00
|
|
|
$nodesetstat=`grep "NODESETSTATE=" $scriptname|awk -F \= '{print \$2}'`;
|
|
|
|
chomp($nodesetstat);
|
|
|
|
|
2008-09-11 22:03:01 +00:00
|
|
|
if (&runcmd("cd /xcatpost;$scriptname") != 0)
|
2008-06-12 12:55:29 +00:00
|
|
|
{
|
|
|
|
print "$::sdate xcataixpost: Could not run $scriptname.\n";
|
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: Could not run $scriptname.\n";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
print "$::sdate xcataixpost: Could not find post script for $::shorthost.\n";
|
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: Could not find post script for $::shorthost.\n";
|
|
|
|
}
|
|
|
|
|
2008-10-15 21:01:38 +00:00
|
|
|
|
2008-09-26 23:07:45 +00:00
|
|
|
if (@ARGV<1) {
|
2008-09-29 16:33:21 +00:00
|
|
|
if (&updateflag($nodesetstat) != 0) {
|
2008-09-26 23:07:45 +00:00
|
|
|
print "$::sdate xcataixpost: Failed to update the xCAT server.\n";
|
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: Failed to update the xCAT server..\n";
|
|
|
|
}
|
2008-11-09 03:20:21 +00:00
|
|
|
} else {
|
|
|
|
#called by updatenode, infrom user it is done
|
|
|
|
print "returned";
|
2008-09-26 23:07:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-12 12:55:29 +00:00
|
|
|
close($::LOG_FILE);
|
|
|
|
|
|
|
|
exit 0;
|
|
|
|
|
|
|
|
#####################################################
|
|
|
|
#
|
|
|
|
# getmypost
|
|
|
|
# Get the xCAT post script info for this node
|
|
|
|
# and write it to a file
|
|
|
|
#
|
|
|
|
#####################################################
|
|
|
|
sub getmypost {
|
|
|
|
|
|
|
|
my $port = "3002";
|
|
|
|
|
|
|
|
my $remote = IO::Socket::INET->new( Proto => "tcp", PeerAddr => $servnode, PeerPort => $port, );
|
|
|
|
|
|
|
|
unless ($remote) {
|
|
|
|
print "$::sdate xcataixpost: Cannot connect to host \'$servnode\'\n";
|
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: Cannot connect to host \'$servnode\'\n";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
$remote->autoflush(1);
|
|
|
|
print $remote "getpostscript\n";
|
|
|
|
|
|
|
|
if (!open(POSTSCRIPT, ">$scriptname") ) {
|
|
|
|
print "$::sdate xcataixpost: Could not open $scriptname.\n";
|
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: Could not open $scriptname.\n";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $line;
|
|
|
|
while (defined ($line = <$remote>)) {
|
|
|
|
chomp $line;
|
|
|
|
if ( ($line eq "ready") || ($line eq "done")) {
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
print POSTSCRIPT "$line\n";
|
|
|
|
}
|
|
|
|
close(POSTSCRIPT);
|
|
|
|
close $remote;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-09-26 23:07:45 +00:00
|
|
|
############################################################
|
|
|
|
#
|
|
|
|
# updateflag
|
|
|
|
# Tells xCAT on the server that the post scripts is done.
|
|
|
|
#
|
|
|
|
############################################################
|
|
|
|
sub updateflag {
|
2008-09-29 16:33:21 +00:00
|
|
|
my $nodesetstat=shift;
|
2008-10-15 21:01:38 +00:00
|
|
|
my $state="booted";
|
2008-09-29 16:33:21 +00:00
|
|
|
if ($nodesetstat eq "standalone") { $state="installed booting"; }
|
|
|
|
|
|
|
|
|
2008-09-26 23:07:45 +00:00
|
|
|
my $port = "3002";
|
|
|
|
my $remote = IO::Socket::INET->new( Proto => "tcp", PeerAddr => $servnode, PeerPort => $port, );
|
|
|
|
unless ($remote) {
|
|
|
|
print "$::sdate xcataixpost: Cannot connect to host \'$servnode\'\n";
|
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: Cannot connect to host \'$servnode\'\n";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
$remote->autoflush(1);
|
|
|
|
|
|
|
|
my $line;
|
|
|
|
while (defined ($line = <$remote>)) {
|
|
|
|
chomp $line;
|
|
|
|
if ($line eq "ready") {
|
2008-09-29 16:33:21 +00:00
|
|
|
print $remote "installstatus $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
|
|
|
|
#
|
|
|
|
#####################################################
|
|
|
|
sub runcmd
|
|
|
|
{
|
|
|
|
my ($cmd) = @_;
|
|
|
|
my $rc=0;
|
|
|
|
$cmd .= ' 2>&1' ;
|
|
|
|
$::outref = [];
|
|
|
|
$::outref = `$cmd`;
|
|
|
|
if ($?)
|
|
|
|
{
|
|
|
|
$rc = $? >> 8;
|
|
|
|
if ($rc > 0)
|
|
|
|
{
|
|
|
|
print "$::sdate xcataixpost: $::outref\n";
|
|
|
|
print $::LOG_FILE "$::sdate xcataixpost: $::outref\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $rc;
|
|
|
|
}
|