From 2a567b9675253001900a01b31e6ce9eec48b237a Mon Sep 17 00:00:00 2001
From: linggao <linggao@8638fb3e-16cb-4fca-ae20-7b5d299a9bcd>
Date: Fri, 27 Jun 2008 14:35:20 +0000
Subject: [PATCH] more fixes for RMC monitoring on AIX and Linux

git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@1802 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
---
 xCAT-rmc/scripts/configrmcnode             | 24 ++++++++-----
 xCAT-server/lib/xcat/plugins/aixinstall.pm | 40 ++++++++++++----------
 xCAT-server/lib/xcat/plugins/pxe.pm        | 18 +++++-----
 xCAT-server/lib/xcat/plugins/yaboot.pm     | 15 ++++----
 4 files changed, 57 insertions(+), 40 deletions(-)

diff --git a/xCAT-rmc/scripts/configrmcnode b/xCAT-rmc/scripts/configrmcnode
index d22dd74ab..6b627c96c 100755
--- a/xCAT-rmc/scripts/configrmcnode
+++ b/xCAT-rmc/scripts/configrmcnode
@@ -28,16 +28,24 @@ fi
 
 #ask RMC take the new nodeid
 if [[ $NODEID != "" ]]; then
+  #stop all rmc daemons
+  /usr/sbin/rsct/bin/rmcctrl -z
+
+  #get new nodeid into id files
   if [ -e /var/ct/cfg/ct_node_id ]; then
-    sed -i s/^[^\#].*$/$NODEID/ /var/ct/cfg/ct_node_id
+    sed s/^[^\#].*$/$NODEID/ /var/ct/cfg/ct_node_id > /tmp/id.tmp
   else
-    echo $NODEID > /var/ct/cfg/ct_node_id 
-  fi
-  if [ -e /etc/ct_node_id ]; then
-    sed -i s/^[^\#].*$/$NODEID/ /etc/ct_node_id
-  else
-    echo $NODEID > /etc/ct_node_id
+    if [ -e /etc/ct_node_id ]; then
+      sed s/^[^\#].*$/$NODEID/ /etc/ct_node_id >  /tmp/id.tmp
+    else 
+      echo $NODEID > /tmp/id.tmp
+    fi
   fi
+  cp /tmp/id.tmp /var/ct/cfg/ct_node_id
+  cp /tmp/id.tmp /etc/ct_node_id
+  rm /tmp/id.tmp
+
+  #reconfig RMC
   result=`/usr/sbin/rsct/install/bin/recfgct -s 2>&1`
   if [ $? -ne 0 ]; then
     logger xCAT "RMC setup on node $NODE: Cannot reconfig RSCT with new node id" 
@@ -69,7 +77,7 @@ if [ $ADD -eq 1 ]; then
     #ms_ip=${result:$index1+1:$index2-$index1-2}
     pos=`expr $index1 + 1`
     length=`expr $index2 - $index1`
-    length=`expr $length - 2`
+    length=`expr $length - 1`
     ms_ip=`expr substr "$result" $pos $length`
   else
     logger xCAT "RMC setup on node $NODE:$result"
diff --git a/xCAT-server/lib/xcat/plugins/aixinstall.pm b/xCAT-server/lib/xcat/plugins/aixinstall.pm
index b94902f87..991edb739 100644
--- a/xCAT-server/lib/xcat/plugins/aixinstall.pm
+++ b/xCAT-server/lib/xcat/plugins/aixinstall.pm
@@ -255,14 +255,6 @@ sub nimnodeset
     	return 1;
 	}
 
-    ###################
-    #give monitoring code a chance to prepare the master for the node deployment
-    my %new_request = (
-       command => ['moncfgmaster'],
-       node => \@nodelist
-     );
-    $sub_req->(\%new_request, \&pass_along);
-    ###################
 
     #
     #  Get a list of the defined NIM machines
@@ -529,6 +521,16 @@ ll~;
 		my $rsp;
 		push @{$rsp->{data}}, "AIX/NIM nodes were initialized.\n";
 		xCAT::MsgUtils->message("I", $rsp, $callback);
+                ###################
+                #give monitoring code a chance to prepare the master for the node deployment
+		#push @{$rsp->{data}}, "Initializing for the node monitoring.\n";
+		#xCAT::MsgUtils->message("I", $rsp, $callback);
+                my %new_request = (
+                command => ['moncfgmaster'],
+                node => \@nodelist
+                );
+                $sub_req->(\%new_request, \&pass_along);
+                ###################
 		return 0;
 	}
 	return 0;
@@ -2675,15 +2677,7 @@ sub mkdsklsnode
 		return 1;
 	}
 
-    #################
-    #give monitoring code a chance to prepare the master for the node deployment
-    my %new_request = (
-       command => ['moncfgmaster'],
-       node => \@nodelist
-     );
-    $sub_req->(\%new_request, \&pass_along);
-    #################
-    
+   
     #
     #  Get a list of the defined NIM machines
     #
@@ -2991,7 +2985,17 @@ if (0) {
 		my $rsp;
 		push @{$rsp->{data}}, "AIX/NIM diskless nodes were initialized.\n";
 		xCAT::MsgUtils->message("I", $rsp, $callback);
-		return 0;
+                #################
+                #give monitoring code a chance to prepare the master for the node deployment
+		#push @{$rsp->{data}}, "Initializing for the node monitoring.\n";
+		#xCAT::MsgUtils->message("I", $rsp, $callback);
+                my %new_request = (
+                command => ['moncfgmaster'],
+                node => \@nodelist
+                );
+                $sub_req->(\%new_request, \&pass_along);
+                #################
+ 		return 0;
 	}
 }
 
