From 9d71144ea9ae463394506888e3e275c74c2eb486 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Wed, 12 Jan 2011 19:41:39 +0000 Subject: qpid-test-cluster script: added -d option to delete data-directory. Also allow hosts to be specified on command line. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1058287 13f79535-47bb-0310-9956-ffa450edef68 --- qpid/cpp/src/tests/qpid-test-cluster | 46 ++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/qpid/cpp/src/tests/qpid-test-cluster b/qpid/cpp/src/tests/qpid-test-cluster index 82f577e05f..9887406ef9 100755 --- a/qpid/cpp/src/tests/qpid-test-cluster +++ b/qpid/cpp/src/tests/qpid-test-cluster @@ -19,8 +19,8 @@ # usage() { - echo "Usage: `basename $0` [options] start|stop|restart|check [qpidd-args] -Start/stop/restart a cluster on hosts in \$HOSTS via ssh. + echo "Usage: `basename $0` [options] start|stop|restart|check [hosts] +Start/stop/restart a cluster on specified hosts or on \$HOSTS via ssh. Options: -l USER Run qpidd and copy files as USER. @@ -28,6 +28,7 @@ Options: Default is $DEFAULT_ENV. -c CONFIG Use CONFIG as qpidd config file. Copies CONFIG to each host. Default is $DEFAULT_CONF + -d Delete data-dir and log file before starting broker. " exit 1 } @@ -37,57 +38,72 @@ DEFAULT_ENV=~/qpid-test-env.sh test -f $DEFAULT_CONF && CONF_FILE=$DEFAULT_CONF test -f $DEFAULT_ENV && ENV_FILE=$DEFAULT_ENV -while getopts "l:e:c:" opt; do + +while getopts "l:e:c:d" opt; do case $opt in l) SSHOPTS="-l$OPTARG $SSHOPTS" ; RSYNC_USER="$OPTARG@" ;; e) ENV_FILE=$OPTARG ;; c) CONF_FILE=$OPTARG ;; + d) DO_DELETE=1 ;; *) usage;; esac done shift `expr $OPTIND - 1` test "$*" || usage CMD=$1; shift -QPIDD_ARGS="$QPIDD_ARGS $*" +HOSTS=${*:-$HOSTS} + +conf_value() { test -f "$CONF_FILE" && awk -F= "/^$1=/ {print \$2}" $CONF_FILE; } if test -n "$CONF_FILE"; then + test -f "$CONF_FILE" || { echo Config file not found: $CONF_FILE; exit 1; } RSYNCFILES="$RSYNCFILES $CONF_FILE" QPIDD_ARGS="$QPIDD_ARGS --config $CONF_FILE" - QPID_PORT=${QPID_PORT:-`awk -F= '/^ *port=/ {print $2}' $CONF_FILE`} + CONF_PORT=`conf_value port` + CONF_DATA_DIR=`conf_value data-dir` + CONF_LOG_FILE=`conf_value log-to-file` fi + if test -n "$ENV_FILE"; then + test -f "$ENV_FILE" || { echo Environment file not found: $ENV_FILE; exit 1; } RSYNCFILES="$RSYNCFILES $ENV_FILE" - SOURCE_ENV="source $ENV_FILE && " + SOURCE_ENV="source $ENV_FILE ; " fi -test -n "$RSYNCFILES" && rsynchosts $RSYNCFILES + +test -n "$RSYNCFILES" && rsynchosts $RSYNCFILES # Copy conf/env files to all hosts do_start() { for h in $HOSTS; do COMMAND="qpidd -d $QPIDD_ARGS" id -nG | grep '\' >/dev/null && COMMAND="sg ais -c '$COMMAND'" - ssh $SSHOPTS $h "$SOURCE_ENV $COMMAND" || { echo "error on $h: $COMMAND"; exit 1; } + if test "$DO_DELETE"; then COMMAND="rm -rf $CONF_DATA_DIR $CONF_LOG_FILE; $COMMAND"; fi + ssh $h "$SOURCE_ENV $COMMAND" || { echo "Failed to start on $h"; exit 1; } done } do_stop() { - for h in $HOSTS; do ssh $SSHOPTS $h "$SOURCE_ENV qpidd -q $QPIDD_ARGS"; done + for h in $HOSTS; do + ssh $h "$SOURCE_ENV qpidd -q --no-module-dir --no-data-dir $QPIDD_ARGS" + done } -do_check() { +do_status() { for h in $HOSTS; do - test -n "$QPID_PORT" && PORTOPT="-p $QPID_PORT" - if qpid-ping -b $h $PORTOPT -q $* &> /dev/null; then - echo $h ok + if ssh $h "$SOURCE_ENV qpidd -c --no-module-dir --no-data-dir $QPIDD_ARGS > /dev/null"; then + echo "$h ok" else - echo $h failed + echo "$h not running" + STATUS=1 fi done } + case $CMD in start) do_start ;; stop) do_stop ;; restart) do_stop ; do_start ;; - check) do_check ;; + status) do_status ;; *) usage;; esac +exit $STATUS -- cgit v1.2.1