2012-04-14 20:06:03 +02:00
#!/bin/bash
2023-01-27 20:15:54 +01:00
# ============== Apache Pekko Cluster Administration Tool ==============
2012-04-24 10:19:36 +02:00
#
2023-01-27 20:15:54 +01:00
# This script is meant to be used from within the Pekko distribution.
2012-04-24 10:19:36 +02:00
#
# Add these options to the sbt or startup script:
# java \
# -Dcom.sun.management.jmxremote.port=9999 \
# -Dcom.sun.management.jmxremote.ssl=false \
# -Dcom.sun.management.jmxremote.authenticate=false \
# ...
# ==============================================================
2012-04-16 16:58:19 +02:00
2012-04-24 10:19:36 +02:00
# FIXME support authentication? if so add: -Dcom.sun.management.jmxremote.password.file=<path to file> AND tweak this script to support it (arg need 'user:passwd' instead of '-')
2012-04-14 20:06:03 +02:00
2017-01-26 15:40:54 +01:00
2012-05-18 16:46:31 +02:00
2013-06-21 00:44:12 +02:00
SELF=`basename $0` # script name
HOST=$1 # cluster node to talk to through JMX
PORT=$2
2017-01-26 15:40:54 +01:00
JMXSHJAR=`dirname $0`/jmxsh-R5.jar
2012-05-18 16:46:31 +02:00
2013-06-21 00:44:12 +02:00
shift 2
2012-04-14 20:06:03 +02:00
2017-01-26 15:40:54 +01:00
JMX_CLIENT="java -jar $JMXSHJAR -h $HOST -p $PORT /dev/fd/0"
2013-06-21 00:44:12 +02:00
2017-03-14 22:31:58 +09:00
function mbeanObjectName() {
if [[ -z "$CLUSTER_PORT" ]]; then
2023-01-27 20:15:54 +01:00
echo "pekko:type=Cluster"
2017-03-14 22:31:58 +09:00
else
2023-01-27 20:15:54 +01:00
echo "pekko:type=Cluster,port=$CLUSTER_PORT"
2017-03-14 22:31:58 +09:00
fi
}
2013-06-21 00:44:12 +02:00
function invoke() {
2017-03-14 22:31:58 +09:00
echo jmx_invoke -m $(mbeanObjectName) "$@" | $JMX_CLIENT
2013-06-21 00:44:12 +02:00
}
function get() {
2017-03-14 22:31:58 +09:00
echo "puts [jmx_get -m $(mbeanObjectName) \"$1\"]" | $JMX_CLIENT
2013-06-21 00:44:12 +02:00
}
2012-04-16 11:23:03 +02:00
2012-04-23 14:13:05 +02:00
function ensureNodeIsRunningAndAvailable {
2016-03-22 15:37:06 +01:00
REPLY=$(get Available 2>&1) # redirects STDERR to STDOUT before capturing it
2012-04-23 14:13:05 +02:00
if [[ "$REPLY" != *true ]]; then
2016-03-22 15:37:06 +01:00
if [[ "$REPLY" == *"Cannot convert result to a string." ]]; then
2023-01-27 20:15:54 +01:00
echo "Pekko cluster MBean is not available on $HOST:$PORT with MBean name '$(mbeanObjectName)'"
2016-03-22 15:37:06 +01:00
else
2023-01-27 20:15:54 +01:00
echo "Pekko cluster node is not available on $HOST:$PORT with MBean name '$(mbeanObjectName)', due to $REPLY"
2016-03-22 15:37:06 +01:00
fi
2012-04-16 11:23:03 +02:00
exit 1
fi
}
2023-01-27 20:15:54 +01:00
echo "This jmx-client/pekko-cluster tool is deprecated use curl and https://github.com/apache/incubator-pekko-management instead." >&2
2016-12-13 10:54:41 +01:00
2012-04-20 00:11:30 +02:00
# switch on command
2017-03-14 22:31:58 +09:00
while [ $# -gt 0 ];
do
case "$1" in
2012-04-16 11:23:03 +02:00
join)
2013-06-21 00:44:12 +02:00
if [ $# -ne 2 ]; then
2017-03-14 22:31:58 +09:00
echo "Usage: $SELF <node-hostname> <jmx-port> <optional: -p cluster-port> join <node-url-to-join>"
2012-04-14 20:06:03 +02:00
exit 1
fi
2012-04-16 11:23:03 +02:00
ACTOR_SYSTEM_URL=$2
echo "$HOST is JOINING cluster node $ACTOR_SYSTEM_URL"
2013-06-21 00:44:12 +02:00
invoke join $ACTOR_SYSTEM_URL
2017-03-14 22:31:58 +09:00
shift 2
2012-04-14 20:06:03 +02:00
;;
leave)
2013-06-21 00:44:12 +02:00
if [ $# -ne 2 ]; then
2017-03-14 22:31:58 +09:00
echo "Usage: $SELF <node-hostname> <jmx-port> <optional: -p cluster-port> leave <node-url-to-join>"
2012-04-14 20:06:03 +02:00
exit 1
fi
2012-04-23 14:13:05 +02:00
ensureNodeIsRunningAndAvailable
2012-04-16 11:23:03 +02:00
ACTOR_SYSTEM_URL=$2
echo "Scheduling $ACTOR_SYSTEM_URL to LEAVE cluster"
2013-06-21 00:44:12 +02:00
invoke leave $ACTOR_SYSTEM_URL
2017-03-14 22:31:58 +09:00
shift 2
2012-04-14 20:06:03 +02:00
;;
down)
2013-06-21 00:44:12 +02:00
if [ $# -ne 2 ]; then
2017-03-14 22:31:58 +09:00
echo "Usage: $SELF <node-hostname> <jmx-port> <optional: -p cluster-port> down <node-url-to-join>"
2012-04-14 20:06:03 +02:00
exit 1
fi
2012-04-23 14:13:05 +02:00
ensureNodeIsRunningAndAvailable
2012-04-16 11:23:03 +02:00
ACTOR_SYSTEM_URL=$2
echo "Marking $ACTOR_SYSTEM_URL as DOWN"
2013-06-21 00:44:12 +02:00
invoke down $ACTOR_SYSTEM_URL
2017-03-14 22:31:58 +09:00
shift 2
2012-04-14 20:06:03 +02:00
;;
member-status)
2013-06-21 00:44:12 +02:00
if [ $# -ne 1 ]; then
2017-03-14 22:31:58 +09:00
echo "Usage: $SELF <node-hostname> <jmx-port> <optional: -p cluster-port> member-status"
2012-04-14 20:06:03 +02:00
exit 1
fi
2012-04-23 14:13:05 +02:00
ensureNodeIsRunningAndAvailable
2012-04-16 11:23:03 +02:00
echo "Querying member status for $HOST"
2013-06-21 00:44:12 +02:00
get MemberStatus
2017-03-14 22:31:58 +09:00
shift 1
2012-04-14 20:06:03 +02:00
;;
cluster-status)
2013-06-21 00:44:12 +02:00
if [ $# -ne 1 ]; then
2017-03-14 22:31:58 +09:00
echo "Usage: $SELF <node-hostname> <jmx-port> <optional: -p cluster-port> cluster-status"
2012-04-14 20:06:03 +02:00
exit 1
fi
2012-04-23 14:13:05 +02:00
ensureNodeIsRunningAndAvailable
2012-04-14 20:06:03 +02:00
2013-06-21 00:44:12 +02:00
get ClusterStatus
2017-03-14 22:31:58 +09:00
shift 1
2012-04-14 20:06:03 +02:00
;;
2012-12-06 10:47:24 +01:00
members)
2013-06-21 00:44:12 +02:00
if [ $# -ne 1 ]; then
2017-03-14 22:31:58 +09:00
echo "Usage: $SELF <node-hostname> <jmx-port> <optional: -p cluster-port> members"
2012-04-14 20:06:03 +02:00
exit 1
fi
2012-04-23 14:13:05 +02:00
ensureNodeIsRunningAndAvailable
2012-04-16 11:23:03 +02:00
2012-12-06 10:47:24 +01:00
echo "Querying members"
2013-06-21 00:44:12 +02:00
get Members
2017-03-14 22:31:58 +09:00
shift 1
2012-04-14 20:06:03 +02:00
;;
2012-12-06 10:47:24 +01:00
unreachable)
2013-06-21 00:44:12 +02:00
if [ $# -ne 1 ]; then
2017-03-14 22:31:58 +09:00
echo "Usage: $SELF <node-hostname> <jmx-port> <optional: -p cluster-port> unreachable"
2012-04-14 20:06:03 +02:00
exit 1
fi
2012-04-23 14:13:05 +02:00
ensureNodeIsRunningAndAvailable
2012-04-16 11:23:03 +02:00
2012-12-06 10:47:24 +01:00
echo "Querying unreachable members"
2013-06-21 00:44:12 +02:00
get Unreachable
2017-03-14 22:31:58 +09:00
shift 1
2012-04-14 20:06:03 +02:00
;;
2012-12-06 10:47:24 +01:00
leader)
2013-06-21 00:44:12 +02:00
if [ $# -ne 1 ]; then
2017-03-14 22:31:58 +09:00
echo "Usage: $SELF <node-hostname> <jmx-port> <optional: -p cluster-port> leader"
2012-04-14 20:06:03 +02:00
exit 1
fi
2012-04-23 14:13:05 +02:00
ensureNodeIsRunningAndAvailable
2012-04-16 11:23:03 +02:00
2012-12-06 10:47:24 +01:00
echo "Checking leader status"
2013-06-21 00:44:12 +02:00
get Leader
2017-03-14 22:31:58 +09:00
shift 1
2012-12-06 10:47:24 +01:00
;;
is-singleton)
2013-06-21 00:44:12 +02:00
if [ $# -ne 1 ]; then
2017-03-14 22:31:58 +09:00
echo "Usage: $SELF <node-hostname> <jmx-port> <optional: -p cluster-port> is-singleton"
2012-12-06 10:47:24 +01:00
exit 1
fi
ensureNodeIsRunningAndAvailable
echo "Checking for singleton cluster"
2013-06-21 00:44:12 +02:00
get Singleton
2017-03-14 22:31:58 +09:00
shift 1
2012-04-14 20:06:03 +02:00
;;
is-available)
2013-06-21 00:44:12 +02:00
if [ $# -ne 1 ]; then
2017-03-14 22:31:58 +09:00
echo "Usage: $SELF <node-hostname> <jmx-port> <optional: -p cluster-port> is-available"
2012-04-14 20:06:03 +02:00
exit 1
fi
2012-04-23 14:13:05 +02:00
ensureNodeIsRunningAndAvailable
2012-04-16 11:23:03 +02:00
2012-04-23 14:13:05 +02:00
echo "Checking if member node on $HOST is AVAILABLE"
2013-06-21 00:44:12 +02:00
get Available
2017-03-14 22:31:58 +09:00
shift 1
2012-04-14 20:06:03 +02:00
;;
2017-03-14 22:31:58 +09:00
-p)
if [[ ! $2 =~ ^[0-9]+$ ]]; then
echo "-p option requires a cluster port number in digits"
exit 1
fi
CLUSTER_PORT=$2
shift 2
;;
2012-04-14 20:06:03 +02:00
*)
2017-03-14 22:31:58 +09:00
printf "Usage: $0 <node-hostname> <jmx-port> <optional: -p cluster-port> <command> ...\n"
printf "\n"
2022-12-02 04:53:48 -08:00
printf "-p parameter needs is needed when cluster is run with pekko.cluster.jmx.multi-mbeans-in-same-jvm = on.¥n"
2012-04-20 00:11:30 +02:00
printf "\n"
printf "Supported commands are:\n"
2012-09-19 16:46:39 +02:00
printf "%26s - %s\n" "join <node-url>" "Sends request a JOIN node with the specified URL"
printf "%26s - %s\n" "leave <node-url>" "Sends a request for node with URL to LEAVE the cluster"
printf "%26s - %s\n" "down <node-url>" "Sends a request for marking node with URL as DOWN"
printf "%26s - %s\n" member-status "Asks the member node for its current status"
2012-12-06 10:47:24 +01:00
printf "%26s - %s\n" members "Asks the cluster for addresses of current members"
printf "%26s - %s\n" unreachable "Asks the cluster for addresses of unreachable members"
2012-09-19 16:46:39 +02:00
printf "%26s - %s\n" cluster-status "Asks the cluster for its current status (member ring, unavailable nodes, meta data etc.)"
printf "%26s - %s\n" leader "Asks the cluster who the current leader is"
printf "%26s - %s\n" is-singleton "Checks if the cluster is a singleton cluster (single node cluster)"
printf "%26s - %s\n" is-available "Checks if the member node is available"
2023-01-18 08:13:01 +01:00
printf "Where the <node-url> should be on the format of 'pekko.tcp://actor-system-name@hostname:port'\n"
2012-04-20 00:11:30 +02:00
printf "\n"
2017-01-26 15:40:54 +01:00
printf "Examples: $0 localhost 9999 is-available\n"
2023-01-18 08:13:01 +01:00
printf " $0 localhost 9999 join pekko.tcp://MySystem@darkstar:2552\n"
2017-01-26 15:40:54 +01:00
printf " $0 localhost 9999 cluster-status\n"
2017-03-14 22:31:58 +09:00
printf " $0 localhost 9999 -p 2551 is-available\n"
2023-01-18 08:13:01 +01:00
printf " $0 localhost 9999 -p 2551 join pekko.tcp://MySystem@darkstar:2552\n"
2017-03-14 22:31:58 +09:00
printf " $0 localhost 9999 -p 2551 cluster-status\n"
2012-04-14 20:06:03 +02:00
exit 1
;;
esac
2017-03-14 22:31:58 +09:00
done