Skip to content

Instantly share code, notes, and snippets.

@bageljp
Last active December 16, 2015 22:39
Show Gist options
  • Select an option

  • Save bageljp/5508764 to your computer and use it in GitHub Desktop.

Select an option

Save bageljp/5508764 to your computer and use it in GitHub Desktop.
apache balancer manager control
#!/bin/bash
#------------------------------------------------------------------------------
#
# Author(s): K.Kadoyama
#
# Usage:
# apache_balancer.bash {worker-url} {ENABLE|DISABLE} [https]
# apache_balancer.bash status [https]
#
# Current Version: 1.1.0
#
# Revision History:
#
# Version 1.0.0 by K.Kadoyama (2013/05/03)
# - Initial new.
#
# Version 1.1.0 by K.Kadoyama (2013/05/06)
# - Change nonce auto get.
#
# Example:
# # please, define URL_BLM
# apache_balancer.bash 192.168.0.1 DISABLE
# apache_balancer.bash 172.16.1.2 ENABLE https
#
#------------------------------------------------------------------------------
#==============================================================================
# Define
#==============================================================================
CMD_CURL="/usr/bin/curl"
WORKER_TARGET="$1"
FLG_ACT="$2"
BLM_URL="/balancer-manager"
URL_MAIN="${BLM_URL}?b=cluster&w=ajp://${WORKER_TARGET}:8009&dw=${FLG_ACT}"
BLM_LIST="192.168.0.1
192.168.0.2
192.168.0.3"
#==============================================================================
# Main
#==============================================================================
if [ "$1" != "status" -a "$2" != "ENABLE" -a "$2" != "DISABLE" ]; then
echo "Usage: `basename $0` {worker-url} {ENABLE|DISABLE|status} [https]"
echo " `basename $0` status [https]"
exit 1
fi
# get nonce
for i in `echo "${BLM_LIST}"`; do
nonce=`${CMD_CURL} -s ${i}${BLM_URL} | grep nonce | awk -F'nonce=' '{print $2}' | awk -F'">' '{print $1}' | uniq`
URL_BLM+=("http://${i}${URL_MAIN}&nonce=${nonce}")
done
# show status
if [ "$1" == "status" ]; then
echo "### apache balancer-manager status check ###"
for i in ${URL_BLM[@]}; do
j="${i/balancer-manager*/balancer-manager}"
${CMD_CURL} -s "${j}" | grep "Dis"
[ "$2" == "https" ] && ${CMD_CURL} -sk "${j/http/https}" | grep "Dis"
done
echo "### end ###"
exit 0
fi
# worker to enable or disable
for i in ${URL_BLM[@]}; do
${CMD_CURL} "${i}"
if [ "$3" == "https" ]; then
sleep 1
${CMD_CURL} -k "${i/http/https}"
fi
sleep 1
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment