Michael Blow has submitted this change and it was merged. Change subject: Detect, Option to Forcibly Terminate AsterixDB Processes ......................................................................
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 <[email protected]> Tested-by: Jenkins <[email protected]> Tested-by: Michael Blow <[email protected]> Integration-Tests: Jenkins <[email protected]> Reviewed-by: Till Westmann <[email protected]> --- M asterixdb/asterix-server/src/main/assembly/filter.properties M asterixdb/asterix-server/src/main/samples/local/bin/start-sample-cluster.sh M asterixdb/asterix-server/src/main/samples/local/bin/stop-sample-cluster.sh 3 files changed, 78 insertions(+), 13 deletions(-) Approvals: Michael Blow: Verified Till Westmann: Looks good to me, approved Jenkins: Verified; No violations found; Verified 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 @@ NC_COMMAND=asterixnc HELPER_COMMAND=asterixhelper LISTEN_PORT=19002 +PRODUCT=AsterixDB \ No newline at end of file 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 @@ $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 & 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/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 -- To view, visit https://asterix-gerrit.ics.uci.edu/1316 To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ie09c86fe67f7933574a03574fbe334e8c1be2bbd Gerrit-PatchSet: 4 Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Owner: Michael Blow <[email protected]> Gerrit-Reviewer: Jenkins <[email protected]> Gerrit-Reviewer: Michael Blow <[email protected]> Gerrit-Reviewer: Till Westmann <[email protected]>
