2009-12-03 08:01:33 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# IBM(c) 2007 EPL license http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
#(C)IBM Corp
|
|
|
|
|
|
|
|
#
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
{
|
|
|
|
$::XCATROOT =
|
|
|
|
$ENV{'XCATROOT'} ? $ENV{'XCATROOT'}
|
|
|
|
: -d '/opt/xcat' ? '/opt/xcat'
|
|
|
|
: '/usr';
|
|
|
|
}
|
|
|
|
use lib "$::XCATROOT/lib/perl";
|
|
|
|
use Getopt::Long;
|
|
|
|
use File::Basename;
|
|
|
|
use xCAT::MsgUtils;
|
|
|
|
use xCAT::Utils;
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
=head1 startstopxcatd
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
restartxcatd - this routine is used to restart the xcatd processes by
|
|
|
|
startsrc and stopsrc commands.
|
|
|
|
It runs on AIX.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
# Main
|
2010-01-06 09:38:35 +00:00
|
|
|
|
|
|
|
my $rc;
|
|
|
|
my @output;
|
|
|
|
my $inoperative = 0;
|
|
|
|
my $check_num;
|
2009-12-03 08:01:33 +00:00
|
|
|
my $cmd = basename($0);
|
|
|
|
if (!(xCAT::Utils->isAIX()))
|
|
|
|
{ # only runs on AIX
|
2010-01-06 09:38:35 +00:00
|
|
|
xCAT::MsgUtils->message("E", "Error: This command should only be run on AIX.\n");
|
2009-12-03 08:01:33 +00:00
|
|
|
exit 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
&parse_args($cmd);
|
|
|
|
|
|
|
|
# Check whether the xcatd subsystem has been created
|
|
|
|
$cmd = "/usr/bin/lssrc -s xcatd | grep \"xcatd Subsystem is not on file\"";
|
|
|
|
@output = `$cmd`;
|
2009-12-04 04:32:19 +00:00
|
|
|
if (scalar(@output)) {
|
|
|
|
# create the subsystem if it does not exist
|
|
|
|
$cmd = "mkssys -p $::XCATROOT/sbin/xcatd -s xcatd -u 0 -S -n 15 -f 15 -a \"-f\"";
|
|
|
|
$rc = system($cmd);
|
|
|
|
if ($rc >> 8) {
|
2010-01-06 09:38:35 +00:00
|
|
|
xCAT::MsgUtils->message("E", "Error: Cannot create the xcatd subsystem.\n");
|
2009-12-04 04:32:19 +00:00
|
|
|
exit 1;
|
|
|
|
}
|
2009-12-03 08:01:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Check the current status of xcatd subsystem
|
|
|
|
$cmd = "lssrc -s xcatd | grep 'xcatd' | grep 'inoperative'";
|
|
|
|
@output = `$cmd`;
|
|
|
|
if (scalar(@output)) {
|
2009-12-04 04:32:19 +00:00
|
|
|
if ($::VERBOSE) {
|
|
|
|
xCAT::MsgUtils->message("I", "xcatd subsystem in inoperative status.\n");
|
|
|
|
}
|
2009-12-03 08:01:33 +00:00
|
|
|
$inoperative = 1;
|
|
|
|
}
|
|
|
|
|
2010-01-06 09:38:35 +00:00
|
|
|
if (! $inoperative) { # active
|
2009-12-03 08:01:33 +00:00
|
|
|
# Stop the xcatd subsystem
|
|
|
|
$cmd = "/usr/bin/stopsrc -s xcatd";
|
|
|
|
$rc = system($cmd);
|
|
|
|
if ($rc >> 8) {
|
2010-01-06 09:38:35 +00:00
|
|
|
xCAT::MsgUtils->message("E", "Error: Cannot run stopsrc command correctly.\n");
|
2009-12-03 08:01:33 +00:00
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Wait for end of the xcatd subsystem
|
2010-01-06 09:38:35 +00:00
|
|
|
$check_num = 3;
|
2009-12-03 08:01:33 +00:00
|
|
|
while ($check_num > 0) {
|
|
|
|
$check_num--;
|
|
|
|
$cmd = "lssrc -s xcatd | grep 'xcatd' | grep 'inoperative'";
|
|
|
|
@output = `$cmd`;
|
|
|
|
if (scalar(@output) == 0) {
|
|
|
|
sleep 1;
|
|
|
|
} else {
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($check_num <= 0) {
|
2010-01-06 09:38:35 +00:00
|
|
|
xCAT::MsgUtils->message("E", "Error: Cannot stop the xcatd subsystem correctly.\n");
|
2009-12-03 08:01:33 +00:00
|
|
|
exit 1;
|
|
|
|
} else {
|
2009-12-04 04:32:19 +00:00
|
|
|
if ($::VERBOSE) {
|
|
|
|
xCAT::MsgUtils->message("I", "Stopped the xcatd subsystem.\n");
|
|
|
|
}
|
2009-12-03 08:01:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-06 09:38:35 +00:00
|
|
|
# Kill xcatd manually if needed
|
|
|
|
$cmd = "ps -ef | grep xcatd: | grep -v grep";
|
|
|
|
@output = `$cmd`;
|
|
|
|
if (scalar(@output)) {
|
|
|
|
$cmd = "ps -ef | grep xcatd | grep 'SSL listener'";
|
|
|
|
@output = `$cmd`;
|
|
|
|
foreach my $ps (@output) {
|
|
|
|
$ps =~ s/^\s+//; # strip any leading spaces
|
|
|
|
my ($uid, $pid, $ppid, $desc) = split /\s+/, $ps;
|
|
|
|
my $cmd = "/usr/bin/kill -15 -$pid >/dev/null 2>&1";
|
|
|
|
`$cmd`;
|
|
|
|
}
|
|
|
|
# Kill the xcatd by force if it still there
|
|
|
|
$cmd = "ps -ef | grep xcatd: | grep -v grep";
|
|
|
|
@output = `$cmd`;
|
|
|
|
foreach my $ps (@output) {
|
|
|
|
$ps =~ s/^\s+//; # strip any leading spaces
|
|
|
|
my ($uid, $pid, $ppid, $desc) = split /\s+/, $ps;
|
|
|
|
my $cmd = "/usr/bin/kill -9 $pid >/dev/null 2>&1";
|
|
|
|
`$cmd`;
|
|
|
|
}
|
|
|
|
$check_num = 3;
|
|
|
|
while ($check_num > 0) {
|
|
|
|
$check_num--;
|
|
|
|
$cmd = "ps -ef | grep xcatd: | grep -v grep";
|
|
|
|
@output = `$cmd`;
|
|
|
|
if (scalar(@output)) {
|
|
|
|
sleep 1;
|
|
|
|
} else {
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($check_num <= 0) {
|
|
|
|
xCAT::MsgUtils->message("E", "Error: Cannot kill the xcatd processes correctly.\n");
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-03 08:01:33 +00:00
|
|
|
# Start the xcatd subsystem
|
|
|
|
$cmd = "/usr/bin/startsrc -s xcatd";
|
|
|
|
|
|
|
|
if ($ENV{XCATRELOAD} || $ENV{XCATROOT} || $ENV{PATH}) {
|
|
|
|
$cmd .= " -e \"";
|
|
|
|
if ($ENV{XCATRELOAD}) {
|
|
|
|
$cmd .= " XCATRELOAD=$ENV{XCATRELOAD}";
|
|
|
|
}
|
|
|
|
if ($ENV{XCATROOT}) {
|
|
|
|
$cmd .= " XCATROOT=$ENV{XCATROOT}";
|
|
|
|
}
|
|
|
|
if ($ENV{PATH}) {
|
|
|
|
$cmd .= " PATH=$ENV{PATH}";
|
|
|
|
}
|
|
|
|
$cmd .= "\"";
|
|
|
|
}
|
|
|
|
$rc = system($cmd);
|
|
|
|
if ($rc >> 8) {
|
2010-01-06 09:38:35 +00:00
|
|
|
xCAT::MsgUtils->message("E", "Error: Cannot run startsrc command correctly.\n");
|
2009-12-03 08:01:33 +00:00
|
|
|
exit 1;
|
|
|
|
}
|
2010-01-06 09:38:35 +00:00
|
|
|
# Sleep a while to make sure the startsrc has completed it's work
|
|
|
|
sleep 3;
|
2009-12-03 08:01:33 +00:00
|
|
|
|
|
|
|
# Check the status of xcatd subsystem
|
2010-01-06 09:38:35 +00:00
|
|
|
$check_num = 3;
|
2009-12-03 08:01:33 +00:00
|
|
|
while ($check_num > 0) {
|
|
|
|
$check_num--;
|
|
|
|
$cmd = "lssrc -s xcatd | grep 'xcatd' | grep 'active'";
|
|
|
|
my @output = `$cmd`;
|
|
|
|
if (scalar(@output) == 0) {
|
|
|
|
sleep 1;
|
|
|
|
} else {
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($check_num <= 0) {
|
2010-01-06 09:38:35 +00:00
|
|
|
xCAT::MsgUtils->message("E", "Error: Cannot start the xcatd subsystem correctly.\n");
|
2009-12-03 08:01:33 +00:00
|
|
|
exit 1;
|
|
|
|
} else {
|
2009-12-04 04:32:19 +00:00
|
|
|
if ($::VERBOSE) {
|
|
|
|
xCAT::MsgUtils->message("I", "Started the xcatd subsystem.\n");
|
|
|
|
}
|
2009-12-03 08:01:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
exit 0;
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
=head3 parse_args
|
|
|
|
|
|
|
|
Parses for input
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
|
|
|
#-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
sub parse_args
|
|
|
|
{
|
2009-12-04 04:32:19 +00:00
|
|
|
my $usagemsg = "restartxcatd [[-h|--help] | [-v|--version] | [-r|--reload]] [-V|--verbose]\n";
|
|
|
|
|
2009-12-03 08:01:33 +00:00
|
|
|
Getopt::Long::Configure("posix_default");
|
|
|
|
Getopt::Long::Configure("no_gnu_compat");
|
|
|
|
Getopt::Long::Configure("bundling");
|
|
|
|
if (
|
|
|
|
!GetOptions(
|
|
|
|
'h|help' => \$::HELP,
|
|
|
|
'r|reload' => \$::RELOAD,
|
2009-12-04 04:32:19 +00:00
|
|
|
'v|version' => \$::VERSION,
|
|
|
|
'V|verbose' => \$::VERBOSE
|
2009-12-03 08:01:33 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
xCAT::MsgUtils->message("E", $usagemsg);
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
if ($::HELP)
|
|
|
|
{
|
|
|
|
xCAT::MsgUtils->message("I", $usagemsg);
|
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
if ($::RELOAD)
|
|
|
|
{
|
|
|
|
$ENV{XCATRELOAD} = "yes";
|
|
|
|
}
|
|
|
|
if ($::VERSION)
|
|
|
|
{
|
|
|
|
my $version = xCAT::Utils->Version();
|
|
|
|
$version .="\n";
|
|
|
|
xCAT::MsgUtils->message("I", $version);
|
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|