diff --git a/xCAT-server/lib/xcat/plugins/pxe.pm b/xCAT-server/lib/xcat/plugins/pxe.pm
index b6736fafd..3da633dbd 100644
--- a/xCAT-server/lib/xcat/plugins/pxe.pm
+++ b/xCAT-server/lib/xcat/plugins/pxe.pm
@@ -233,14 +233,6 @@ sub process_request {
       return;
   }
 
-  #give monitoring code a chance to prepare the master for the node deployment
-  my %new_request = (
-       command => ['moncfgmaster'],
-       node => \@rnodes
-    );
-  $sub_req->(\%new_request, \&pass_along);
-
-  #back to normal business
   #if not shared, then help sync up
   if ($req->{_disparatetftp}) { #reading hint from preprocess_command
    @nodes = ();
@@ -290,6 +282,16 @@ sub process_request {
       setstate($_);
     }
   }
+
+  ##################################
+  #give monitoring code a chance to prepare the master for the node deployment
+  my %new_request = (
+       command => ['moncfgmaster'],
+       node => \@rnodes
+    );
+  $sub_req->(\%new_request, \&pass_along);
+  ##################################
+
 }
 
 
diff --git a/xCAT-server/lib/xcat/plugins/yaboot.pm b/xCAT-server/lib/xcat/plugins/yaboot.pm
index a717d4fbd..217619118 100644
--- a/xCAT-server/lib/xcat/plugins/yaboot.pm
+++ b/xCAT-server/lib/xcat/plugins/yaboot.pm
@@ -224,12 +224,6 @@ sub process_request {
       return;
   }
 
-  #give monitoring code a chance to prepare the master for the node deployment
-  my %new_request = (
-       command => ['moncfgmaster'],
-       node => \@rnodes
-    );
-  $sub_req->(\%new_request, \&pass_along);
 
   #back to normal business
   #if not shared tftpdir, then filter, otherwise, set up everything
@@ -267,6 +261,15 @@ sub process_request {
       setstate($_);
     }
   }
+
+  #####################################
+  # give monitoring code a chance to prepare the master for the node deployment
+  my %new_request = (
+       command => ['moncfgmaster'],
+       node => \@rnodes
+    );
+  $sub_req->(\%new_request, \&pass_along);
+  #####################################
 }