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 "Error trying to secure a startup lock";
|
|
|
|
print "done\n";
|
|
|
|
}
|
|
|
|
truncate(LOCKHANDLE,0);
|
|
|
|
print LOCKHANDLE $$."\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
sub release_lock {
|
|
|
|
truncate(LOCKHANDLE,0);
|
|
|
|
flock(LOCKHANDLE,LOCK_UN);
|
|
|
|
}
|
|
|
|
|
2007-12-18 18:24:16 +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);
|
2007-12-18 18:24:16 +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)) {
|
|
|
|
sleep 15;
|
|
|
|
print "Unable to open lock file";
|
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
get_lock();
|
|
|
|
#my $sleepint=int(rand(10)); #Stagger start to avoid overwhelming conserver/xCATd
|
|
|
|
#print "Opening console in ".(2+(0.5*$sleepint))." seconds...\n";
|
|
|
|
#sleep $sleepint;
|
2007-12-18 18:24:16 +00:00
|
|
|
}
|
2009-01-30 14:27:32 +00:00
|
|
|
my $sleepint=int(rand(10)); #Stagger start to avoid overwhelming conserver/xCATd
|
2007-12-18 18:24:16 +00:00
|
|
|
use lib "$::XCATROOT/lib/perl";
|
2009-03-26 14:30:37 +00:00
|
|
|
$ENV{HOME}='/root/';
|
2008-08-16 14:44:41 +00:00
|
|
|
require xCAT::Client;
|
2007-12-18 18:24:16 +00:00
|
|
|
|
2008-08-16 14:44:41 +00:00
|
|
|
#require xCAT::Table;
|
|
|
|
#require xCAT::Utils;
|
2008-05-13 14:03:46 +00:00
|
|
|
require File::Basename;
|
|
|
|
import File::Basename;
|
2007-10-26 22:44:33 +00:00
|
|
|
my $scriptname = $0;
|
|
|
|
|
2008-08-16 14:44:41 +00:00
|
|
|
#$mptab = xCAT::Table->new('mp');
|
|
|
|
#unless ($mptab) {
|
2008-05-13 14:03:46 +00:00
|
|
|
#sleep 5; #Try not to overwhelm logfiles...
|
2008-08-16 14:44:41 +00:00
|
|
|
# die "mp table must be configured";
|
|
|
|
#}
|
|
|
|
#$mpatab = xCAT::Table->new('mpa');
|
|
|
|
#$passtab = xCAT::Table->new('passwd');
|
2007-10-26 22:44:33 +00:00
|
|
|
|
|
|
|
my $username = "USERID";
|
|
|
|
my $passsword = "PASSW0RD";
|
|
|
|
my $mm;
|
|
|
|
my $slot;
|
2008-08-16 14:44:41 +00:00
|
|
|
#my $dba;
|
|
|
|
#if ($passtab) {
|
|
|
|
# ($dba) = $passtab->getAttribs({key=>blade},qw(username password));
|
|
|
|
# if ($dba->{username}) {
|
|
|
|
# $username = $dba->{username};
|
|
|
|
# }
|
|
|
|
# if ($dba->{password}) {
|
|
|
|
# $password = $dba->{password};
|
|
|
|
# }
|
|
|
|
#}
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2008-08-16 14:44:41 +00:00
|
|
|
#$dba = $mptab->getNodeAttribs($ARGV[0],[qw(mpa id)]);
|
|
|
|
#$mm = $dba->{mpa};
|
|
|
|
#$slot = $dba->{id};
|
|
|
|
#if ($mpatab) {
|
|
|
|
# ($dba) = $mpatab->getAttribs({mpa=>$mm},qw(username password));
|
|
|
|
# if ($dba) {
|
|
|
|
# if ($dba->{username}) { $username = $dba->{username}; }
|
|
|
|
# if ($dba->{password}) { $password = $dba->{password}; }
|
|
|
|
# }
|
|
|
|
#}
|
|
|
|
#xCAT::Utils::close_all_dbhs;
|
2008-05-13 14:03:46 +00:00
|
|
|
#sleep 5; #Slow start, I know, but with exec, can't return
|
2008-08-16 14:44:41 +00:00
|
|
|
sub getans {
|
|
|
|
my $rsp = shift;
|
|
|
|
if ($rsp->{node}) {
|
|
|
|
$mm = $rsp->{node}->[0]->{mm}->[0];
|
|
|
|
$username = $rsp->{node}->[0]->{username}->[0];
|
|
|
|
$slot = $rsp->{node}->[0]->{slot}->[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
my $cmdref={
|
2009-03-26 09:22:29 +00:00
|
|
|
command=>["getbladecons"],
|
|
|
|
arg=>["text"],
|
|
|
|
noderange=>[$ARGV[0]]
|
2008-08-16 14:44:41 +00:00
|
|
|
};
|
|
|
|
xCAT::Client::submit_request($cmdref,\&getans);
|
|
|
|
until ($mm and $username and $slot) {
|
2009-01-30 14:27:32 +00:00
|
|
|
release_lock(); #Let other clients have a go
|
|
|
|
$sleepint=10+int(rand(20)); #Stagger to minimize lock collisions, but no big deal when it does happen
|
|
|
|
print "Console not ready, retrying in $sleepint seconds (Hit Ctrl-E,c,o to skip delay)\n";
|
|
|
|
sleep $sleepint;
|
|
|
|
get_lock();
|
2008-08-16 14:44:41 +00:00
|
|
|
xCAT::Client::submit_request($cmdref,\&getans);
|
|
|
|
}
|
2009-01-30 14:27:32 +00:00
|
|
|
release_lock(); #done with xcatd, can run with near impunity
|
|
|
|
my $solchkcmd = "ssh -t $username"."@"."$mm sol -T blade[$slot]";
|
|
|
|
my $solstatus = `$solchkcmd`;
|
|
|
|
while ($solstatus !~ /SOL Session: Ready/ and $solstatus !~ /SOL Session: Active/) {
|
|
|
|
$sleepint=60+int(rand(30)); #Stagger sleep to take it easy on AMM/hosting server
|
|
|
|
print "SOL unavailable, retrying in $sleepint seconds (hit Ctrl-E,c,o to skip)\n";
|
|
|
|
sleep $sleepint;
|
|
|
|
$solstatus = `$solchkcmd`;
|
|
|
|
}
|
2007-11-26 15:43:17 +00:00
|
|
|
exec "ssh -t $username"."@"."$mm console -o -T blade[$slot]";
|
|
|
|
#my $pathtochild= dirname($scriptname). "/";
|
|
|
|
#exec $pathtochild."blade.expect $mm $slot $username $password";
|
2007-10-26 22:44:33 +00:00
|
|
|
|
2008-08-16 14:44:41 +00:00
|
|
|
#SECURITY: In this case, the authentication is expected to be done using the script user's ssh keys. As such,
|
|
|
|
#this script does not receive any particularly sensitive data from the xCAT server.
|
2007-10-26 22:44:33 +00:00
|
|
|
|