Wait For NC Processes To Exit Before Sanity Check

Wait for NCService / NCDriver processes to exit (or timeout to exhaust)
before checking for extraneous processes.  Otherwise, a false-positive
may be reported.

Change-Id: I35ebad976fa49d308843aee784ceacff5850bd11
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1348
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <tillw@apache.org>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
diff --git a/asterixdb/asterix-server/src/main/samples/local/bin/stop-sample-cluster.bat b/asterixdb/asterix-server/src/main/samples/local/bin/stop-sample-cluster.bat
index 0971065..7ac9483 100644
--- a/asterixdb/asterix-server/src/main/samples/local/bin/stop-sample-cluster.bat
+++ b/asterixdb/asterix-server/src/main/samples/local/bin/stop-sample-cluster.bat
@@ -89,9 +89,9 @@
 set tries=0
 :wait_loop
 set /A tries=%tries% + 1
-if "%tries%" == "60" goto :post_shutdown
+if "%tries%" == "60" goto :timed_out
 wmic process where ^
-  "name='java.exe' and CommandLine like '%%org.codehaus.mojo.appassembler.booter.AppassemblerBooter%%' and CommandLine like '%%app.name=\"%%cc\"%%'" ^
+  "name='java.exe' and CommandLine like '%%org.codehaus.mojo.appassembler.booter.AppassemblerBooter%%' and (CommandLine like '%%app.name=\"%%[cn]c\"%%' or CommandLine like '%%app.name=\"%%ncservice\"%%')" ^
   GET processid >%tempfile% 2>/dev/null
 
 set found=
@@ -100,6 +100,11 @@
   timeout /T 1 /NOBREAK >/dev/null
   goto :wait_loop
 )
+goto :post_shutdown
+
+:timed_out
+echo timed out!
+
 :post_shutdown
 echo.
 
diff --git a/asterixdb/asterix-server/src/main/samples/local/bin/stop-sample-cluster.sh b/asterixdb/asterix-server/src/main/samples/local/bin/stop-sample-cluster.sh
index f6824c8..7ee5fdf 100755
--- a/asterixdb/asterix-server/src/main/samples/local/bin/stop-sample-cluster.sh
+++ b/asterixdb/asterix-server/src/main/samples/local/bin/stop-sample-cluster.sh
@@ -62,7 +62,11 @@
   first=1
   tries=0
   echo -n "INFO: Waiting up to 60s for cluster to shutdown"
-  while [ -n "$($JAVA_HOME/bin/jps | awk '/CCDriver/')" -a $tries -lt 60 ]; do
+  while [ -n "$($JAVA_HOME/bin/jps | awk '/ (CCDriver|NCDriver|NCService)$/')" ]; do
+    if [ $tries -ge 60 ]; then
+      echo "...timed out!"
+      break
+    fi
     sleep 1s
     echo -n .
     tries=$(expr $tries + 1)