You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by mb...@apache.org on 2016/10/28 16:01:52 UTC

asterixdb git commit: Detect, Option to Forcibly Terminate AsterixDB Processes

Repository: asterixdb
Updated Branches:
  refs/heads/master 82a831d26 -> fec04f03d


Detect, Option to Forcibly Terminate AsterixDB Processes

Usability changes for sample local cluster:
1. Before start, check if there are any AsterixDB proceses running.  If so,
   error out.  This can be overridden with -f, which will proceed to start
   the cluster anyway.  This is useful in case where the other processes
   are operating on non-conflicting ports.
2. After stop, check if there are any AsterixDB processes running.  If
   so, emit a warning, and if -f is supplied to stop, kill any
   straggling processes.

Change-Id: Ie09c86fe67f7933574a03574fbe334e8c1be2bbd
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1316
Sonar-Qube: Jenkins <je...@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
Tested-by: Michael Blow <mb...@apache.org>
Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <ti...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/fec04f03
Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/fec04f03
Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/fec04f03

Branch: refs/heads/master
Commit: fec04f03d2ec84d5f84abf8e3df85056549f5c4a
Parents: 82a831d
Author: Michael Blow <mb...@apache.org>
Authored: Thu Oct 27 21:15:20 2016 -0400
Committer: Michael Blow <mb...@apache.org>
Committed: Fri Oct 28 09:01:18 2016 -0700

----------------------------------------------------------------------
 .../src/main/assembly/filter.properties         |  1 +
 .../samples/local/bin/start-sample-cluster.sh   | 38 +++++++++++++-
 .../samples/local/bin/stop-sample-cluster.sh    | 52 +++++++++++++++-----
 3 files changed, 78 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fec04f03/asterixdb/asterix-server/src/main/assembly/filter.properties
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-server/src/main/assembly/filter.properties b/asterixdb/asterix-server/src/main/assembly/filter.properties
index f7a53b3..34d86df 100644
--- a/asterixdb/asterix-server/src/main/assembly/filter.properties
+++ b/asterixdb/asterix-server/src/main/assembly/filter.properties
@@ -3,3 +3,4 @@ CC_COMMAND=asterixcc
 NC_COMMAND=asterixnc
 HELPER_COMMAND=asterixhelper
 LISTEN_PORT=19002
+PRODUCT=AsterixDB
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fec04f03/asterixdb/asterix-server/src/main/samples/local/bin/start-sample-cluster.sh
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-server/src/main/samples/local/bin/start-sample-cluster.sh b/asterixdb/asterix-server/src/main/samples/local/bin/start-sample-cluster.sh
index 53ceff8..d702e8a 100755
--- a/asterixdb/asterix-server/src/main/samples/local/bin/start-sample-cluster.sh
+++ b/asterixdb/asterix-server/src/main/samples/local/bin/start-sample-cluster.sh
@@ -18,6 +18,22 @@
 # under the License.
 # ------------------------------------------------------------
 
+function usage() {
+  echo
+  echo Usage: $(basename $0) [-f[orce]]
+  echo
+  echo "  -f[orce]  : Forces a start attempt when ${PRODUCT} processes are found to be running"
+}
+
+while [ -n "$1" ]; do
+  case $1 in
+    -f|-force) force=1;;
+    -help|--help|-usage|--usage) usage; exit 0;;
+    *) echo "ERROR: unknown argument '$1'"; usage; exit 1;;
+  esac
+  shift
+done
+
 if [ -z "$JAVA_HOME" -a -x /usr/libexec/java_home ]; then
   JAVA_HOME=$(/usr/libexec/java_home)
   export JAVA_HOME
@@ -51,12 +67,32 @@ mkdir -p $LOGSDIR
 $INSTALLDIR/bin/${HELPER_COMMAND} get_cluster_state -quiet \
     && echo "ERROR: sample cluster address (localhost:${LISTEN_PORT}) already in use" && exit 1
 
