2008-07-31 17:32:39 +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-07-31 17:32:39 +00:00
|
|
|
BEGIN
|
|
|
|
{
|
|
|
|
use Time::HiRes qw(sleep);
|
2009-01-30 14:27:32 +00:00
|
|
|
use File::Path;
|
|
|
|
use Fcntl qw(:DEFAULT :flock);
|
2008-07-31 17:32:39 +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));
|
|
|
|
#print "Opening console in ".(2+(0.5*$sleepint))." seconds...\n";
|
|
|
|
#sleep $sleepint;
|
2008-07-31 17:32:39 +00:00
|
|
|
}
|
2009-01-30 14:27:32 +00:00
|
|
|
#BEGIN
|
|
|
|
#{
|
|
|
|
# use Time::HiRes qw(sleep);
|
|
|
|
# $::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
|
|
|
|
# my $sleepint=int(rand(10));
|
|
|
|
# print "Opening console in ".(0.5*$sleepint)." seconds...\n";
|
|
|
|
# sleep (0.5*$sleepint);
|
|
|
|
#}
|
|
|
|
my $sleepint;
|
2008-07-31 17:32:39 +00:00
|
|
|
use lib "$::XCATROOT/lib/perl";
|
2008-07-31 21:06:33 +00:00
|
|
|
$ENV{HOME}='/root/';
|
2008-07-31 17:32:39 +00:00
|
|
|
require xCAT::Client;
|
|
|
|
|
|
|
|
require File::Basename;
|
|
|
|
import File::Basename;
|
|
|
|
my $scriptname = $0;
|
|
|
|
|
|
|
|
my $cmdref={
|
2008-08-12 17:15:48 +00:00
|
|
|
command=>"getxencons",
|
2008-07-31 17:32:39 +00:00
|
|
|
arg=>"text",
|
|
|
|
noderange=>$ARGV[0]
|
|
|
|
};
|
|
|
|
use Data::Dumper;
|
|
|
|
my $dsthost;
|
|
|
|
my $dstty;
|
|
|
|
my $speed;
|
|
|
|
sub getans {
|
|
|
|
my $rsp = shift;
|
|
|
|
if ($rsp->{node}) {
|
2008-08-12 17:15:48 +00:00
|
|
|
$dsthost = $rsp->{node}->[0]->{sshhost}->[0];
|
|
|
|
$dstty = $rsp->{node}->[0]->{psuedotty}->[0];
|
|
|
|
$speed = $rsp->{node}->[0]->{baudrate}->[0];
|
2008-07-31 17:32:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
xCAT::Client::submit_request($cmdref,\&getans);
|
2008-08-12 12:59:14 +00:00
|
|
|
until ($dsthost and $speed and $dstty) {
|
2009-01-30 14:27:32 +00:00
|
|
|
release_lock();
|
|
|
|
$sleepint=int(rand(30))+60;
|
|
|
|
print "Console not ready, retrying in $sleepint seconds (Ctrl-e,c,o to skip delay)\n";
|
|
|
|
sleep $sleepint;
|
|
|
|
get_lock();
|
2008-08-12 12:59:14 +00:00
|
|
|
xCAT::Client::submit_request($cmdref,\&getans);
|
|
|
|
}
|
2009-01-30 14:27:32 +00:00
|
|
|
release_lock();
|
2009-03-02 15:00:38 +00:00
|
|
|
exec "ssh -t $dsthost screen -e ^]a -d -R -S serial-".$ARGV[0]."-cons -A $dstty $speed";
|
2008-07-31 17:32:39 +00:00
|
|
|
|
|
|
|
#my $pathtochild= dirname($scriptname). "/";
|
|
|
|
#exec $pathtochild."blade.expect $mm $slot $username $password";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|