2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-07-31 18:19:40 +00:00
Files
xcat-core/xCAT-server/bin/replaycons
T
Vinícius Ferrão 21da014ed7 fix(replaycons): detect confluent by console service, not binary presence
replaycons chose the confluent console log directory
(/var/log/confluent/consoles) whenever the confetty binary happened to be
present.  On a host that has confluent installed but runs conserver as the
active console service, that directory is empty and replaycons could not find
the log.  Gate on the site table's consoleservice attribute instead -- the
same setting rcons uses -- so replaycons reads /var/log/confluent/consoles
only when confluent is actually the configured console service.

Recovered from the unmerged lenovobuild branch (originals 3ce4d81b3, 57f6ddd38).

Co-authored-by: Jarrod Johnson <10814490+jjohnson42@users.noreply.github.com>
2026-07-22 21:09:06 -03:00

131 lines
2.9 KiB
Perl
Executable File

#!/usr/bin/perl
#!/usr/bin/env perl
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
BEGIN
{
$::XCATROOT = $ENV{'XCATROOT'} ? $ENV{'XCATROOT'} : '/opt/xcat';
}
use lib "$::XCATROOT/lib/perl";
use strict;
use xCAT::Table;
use xCAT::Utils;
use xCAT::TableUtils;
use xCAT::NetworkUtils;
use xCAT::MsgUtils;
use Getopt::Long;
my $usage_string =
"Usage:
replaycons node_log [bps] [tail]
replaycons -h|--help
replaycons -v|--version
bps Specifies the display rate.
The default is 19200.
tail Specifies the number of bytes to be displayed.
The default displays all.
-h|--help Display this usage statement.
-v|--version Display the version number.";
my $version_string = "Version 2.0";
$Getopt::Long::ignorecase = 0;
if (!GetOptions(
'h|help' => \$::HELP,
'v|version' => \$::VERSION)) {
exit(1);
}
if ($::HELP) {
print "$usage_string\n";
exit(0);
}
if ($::VERSION) {
print "$version_string\n";
exit(0);
}
if (@ARGV < 1) {
print "Please specify a node name.\n";
exit(1);
}
my $node = @ARGV[0];
my $bps = 19200;
if (@ARGV > 1) {
$bps = @ARGV[1];
if ($bps == 0) { $bps = 19200; }
}
my $tail = 0;
if (@ARGV > 2) { $tail = @ARGV[2]; }
print "node=$node, bps=$bps, tail=$tail\n";
# get the conserver for the node
my $conserver;
my $hmtab = xCAT::Table->new('nodehm');
if ($hmtab) {
my $ent = $hmtab->getNodeAttribs($node, [ 'node', 'conserver' ]);
if ($ent->{conserver}) { $conserver = $ent->{conserver}; }
} else {
print "nodehm table cannot be opened\n";
exit(1);
}
my $file = "/var/log/consoles/$node";
#use confluent only when it is the configured console service, not merely
#installed -- otherwise a host with confluent present but conserver active
#would look in the wrong (empty) log directory
my $stab = xCAT::Table->new('site');
if ($stab) {
(my $ref) = $stab->getAttribs({ key => 'consoleservice' }, 'value');
if ($ref->{value} && $ref->{value} eq 'confluent') {
$file = "/var/log/confluent/consoles/$node";
}
}
#print "file=$file\n";
#if has conserver, goto conserver the execute replaycons command
my @hostinfo = xCAT::NetworkUtils->determinehostname();
my %iphash = ();
foreach (@hostinfo) { $iphash{$_} = 1; }
if (($conserver) && ($iphash{$conserver} != 1)) {
system("ssh -o BatchMode=yes $conserver $::XCATROOT/bin/replaycons $node $bps $tail 2>&1");
exit(0);
}
my $cps = $bps / 8;
my $ms = 1 / $cps;
my $msc = 0;
my $debug = 0;
my @c;
select(STDOUT);
$| = 1;
if (!open(FILE, $file)) {
print "replaycons: cannot open $file\n";
exit(1);
}
if ($tail > 0) {
seek(FILE, -$tail, 2);
}
while (<FILE>) {
@c = split(//);
foreach (@c) {
print $_;
$msc += $ms;
if ($msc > .1) {
select(undef, undef, undef, $msc);
$msc = 0;
}
}
}
close(FILE);
exit(0);