2007-10-26 22:44:33 +00:00
#!/usr/bin/env perl
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
2009-01-30 14:27:32 +00:00
use Fcntl qw(:DEFAULT :flock);
sub get_lock {
unless (flock(LOCKHANDLE,LOCK_EX|LOCK_NB)) {
$| = 1;
print "Acquiring startup lock...";
flock(LOCKHANDLE,LOCK_EX) or die "Fatal Error securing startup lock";
print "done\n";
}
truncate(LOCKHANDLE,0);
print LOCKHANDLE $$."\n";
}
sub release_lock {
truncate(LOCKHANDLE,0);
flock(LOCKHANDLE,LOCK_UN);
}
2008-01-03 15:55:47 +00:00
BEGIN
{
2008-05-13 14:03:46 +00:00
use Time::HiRes qw(sleep);
2009-01-30 14:27:32 +00:00
use File::Path;
use Fcntl qw(:DEFAULT :flock);
2008-01-03 15:55:47 +00:00
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
2009-01-30 14:27:32 +00:00
umask 0077;
mkpath("/tmp/xcat/");
unless (sysopen(LOCKHANDLE,"/tmp/xcat/consolelock",O_WRONLY | O_CREAT)) {
print "Unable to open lock file";
2012-04-16 00:42:36 +00:00
exec("sleep 15");
2009-01-30 14:27:32 +00:00
exit 0;
}
get_lock();
#my $sleepint=int(rand(10));
#print "Opening console in ".(2+(0.5*$sleepint))." seconds...\n";
#sleep $sleepint;
2008-01-03 15:55:47 +00:00
}
2009-01-30 14:27:32 +00:00
my $sleepint=int(rand(10)); #Stagger start to avoid overwhelming conserver/xCATd
2008-01-03 15:55:47 +00:00
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
use lib "$::XCATROOT/lib/perl";
2008-08-16 13:41:14 +00:00
require xCAT::Client;
2007-10-26 22:44:33 +00:00
my $username = 'USERID';
my $password = 'PASSW0RD';
my $node = $ARGV[0];
2008-08-16 13:41:14 +00:00
my $bmc;
sub getans {
my $rsp = shift;
if ($rsp->{node}) {
$bmc = $rsp->{node}->[0]->{bmcaddr}->[0];
$username = $rsp->{node}->[0]->{bmcuser}->[0];
$password = $rsp->{node}->[0]->{bmcpass}->[0];
2013-01-06 08:38:34 +00:00
if (exists $rsp->{node}->[0]->{error}) {
my $error = $rsp->{node}->[0]->{error}->[0];
print $error."\n";
}
2008-08-16 13:41:14 +00:00
}
2007-10-26 22:44:33 +00:00
}
2008-08-16 13:41:14 +00:00
my $cmdref={
2013-06-14 12:53:14 +00:00
command=>["getipmicons"],
arg=>["text"],
noderange=>[$ARGV[0]]
2008-08-16 13:41:14 +00:00
};
xCAT::Client::submit_request($cmdref,\&getans);
until ($username and $password and $bmc) {
2009-01-30 14:27:32 +00:00
release_lock(); #Let other clients have a go
2012-04-16 00:42:36 +00:00
$sleepint=10+int(rand(20));
2009-01-30 14:27:32 +00:00
print "Console not ready, retrying in $sleepint seconds (Ctrl-e,c,o to skip delay) \n";
2012-04-16 00:42:36 +00:00
exec("sleep $sleepint");
2009-01-30 14:27:32 +00:00
get_lock();
2008-08-16 13:41:14 +00:00
xCAT::Client::submit_request($cmdref,\&getans);
2007-10-26 22:44:33 +00:00
}
2009-01-30 14:27:32 +00:00
release_lock();
2008-08-16 13:41:14 +00:00
#require xCAT::Table;
#require xCAT::Utils;
#my $dba;
#my $ipmitab = xCAT::Table->new('ipmi');
#unless ($ipmitab) { die "Unable to open IPMI table"; }
#my $passtab = xCAT::Table->new('passwd');
#if ($passtab) {
# ($dba) = $passtab->getAttribs({key=>'ipmi'},qw(username password));
# if ($dba) {
# if ($dba->{username}) { $username = $dba->{username}; }
# if ($dba->{password}) { $password = $dba->{password}; }
# }
#}
#$dba = $ipmitab->getNodeAttribs($ARGV[0],[qw(bmc username password)]);
#if ($dba) {
# if ($dba->{bmc}) { $bmc = $dba->{bmc}; }
# if ($dba->{username}) { $username = $dba->{username}; }
# if ($dba->{password}) { $password = $dba->{password}; }
#}
#xCAT::Utils::close_all_dbhs;
2008-03-19 20:58:29 +00:00
#my $isintel = system "ipmitool -I lanplus -U $username -P $password -H $bmc chassis status > /dev/null 2>&1";
2008-10-05 19:47:04 +00:00
my $isintel=0;
2009-01-30 14:27:32 +00:00
my $sleepint;
my $rc;
2010-05-12 19:29:37 +00:00
my $ipmitool = "ipmitool";
if (-x "$XCATROOT/bin/ipmitool-xcat") {
$ipmitool = "$XCATROOT/bin/ipmitool-xcat";
}
my @mcinfo=`$ipmitool -I lan -U $username -P $password -H $bmc mc info`;#| grep 'Manufacturer ID : 343' > /dev/null 2>&1";
2009-01-30 14:27:32 +00:00
$rc = $?;
2010-06-04 20:21:24 +00:00
if ($rc) { #some shoddy vendors ignore the IPMI 2.0 requirement to support IPMI 1.5 formats for BMC capability determination, attempt IPMI 2.0 even without the ability to confirm IPMI 2.0 support. Though SOL was not baked in prior IPMI 2.0, this script supports pre-2.0 'ISOL' on older devices, hence why we are checking for 1.5/2.0 before proceeding normally
@mcinfo=`$ipmitool -I lanplus -U $username -P $password -H $bmc mc info`;
$rc = $?;
}
2009-01-30 14:27:32 +00:00
while ($rc != 0) {
$sleepint = 10+int(rand(20));
print "Failure to reach IPMI device, retrying in $sleepint seconds (Hit Ctrl-E,c,o to skip)\n";
2012-04-16 00:42:36 +00:00
exec("sleep $sleepint");
#sleep $sleepint;
2010-05-12 19:29:37 +00:00
@mcinfo=`$ipmitool -I lan -U $username -P $password -H $bmc mc info`;#| grep 'Manufacturer ID : 343' > /dev/null 2>&1";
2009-01-30 14:27:32 +00:00
$rc = $?;
2010-06-04 20:21:24 +00:00
if ($rc) { #repeat workaround for shoddy vendors
@mcinfo=`$ipmitool -I lanplus -U $username -P $password -H $bmc mc info`;
$rc = $?;
}
2009-01-30 14:27:32 +00:00
}
2008-10-05 19:47:04 +00:00
my $solcom="sol";
my $iface="lanplus";
if (grep /IPMI Version : 1.5/,@mcinfo) {
$solcom="isol";
$iface="lan";
} elsif (grep /Manufacturer ID : 343/,@mcinfo) {
$isintel=1;
}
2008-03-17 16:02:49 +00:00
my $inteloption="";
if ($isintel) {
$inteloption=" -o intelplus";
}
2008-10-05 19:47:04 +00:00
if ($iface eq "lanplus") {
2010-05-12 19:29:37 +00:00
system "$ipmitool -I lanplus $inteloption -U $username -P $password -H $bmc $solcom deactivate"; #Stop any active session
2008-10-05 19:47:04 +00:00
}
2009-01-30 14:27:32 +00:00
2010-05-12 19:29:37 +00:00
exec "$ipmitool -I $iface $inteloption -U $username -P $password -H $bmc $solcom activate";
2007-10-26 22:44:33 +00:00