2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-05-30 01:26:38 +00:00
chenglch 2da3f5140d Move sleep retry from xcat to goconserver
If cons script is waiting, goconserver could not aware of
the status of the console connection. This patch check
the environment when running the script, if it is gocons
and retrying is needed, exit immediately.
2018-02-09 12:11:48 +08:00

69 lines
1.7 KiB
Perl
Executable File

#!/usr/bin/env perl
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
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);
}
BEGIN
{
use Time::HiRes qw(sleep);
use File::Path;
use Fcntl qw(:DEFAULT :flock);
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
}
my $sleepint;
use lib "$::XCATROOT/lib/perl";
require xCAT::Client;
require xCAT::Utils;
require File::Basename;
umask 0077;
mkpath("/tmp/xcat/");
unless (sysopen(LOCKHANDLE, "/tmp/xcat/consolelock", O_WRONLY | O_CREAT)) {
xCAT::Utils::console_sleep(15, "Unable to open lock file");
exit 0;
}
get_lock();
my $cmdref = {
command => "getxencons",
arg => "text",
noderange => $ARGV[0]
};
use Data::Dumper;
my $dsthost;
my $dstty;
my $speed;
sub getans {
my $rsp = shift;
if ($rsp->{node}) {
$dsthost = $rsp->{node}->[0]->{sshhost}->[0];
$dstty = $rsp->{node}->[0]->{psuedotty}->[0];
$speed = $rsp->{node}->[0]->{baudrate}->[0];
}
}
xCAT::Client::submit_request($cmdref, \&getans);
until ($dsthost and $speed and $dstty) {
release_lock();
$sleepint = int(rand(30)) + 60;
xCAT::Utils::console_sleep($sleepint, "Console not ready, retrying in $sleepint seconds (Ctrl-C to skip delay)\n");
}
release_lock();
exec "ssh -t $dsthost screen -U -a -O -e ^]a -d -R -S serial-" . $ARGV[0] . "-cons -A $dstty $speed";