Marko Oldenburg e4c7b319e2
All checks were successful
Build Helm Chart / helm-package (push) Successful in 7s
first commit
2025-03-04 07:05:50 +01:00

76 lines
2.4 KiB
Bash
Executable File

#!/bin/sh
export BROKER_IP=`hostname -f`
instanceDir="${HOME}/${AMQ_NAME}"
ENDPOINT_NAME="${HEADLESS_ENDPOINT}"
if [ "$HEADLESS_SVC_NAME" ]; then
ENDPOINT_NAME=$HEADLESS_SVC_NAME
fi
endpointsUrl="https://${KUBERNETES_SERVICE_HOST:-kubernetes.default.svc}:${KUBERNETES_SERVICE_PORT:-443}/api/v1/namespaces/${POD_NAMESPACE}/"
endpointsAuth="Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)"
function waitForJolokia() {
while : ;
do
sleep 5
curl -s -o /dev/null -G -k http://${AMQ_USER}:${AMQ_PASSWORD}@${BROKER_IP}:8161/console/jolokia
if [ $? -eq 0 ]; then
break
fi
done
}
endpointsCode=$(curl -s -o /dev/null -w "%{http_code}" -G -k -H "${endpointsAuth}" ${endpointsUrl})
if [ $endpointsCode -ne 200 ]; then
echo "Can't find endpoints with ips status <${endpointsCode}>"
exit 1
fi
ENDPOINTS=$(curl -s -X GET -G -k -H "${endpointsAuth}" ${endpointsUrl}"endpoints/${ENDPOINT_NAME}")
echo $ENDPOINTS
count=0
while [ 1 ]; do
ip=$(echo $ENDPOINTS | python -c "import sys, json; print json.load(sys.stdin)['subsets'][0]['addresses'][${count}]['ip']")
if [ $? -ne 0 ]; then
echo "Can't find ip to scale down to tried ${count} ips"
exit
fi
echo "got ip ${ip} broker ip is ${BROKER_IP}"
if [ "$ip" != "$BROKER_IP" ]; then
break
fi
count=$(( count + 1 ))
done
source /opt/amq/bin/launch.sh nostart
SCALE_TO_BROKER_IP=$ip
# Add connector to the pod to scale down to
connector="<connector name=\"scaledownconnector\">tcp:\/\/${SCALE_TO_BROKER_IP}:61616<\/connector>"
sed -i "/<\/connectors>/ s/.*/${connector}\n&/" ${instanceDir}/etc/broker.xml
# Remove the acceptors
#sed -i -ne "/<acceptors>/ {p; " -e ":a; n; /<\/acceptors>/ {p; b}; ba}; p" ${instanceDir}/etc/broker.xml
acceptor="<acceptor name=\"artemis\">tcp:\/\/${BROKER_IP}:61616?protocols=CORE<\/acceptor>"
sed -i -ne "/<acceptors>/ {p; i $acceptor" -e ":a; n; /<\/acceptors>/ {p; b}; ba}; p" ${instanceDir}/etc/broker.xml
#start the broker and issue the scaledown command to drain the messages.
${instanceDir}/bin/artemis-service start
if [ "$AMQ_DATA_DIR_LOGGING" = "true" ]; then
tail -n 100 -f ${AMQ_DATA_DIR}/log/artemis.log &
else
tail -n 100 -f ${AMQ_NAME}/log/artemis.log &
fi
waitForJolokia
curl -s -o /dev/null -G -k http://${AMQ_USER}:${AMQ_PASSWORD}@${BROKER_IP}:8161/console/jolokia/exec/org.apache.activemq.artemis:broker=%22${AMQ_NAME}%22/scaleDown/scaledownconnector