-Move stateless diskless to new postscript strategy, leave AIX alone for now

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@1244 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
jbjohnso 2008-05-01 20:52:16 +00:00
parent 5d4aa10f7a
commit e173ea9f3d
3 changed files with 229 additions and 164 deletions

View File

@ -144,6 +144,7 @@ sub copybootscript {
my $profile = shift;
my $callback = shift;
if ( -f "$installroot/postscripts/xcatdsklspost") {
# copy the xCAT diskless post script to the image
@ -160,6 +161,10 @@ sub copybootscript {
xCAT::MsgUtils->message("E", $rsp, $callback);
return 1;
}
if ( -f "$installroot/postscripts/xcatdsklspost.aix") {
copy ("$installroot/postscripts/xcatdsklspost.aix", "$installroot/netboot/$osver/$arch/$profile/rootimg/opt/xcat/xcatdsklspost.aix");
chmod(0755,"$installroot/netboot/$osver/$arch/$profile/rootimg/opt/xcat/xcatdsklspost.aix");
}
if ( -f "$installroot/postscripts/xcatpostinit") {

View File

@ -1,4 +1,4 @@
#!/usr/bin/env perl
#!/bin/sh
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
#####################################################
#
@ -6,168 +6,41 @@
#
#####################################################
use File::Path;
if [ ! `uname` == Linux ]; then
MYDIR=`dirname $0`
exec $MYDIR/xcatdsklspost.aix
exit
fi
# since we don't have syslog set up yet we'll
# just save msgs in a local log file
$logdir = "/var/log/xcat";
SIP=`grep dhcp-server-identifier /var/lib/dhclient/dhclient-eth0.leases|tail -n 1|awk '{print $3}'|sed -e 's/;//'`
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;
# get hostname
$::shorthost = `hostname -s`;
chomp $::shorthost;
# get platform
my $osname = `uname`;
chomp $osname;
# get the postscript tar file from the server and unwrap it
if ($osname eq "Linux") {
if (&getLinuxpostfile() != 0 ) {
close($::LOG_FILE_HANDLE);
exit 1;
}
} else {
if (&getAIXpostfile() != 0 ) {
close($::LOG_FILE_HANDLE);
exit 1;
}
}
# check & run the postscript
my $scriptname = "/xcatpost/".$::shorthost;
if (-f $scriptname)
{
my $rc = system("$scriptname");
if ($rc >> 8)
{
print $::LOG_FILE "$::sdate xcatdsklspost: Could not run $scriptname.\n";
}
} else {
print $::LOG_FILE "$::sdate xcatdsklspost: Could not find post script for $::shorthost.\n";
}
close($::LOG_FILE_HANDLE);
exit 0;
#####################################################
#
# getLinuxpostfile
# Get the linux post scripts from the server
#
#####################################################
sub getLinuxpostfile {
# look in the dhcp leases file for the name of the server
my $dhclientfile="/var/lib/dhclient/dhclient-eth0.leases";
my @lines;
if (open(DHCLIENT, "<$dhclientfile")) {
@lines = <DHCLIENT>;
close(DHCLIENT);
} else {
print $::LOG_FILE "$::sdate xcatdsklspost: Could not open $dhclientfile.\n";
return 1;
}
my $ip; # IP of server
foreach my $l (@lines)
{
if ($l =~ /dhcp-server-identifier/) {
my ($junk, $junk2, $s) = split(" ", $l);
($ip, $junk) = split("\;", $s);
}
}
# get postscripts tar file from the server
my $getcmd = "mkdir -p /xcatpost; cd /xcatpost; wget --wait=10 --random-wait --waitretry=10 --retry-connrefused -t 0 -T 60 http://$ip/install/autoinst/xcatpost.tar.gz; gunzip xcatpost.tar.gz; tar -xvf xcatpost.tar";
if (&runcmd($getcmd) != 0)
{
print $::LOG_FILE "$::sdate xcatdsklspost: Could not get xcatpost.tar.gz.\n";
return 1;
}
return 0;
}
#####################################################
#
# getAIXpostfile
# Get the AIX post scripts from the server
#
#####################################################
sub getAIXpostfile {
# get the name of my service node/NIM master from the /etc/niminfo file
if (-f "/etc/niminfo") {
my $cmd = "cat /etc/niminfo | grep 'NIM_NAME'";
&runcmd($cmd);
my $hnline = $::outref;
my $junk;
($junk, $::shorthost) = split(/=/, $hnline);
$::shorthost =~ s/^\s*//; # delete leading white space
chomp $::shorthost;
$cmd = "cat /etc/niminfo | grep 'NIM_MASTER_HOSTNAME'";
&runcmd($cmd);
my $SNline = $::outref;
($junk, $sn) = split(/=/, $SNline);
$sn =~ s/^\s*//; # delete leading white space
chomp $sn;
} else {
print $::LOG_FILE "$::sdate xcatdsklspost: Could not find /etc/niminfo file.\n";
return 1;
}
# use tftp to get the tar file
my $getcmd="mkdir -p /xcatpost; cd /xcatpost; tftp -o xcatpost.tar.gz $sn /install/autoinst/xcatpost.tar.gz";
if (&runcmd($getcmd) != 0)
{
print $::LOG_FILE "$::sdate xcatdsklspost: Could not get xcatpost.tar.gz.\n";
return 1;
}
# unwrap the tar file
my $uncmd = "cd /xcatpost; gunzip xcatpost.tar.gz; tar -xvf xcatpost.tar";
if (&runcmd($uncmd) != 0)
{
print $::LOG_FILE "$::sdate xcatdsklspost: Could not extract from /xcatpost/xcatpost.tar.gz.\n";
return 1;
}
return 0;
}
#
# run the command
#
sub runcmd
{
my ($cmd) = @_;
my $rc=0;
$cmd .= ' 2>&1' ;
$::outref = [];
$::outref = `$cmd`;
if ($?)
{
$rc = $? >> 8;
if ($rc > 0)
{
print $::LOG_FILE "$::sdate xcatdsklspost: $::outref\n";
}
}
return $rc;
}
mkdir -p /etc/stunnel
cat > /etc/stunnel/stunnel.conf << EOF
client=yes
foreground=no
output=/dev/null
verify=0
[xcatd]
accept=400
EOF
echo "connect=$SIP:3001" >> /etc/stunnel/stunnel.conf
stunnel;
sleep 1;
mkdir -p /xcatpost;
mkdir /tmp/postage
cd /tmp/postage
wget -l inf -N -r --waitretry=10 --random-wait --retry-connrefused -t 0 -T 60 ftp://$SIP/install/postscripts 2> /tmp/wget.log
mv $SIP/install/postscripts/* /xcatpost;
rm -rf $SIP
cd /xcatpost;
PATH=/xcatpost:$PATH
export PATH
chmod +x /xcatpost/*;
/xcatpost/getpostscript.awk | sed -e 's/<[^>]*>//g'|egrep -v '^ *$'|sed -e 's/^ *//' > /tmp/mypostscript;
chmod +x /tmp/mypostscript
if [ -x /tmp/mypostscript ];then
/tmp/mypostscript
fi
rm -f /tmp/mypostscript
killall stunnel
rm -rf /etc/stunnel

View File

@ -0,0 +1,187 @@
#!/usr/bin/env perl
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
#####################################################
#
# Generic xCAT post script for diskless nodes
#
#####################################################
use File::Path;
# 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;
# get hostname
$::shorthost = `hostname -s`;
chomp $::shorthost;
# get platform
my $osname = `uname`;
chomp $osname;
# get the postscript tar file from the server and unwrap it
if ($osname eq "Linux") {
if (&getLinuxpostfile() != 0 ) {
close($::LOG_FILE_HANDLE);
exit 1;
}
} else {
if (&getAIXpostfile() != 0 ) {
close($::LOG_FILE_HANDLE);
exit 1;
}
}
# check & run the postscript
my $scriptname = "/xcatpost/".$shorthost;
if ($osname eq "Linux") {
$scriptname = "/tmp/mypostscript";
}
if (-f $scriptname)
{
my $rc = system("$scriptname");
if ($rc >> 8)
{
print $::LOG_FILE "$::sdate xcatdsklspost: Could not run $scriptname.\n";
}
} else {
print $::LOG_FILE "$::sdate xcatdsklspost: Could not find post script for $::shorthost.\n";
}
close($::LOG_FILE_HANDLE);
exit 0;
#####################################################
#
# getLinuxpostfile
# Get the linux post scripts from the server
#
#####################################################
sub getLinuxpostfile {
# look in the dhcp leases file for the name of the server
my $dhclientfile="/var/lib/dhclient/dhclient-eth0.leases";
my @lines;
if (open(DHCLIENT, "<$dhclientfile")) {
@lines = <DHCLIENT>;
close(DHCLIENT);
} else {
print $::LOG_FILE "$::sdate xcatdsklspost: Could not open $dhclientfile.\n";
return 1;
}
my $ip; # IP of server
foreach my $l (@lines)
{
if ($l =~ /dhcp-server-identifier/) {
my ($junk, $junk2, $s) = split(" ", $l);
($ip, $junk) = split("\;", $s);
}
}
# get postscripts tar file from the server
my $stunconf;
mkpath "/etc/stunnel";
open($stunconf,">","/etc/stunnel/stunnel.conf");
print $stunconf "client=yes\n";
print $stunconf "foreground=no\n";
print $stunconf "output=/dev/null\n";
print $stunconf "verify=0\n";
print $stunconf "[xcatd]\n";
print $stunconf "accept=400\n";
print $stunconf "connect=$ip:3001\n";
close($stunconf);
my $getcmd = "stunnel; sleep 1; mkdir -p /xcatpost; cd /xcatpost; wget -l inf -N -r --waitretry=10 --random-wait --retry-connrefused -t 0 -T 60 ftp://$ip/install/postscripts; mv $ip/install/postscripts/* .; chmod +x /xcatpost/*; /xcatpost/getpostscript.awk | sed -e 's/<[^>]*>//g'|egrep -v '^ *$'|sed -e 's/^ *//' > /tmp/mypostscript; chmod +x /tmp/mypostscript";
if (&runcmd($getcmd) != 0)
{
print $::LOG_FILE "$::sdate xcatdsklspost: Could not get xcatpost.tar.gz.\n";
return 1;
}
return 0;
}
#####################################################
#
# getAIXpostfile
# Get the AIX post scripts from the server
#
#####################################################
sub getAIXpostfile {
# get the name of my service node/NIM master from the /etc/niminfo file
if (-f "/etc/niminfo") {
my $cmd = "cat /etc/niminfo | grep 'NIM_NAME'";
&runcmd($cmd);
my $hnline = $::outref;
my $junk;
($junk, $::shorthost) = split(/=/, $hnline);
$::shorthost =~ s/^\s*//; # delete leading white space
chomp $::shorthost;
$cmd = "cat /etc/niminfo | grep 'NIM_MASTER_HOSTNAME'";
&runcmd($cmd);
my $SNline = $::outref;
($junk, $sn) = split(/=/, $SNline);
$sn =~ s/^\s*//; # delete leading white space
chomp $sn;
} else {
print $::LOG_FILE "$::sdate xcatdsklspost: Could not find /etc/niminfo file.\n";
return 1;
}
# use tftp to get the tar file
my $getcmd="mkdir -p /xcatpost; cd /xcatpost; tftp -o xcatpost.tar.gz $sn /install/autoinst/xcatpost.tar.gz";
if (&runcmd($getcmd) != 0)
{
print $::LOG_FILE "$::sdate xcatdsklspost: Could not get xcatpost.tar.gz.\n";
return 1;
}
# unwrap the tar file
my $uncmd = "cd /xcatpost; gunzip xcatpost.tar.gz; tar -xvf xcatpost.tar";
if (&runcmd($uncmd) != 0)
{
print $::LOG_FILE "$::sdate xcatdsklspost: Could not extract from /xcatpost/xcatpost.tar.gz.\n";
return 1;
}
return 0;
}
#
# run the command
#
sub runcmd
{
my ($cmd) = @_;
my $rc=0;
$cmd .= ' 2>&1' ;
$::outref = [];
$::outref = `$cmd`;
if ($?)
{
$rc = $? >> 8;
if ($rc > 0)
{
print $::LOG_FILE "$::sdate xcatdsklspost: $::outref\n";
}
}
return $rc;
}