+if $JAVA_HOME/bin/jps | grep ' \(CCDriver\|NCDriver\|NCService\)$' > /tmp/$$_jps; then
+  if [ $force ]; then
+    severity=WARNING
+  else
+    severity=ERROR
+  fi
+  echo -n "${severity}: ${PRODUCT} processes are already running; "
+  if [ $force ]; then
+    echo "-f[orce] specified, ignoring"
+  else
+    echo "aborting"
+    echo
+    echo "Re-run with -f to ignore, or run stop-sample-cluster.sh -f to forcibly terminate all running ${PRODUCT} processes:"
+    cat /tmp/$$_jps | sed 's/^/  - /'
+    rm /tmp/$$_jps
+    exit 1
+  fi
+fi
+
+rm /tmp/$$_jps
 (
   echo "--------------------------"
   date
   echo "--------------------------"
 ) | tee -a $LOGSDIR/blue-service.log | tee -a $LOGSDIR/red-service.log >> $LOGSDIR/cc.log
-echo "Starting sample cluster..."
+echo "INFO: Starting sample cluster..."
 $INSTALLDIR/bin/${NC_SERVICE_COMMAND} -logdir - -config-file $CLUSTERDIR/conf/blue.conf >> $LOGSDIR/blue-service.log 2>&1 &
 $INSTALLDIR/bin/${NC_SERVICE_COMMAND} -logdir - >> $LOGSDIR/red-service.log 2>&1 &
 $INSTALLDIR/bin/${CC_COMMAND} -config-file $CLUSTERDIR/conf/cc.conf >> $LOGSDIR/cc.log 2>&1 &

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/fec04f03/asterixdb/asterix-server/src/main/samples/local/bin/stop-sample-cluster.sh
----------------------------------------------------------------------
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 b69ee53..f6824c8 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
@@ -18,6 +18,22 @@
 # under the License.
 # ------------------------------------------------------------
 
+function usage() {
+  echo
+  echo Usage: $(basename $0) [-f[orce]]
+  echo
+  echo "  -f[orce]  : Forcibly terminates any running ${PRODUCT} processes (after shutting down cluster, if running)"
+}
+
+while [ -n "$1" ]; do
+  case $1 in
+    -f|-force) force=1;;
+    -help|--help|-usage|--usage) usage; exit 0;;
+    *) echo "ERROR: unknown argument '$1'"; usage; exit 1;;
+    esac
+  shift
+done
+
 if [ -z "$JAVA_HOME" -a -x /usr/libexec/java_home ]; then
   JAVA_HOME=$(/usr/libexec/java_home)
   export JAVA_HOME
@@ -43,19 +59,31 @@ INSTALLDIR=$(cd $CLUSTERDIR/../..; echo $PWD)
 $INSTALLDIR/bin/${HELPER_COMMAND} get_cluster_state -quiet
 if [ $? -ne 1 ]; then
   $INSTALLDIR/bin/${HELPER_COMMAND} shutdown_cluster_all
+  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
+    sleep 1s
+    echo -n .
+    tries=$(expr $tries + 1)
+  done
+  echo ".done." || true
 else
-  echo "WARNING: sample cluster does not appear to be running, will attempt to wait for"
-  echo "         CCDriver to terminate if running."
+  echo "WARNING: sample cluster does not appear to be running"
 fi
 
-first=1
-while [ -n "$($JAVA_HOME/bin/jps | awk '/CCDriver/')" ]; do
-  if [ $first ]; then
-    echo
-    echo -n "Waiting for CCDriver to terminate."
-    unset first
+if $JAVA_HOME/bin/jps | grep ' \(CCDriver\|NCDriver\|NCService\)$' > /tmp/$$_jps; then
+  echo -n "WARNING: ${PRODUCT} processes remain after cluster shutdown; "
+  if [ $force ]; then
+    echo "-f[orce] specified, forcibly terminating ${PRODUCT} processes:"
+    cat /tmp/$$_jps | while read line; do
+      echo -n "   - $line..."
+      echo $line | awk '{ print $1 }' | xargs -n1 kill -9
+      echo "killed"
+    done
+  else
+    echo "re-run with -f|-force to forcibly terminate all ${PRODUCT} processes:"
+    cat /tmp/$$_jps | sed 's/^/  - /'
   fi
-  sleep 2s
-  echo -n .
-done
-[ ! $first ] && echo ".done." || true
+fi
+rm /tmp/$$_jps