e.g. ./balancer.sh enable http://web-01:8080
#!/bin/bash
set -e
print_usage()
{
echo "Usage: $0 enable|disable http://worker-url"
}
WORKER_URL=$2
ACTION=$1
if [ "${WORKER_URL}" == "" ]; then
print_usage
exit 1
fi
if [ "${ACTION}" == "" ]; then
print_usage
exit 1
fi
BALANCER_MANAGER_URL=http://load-balancer-host/balancer-manager
BALANCER_NAME=load-balancer
BALANCER_NONSE=`curl -s ${BALANCER_MANAGER_URL} | sed -n "/href=/s/.*href=\([^>]*\).*/\1/p" | tail -1 | sed -n "s/.*nonce=\(.*\)\"/\1/p"`
if [ "${BALANCER_NONSE}" == "" ]; then
echo "Could not extract nonce from ${BALANCER_MANAGER_URL}"
exit 1
fi
curl -s -o /dev/null "${BALANCER_MANAGER_URL}?b=${BALANCER_NAME}&w=${WORKER_URL}&dw=${ACTION}&nonce=${BALANCER_NONSE}"