summaryrefslogtreecommitdiff
path: root/qpid/cpp/src/tests/qpid-test-cluster
blob: 82f577e05f0de983f69c41012751a971559bb8df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/sh
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#

usage() {
    echo "Usage: `basename $0` [options] start|stop|restart|check [qpidd-args]
Start/stop/restart a cluster on hosts in \$HOSTS via ssh.

Options:
 -l USER     Run qpidd and copy files as USER.
 -e SCRIPT   Source SCRIPT for environment settings. Copies SCRIPT to each host.
             Default is $DEFAULT_ENV.
 -c CONFIG   Use CONFIG as qpidd config file. Copies CONFIG to each host.
             Default is $DEFAULT_CONF
"
    exit 1
}

DEFAULT_CONF=~/qpid-test-qpidd.conf
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
    case $opt in
	l) SSHOPTS="-l$OPTARG $SSHOPTS" ; RSYNC_USER="$OPTARG@" ;;
	e) ENV_FILE=$OPTARG ;;
	c) CONF_FILE=$OPTARG ;;
	*) usage;;
    esac
done
shift `expr $OPTIND - 1`
test "$*" || usage
CMD=$1; shift
QPIDD_ARGS="$QPIDD_ARGS $*"

if test -n "$CONF_FILE"; then
    RSYNCFILES="$RSYNCFILES $CONF_FILE"
    QPIDD_ARGS="$QPIDD_ARGS --config $CONF_FILE"
    QPID_PORT=${QPID_PORT:-`awk -F= '/^ *port=/ {print $2}' $CONF_FILE`}
fi
if test -n "$ENV_FILE"; then
    RSYNCFILES="$RSYNCFILES $ENV_FILE"
    SOURCE_ENV="source $ENV_FILE && "
fi
test -n "$RSYNCFILES" && rsynchosts $RSYNCFILES

do_start() {
    for h in $HOSTS; do
	COMMAND="qpidd -d $QPIDD_ARGS"
	id -nG | grep '\<ais\>' >/dev/null && COMMAND="sg ais -c '$COMMAND'"
	ssh $SSHOPTS $h "$SOURCE_ENV $COMMAND" || { echo "error on $h: $COMMAND"; exit 1; }
    done
}

do_stop() {
    for h in $HOSTS; do ssh $SSHOPTS $h "$SOURCE_ENV qpidd -q $QPIDD_ARGS"; done
}

do_check() {
    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
	else
	    echo $h failed
	fi
    done
}
case $CMD in
    start) do_start ;;
    stop) do_stop ;;
    restart) do_stop ; do_start ;;
    check) do_check ;;
    *) usage;;
esac