From 2d4e596b3d1bc6a021a48ff24d5e5867f645e899 Mon Sep 17 00:00:00 2001 From: daniceexi Date: Thu, 3 Dec 2009 08:01:33 +0000 Subject: [PATCH] Code drop of supporting the SRC mechanism for xcatd git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@4713 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd --- xCAT-rmc/xCAT-rmc.spec | 2 +- xCAT-server/sbin/mysqlsetup | 4 +- xCAT-server/sbin/restartxcatd | 220 ++++++++++++++++++++++++++++++++++ xCAT-server/sbin/xcatconfig | 16 ++- xCAT-server/sbin/xcatd | 32 +++-- xCAT-server/xCAT-server.spec | 6 +- xCAT/postscripts/servicenode | 21 ++-- 7 files changed, 276 insertions(+), 25 deletions(-) create mode 100755 xCAT-server/sbin/restartxcatd diff --git a/xCAT-rmc/xCAT-rmc.spec b/xCAT-rmc/xCAT-rmc.spec index cd4b61877..5677227fc 100644 --- a/xCAT-rmc/xCAT-rmc.spec +++ b/xCAT-rmc/xCAT-rmc.spec @@ -81,7 +81,7 @@ rm -rf $RPM_BUILD_ROOT %else #restart the xcatd on if xCAT or xCATsn is installed already if [ -f $RPM_INSTALL_PREFIX0/sbin/xcatd ]; then - XCATROOT=$RPM_INSTALL_PREFIX0 $RPM_INSTALL_PREFIX0/sbin/xcatstart -r + XCATROOT=$RPM_INSTALL_PREFIX0 $RPM_INSTALL_PREFIX0/sbin/restartxcatd -r fi %endif diff --git a/xCAT-server/sbin/mysqlsetup b/xCAT-server/sbin/mysqlsetup index 2211ebfac..3e4b2c467 100755 --- a/xCAT-server/sbin/mysqlsetup +++ b/xCAT-server/sbin/mysqlsetup @@ -849,7 +849,7 @@ sub mysqlreboot } $cmd = - "awk '{gsub(\"xcatd:2:once:/opt/xcat/sbin/xcatd > /dev/console 2>&1\",\"mysql:2:once:/usr/local/mysql/bin/mysqld_safe --user=mysql \\& \\nxcatd:2:once:/opt/xcat/sbin/xcatd > /dev/console 2>\\&1\"); print}' /etc/inittab > /etc/inittab.xcat"; + "awk '{gsub(\"xcatd:2:once:/opt/xcat/sbin/restartxcatd > /dev/console 2>&1\",\"mysql:2:once:/usr/local/mysql/bin/mysqld_safe --user=mysql \\& \\nxcatd:2:once:/opt/xcat/sbin/restartxcatd > /dev/console 2>\\&1\"); print}' /etc/inittab > /etc/inittab.xcat"; xCAT::Utils->runcmd($cmd, 0); if ($::RUNCMD_RC != 0) @@ -1522,7 +1522,7 @@ sub restorexcatdb my $xcmd; if ($::osname eq 'AIX') { - $xcmd = "$::XCATROOT/sbin/xcatstart"; + $xcmd = "$::XCATROOT/sbin/restartxcatd"; } else diff --git a/xCAT-server/sbin/restartxcatd b/xCAT-server/sbin/restartxcatd new file mode 100755 index 000000000..2018191ff --- /dev/null +++ b/xCAT-server/sbin/restartxcatd @@ -0,0 +1,220 @@ +#!/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 +my $cmd = basename($0); +if (!(xCAT::Utils->isAIX())) +{ # only runs on AIX + xCAT::MsgUtils->message("E", "This command should only be run on AIX.\n"); + exit 1; + +} + +&parse_args($cmd); + +my $rc; +my $cmd; +my @output; +my $inoperative = 0; +my $check_num; + +# Check whether the xcatd subsystem has been created +$cmd = "/usr/bin/lssrc -s xcatd | grep \"xcatd Subsystem is not on file\""; +@output = `$cmd`; +if (@output) { + xCAT::MsgUtils->message("E", "Cannot find the xcatd subsystem on the Management Node.\n"); + exit 1; +} + +# Check the current status of xcatd subsystem +$cmd = "lssrc -s xcatd | grep 'xcatd' | grep 'inoperative'"; +@output = `$cmd`; +if (scalar(@output)) { + xCAT::MsgUtils->message("I", "xcatd subsystem in inoperative status.\n"); + $inoperative = 1; +} + +if ($inoperative) { + # Kill xcatd if needed + $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; + $cmd = "/usr/bin/kill -15 -$pid"; + $rc = system($cmd); + if ($rc >> 8) { + xCAT::MsgUtils->message("E", "Cannot kill the xcatd processes correctly.\n"); + exit 1; + } + } + $check_num = 10; + while ($check_num > 0) { + $check_num--; + @output = `$cmd`; + if (scalar(@output)) { + sleep 1; + } else { + last; + } + } + if ($check_num <= 0) { + xCAT::MsgUtils->message("E", "Cannot kill the xcatd processes correctly.\n"); + exit 1; + } +} else { + # Stop the xcatd subsystem + $cmd = "/usr/bin/stopsrc -s xcatd"; + $rc = system($cmd); + if ($rc >> 8) { + xCAT::MsgUtils->message("E", "Cannot run stopsrc command correctly.\n"); + exit 1; + } + + # Wait for end of the xcatd subsystem + $check_num = 10; + 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) { + xCAT::MsgUtils->message("E", "Cannot stop the xcatd subsystem correctly.\n"); + exit 1; + } else { + xCAT::MsgUtils->message("I", "Stoped the xcatd subsystem.\n"); + } +} + +# 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) { + xCAT::MsgUtils->message("E", "Cannot run startsrc command correctly.\n"); + exit 1; +} + +# Check the status of xcatd subsystem +$check_num = 10; +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) { + xCAT::MsgUtils->message("E", "Cannot start the xcatd subsystem correctly.\n"); + exit 1; +} else { + xCAT::MsgUtils->message("I", "Started the xcatd susbsystem.\n"); +} + +exit 0; + +#----------------------------------------------------------------------------- + +=head3 parse_args + + Parses for input + +=cut + +#----------------------------------------------------------------------------- + +my $usagemsg = "restartxcatd [-h|-v|-r]\n"; + +sub parse_args +{ + my ($cmd) = @_; + my $msg; + my $usagemsg; + Getopt::Long::Configure("posix_default"); + Getopt::Long::Configure("no_gnu_compat"); + Getopt::Long::Configure("bundling"); + if ( + !GetOptions( + 'h|help' => \$::HELP, + 'r|reload' => \$::RELOAD, + 'v|version' => \$::VERSION + + ) + ) + { + 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; + } + +} + + + diff --git a/xCAT-server/sbin/xcatconfig b/xCAT-server/sbin/xcatconfig index e78e7b8db..26cc9c66f 100644 --- a/xCAT-server/sbin/xcatconfig +++ b/xCAT-server/sbin/xcatconfig @@ -258,10 +258,18 @@ if ($::INITIALINSTALL || $::FORCE || $::UPDATEINSTALL) &setupAIXIPMITool; + # Add the xcatd subsystem to the AIX + no strict 'refs'; + my $mkssys_cmd = "mkssys -p $::XCATROOT/sbin/xcatd -s xcatd -u 0 -S -n 15 -f 15 -a \"-f\""; + system($mkssys_cmd); + use strict; + # for AIX systems add xcatd to the /etc/inittab file + my $rmitab_cmd = "rmitab xcatd"; + system($rmitab_cmd); my $mkitab_cmd = - 'mkitab "xcatd:2:once:/opt/xcat/sbin/xcatd > /dev/console 2>&1" > /dev/null 2>&1'; - my $rc = system($mkitab_cmd); # may already be there no error check + "mkitab \"xcatd:2:once:$::XCATROOT/sbin/restartxcatd > /dev/console 2>&1\" > /dev/null 2>&1"; + my $rc = system($mkitab_cmd); # add AIX needed exports &setupAIXexports; @@ -319,15 +327,13 @@ if ($::INITIALINSTALL || $::FORCE || $::UPDATEINSTALL || $::genCredentials) my $xcmd; if ($::osname eq 'AIX') { - $xcmd = "$::XCATROOT/sbin/xcatstart"; - + $xcmd = "$::XCATROOT/sbin/restartxcatd"; } else { $xcmd = "/etc/init.d/xcatd restart"; } system($xcmd); - } # more - Linux-only config diff --git a/xCAT-server/sbin/xcatd b/xCAT-server/sbin/xcatd index 9b772b6b7..e6f4e773d 100755 --- a/xCAT-server/sbin/xcatd +++ b/xCAT-server/sbin/xcatd @@ -511,6 +511,9 @@ sub plugin_reaper { } $SIG{CHLD} = \&generic_reaper; + +my $pid_UDP; +my $pid_MON; $SIG{TERM} = $SIG{INT} = sub { printf("Asked to quit...\n"); $quit++; @@ -520,20 +523,30 @@ $SIG{TERM} = $SIG{INT} = sub { foreach (keys %plugin_children) { kill 2, $_; } + if ($pid_UDP) { + kill 2, $pid_UDP; + } + if ($pid_MON) { + kill 2, $pid_MON; + } + xCAT::Table::shut_dbworker; + if ($dbmaster) { + kill 2, $dbmaster; + } $SIG{ALRM} = sub { xexit 0; }; #die "Did not close out in time for 5 second grace period"; }; alarm(2); }; -my $pid = xCAT::Utils->xfork; -defined $pid or die "Unable to fork for UDP/TCP"; -unless ($pid) { +$pid_UDP = xCAT::Utils->xfork; +defined $pid_UDP or die "Unable to fork for UDP/TCP"; +unless ($pid_UDP) { $$progname="xcatd: UDP listener"; do_udp_service; xexit(0); } -$pid = xCAT::Utils->xfork; -defined $pid or die "Unable to fork installmonitor"; -unless ($pid) { +$pid_MON = xCAT::Utils->xfork; +defined $pid_MON or die "Unable to fork installmonitor"; +unless ($pid_MON) { $$progname="xcatd: install monitor"; do_installm_service; xexit(0); @@ -556,7 +569,12 @@ if ($inet6support) { } unless ($listener) { - kill 2, $pid; + kill 2, $pid_UDP; + kill 2, $pid_MON; + xCAT::Table::shut_dbworker; + if ($dbmaster) { + kill 2, $dbmaster; + } xCAT::MsgUtils->message("S","xCAT service unable to open SSL services on $port: $!"); closelog(); die "ERROR:Unable to start xCAT service on port $port."; diff --git a/xCAT-server/xCAT-server.spec b/xCAT-server/xCAT-server.spec index 593519ee4..ba6eddd93 100644 --- a/xCAT-server/xCAT-server.spec +++ b/xCAT-server/xCAT-server.spec @@ -71,8 +71,6 @@ chmod -h 755 $RPM_BUILD_ROOT/%{prefix}/sbin/* cp -h bin/* $RPM_BUILD_ROOT/%{prefix}/bin chmod -h 755 $RPM_BUILD_ROOT/%{prefix}/bin/* %endif -ln -sf ../sbin/stopstartxcatd $RPM_BUILD_ROOT/%{prefix}/sbin/xcatstart -ln -sf ../sbin/stopstartxcatd $RPM_BUILD_ROOT/%{prefix}/sbin/xcatstop #cp rc.d/* $RPM_BUILD_ROOT/%{prefix}/rc.d #chmod 755 $RPM_BUILD_ROOT/%{prefix}/rc.d/* @@ -97,6 +95,7 @@ set -x # For now, don't ship these plugins - to avoid AIX dependency. %ifnos linux +rm $RPM_BUILD_ROOT/%{prefix}/sbin/stopstartxcatd #rm $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT_plugin/blade.pm rm $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT_plugin/hpblade.pm rm $RPM_BUILD_ROOT/%{prefix}/lib/perl/xCAT_plugin/hpilo.pm @@ -186,7 +185,8 @@ fi if [ "$1" -gt "1" ]; then #only on upgrade for AIX... #migration issue for monitoring XCATROOT=$RPM_INSTALL_PREFIX0 $RPM_INSTALL_PREFIX0/sbin/chtab filename=monitorctrl.pm notification -d - XCATROOT=$RPM_INSTALL_PREFIX0 $RPM_INSTALL_PREFIX0/sbin/xcatstart -r + + XCATROOT=$RPM_INSTALL_PREFIX0 $RPM_INSTALL_PREFIX0/sbin/restartxcatd -r fi %endif diff --git a/xCAT/postscripts/servicenode b/xCAT/postscripts/servicenode index 6e22718e8..904f2fad6 100755 --- a/xCAT/postscripts/servicenode +++ b/xCAT/postscripts/servicenode @@ -162,24 +162,31 @@ sub setupAIXsn `logger -t xcat $msg`; } - # get the xCAT credentials from the server + # get the xCAT credentials from the server &getcreds; + # Add the xcatd subsystem to the AIX + my $mkssys_cmd = 'mkssys -p /opt/xcat/sbin/xcatd -s xcatd -u 0 -S -n 15 -f 15 -a "-f"'; + if (&runcmd($mkssys_cmd) != 0) { + $msg = "$::sdate servicenode: Could not create subsystem for xcatd. It maybe already have been added.\n"; + `logger -t xcat $msg`; + } + # start xcatd - if (&runcmd("/opt/xcat/sbin/xcatd &") != 0) { + if (&runcmd("/opt/xcat/sbin/restartxcatd") != 0) { $msg = "$::sdate servicenode: Could not start xcatd.\n"; - `logger -t xcat $msg`; - } + `logger -t xcat $msg`; + } # add xcatd to /etc/inittab??? - my $mkitab_cmd = 'mkitab "xcatd:2:once:/opt/xcat/sbin/xcatd > /dev/console 2>&1"'; + my $mkitab_cmd = 'mkitab "xcatd:2:once:/opt/xcat/sbin/restartxcatd > /dev/console 2>&1"'; if (&runcmd($mkitab_cmd) != 0) { # error might just mean that the entry is already there! # $msg = "$::sdate servicenode: Could not add xcatd to /etc/inittab.\n"; - # `logger -t xcat $msg`; - } + # `logger -t xcat $msg`; + } # set ulimit - so we can copy over large files - like spot if (&runcmd("/usr/bin/chuser fsize=-1 root") != 0) {