We have a setup where we have one httpd (apache) with mod_jk talking in a load balance setup to three tomcat servers. We have to recycle each tomcat instance envery three hours. So tomcat1 will restart at 1, and tomcat2 at 2 and ... until tomcat1 recycles again at 4.
We want to configure a script or a type of program to disable the worker node that is going through a recylce to minimize session errors at the user using our application.
Any suggestions.
mod_jk re-reads workers.properties on an "apachectl graceful", so you if your workers.properties looks like this:
worker.loadbalancer.type=lb
worker.loadbalancer.balanced_workers=tomcat1, tomcat2, tomcat3
...
You could just write a script which replaces the balanced_workers list with the ones you want, and then graceful's apache
Update here's a script to do just that, which I cobbled together from some bits I had lying around. I wouldn't suggest using it in production, but it might give you some ideas for your own version.
#!/bin/bash
# set some paths
WORKERS_PROPERTIES="./workers.properties"
APACHECTL="/usr/sbin/apache2ctl"
# what does the loadbalancer config line look like?
WORKER_LINE_START="worker.loadbalancer.balanced_workers="
# full list of workers
ALL_WORKERS="tomcat1 tomcat2 tomcat3"
# first command line arg is the worker to remove.
remove=$1
# build up the new line listing the active workers
worker_line=$WORKER_LINE_START
sep=""
for worker in $ALL_WORKERS
do
if [ ${remove} != ${worker} ]
then
worker_line="${worker_line}$sep $worker"
sep=","
fi
done
# sed hackery to replace the current line with the one we just built.
# needs gnu sed (or another one that supports in-place editing)
sed -i.bak "s/^$WORKER_LINE_START.*$/$worker_line/" $WORKERS_PROPERTIES
# restart apache
$APACHECTL graceful
gkiragiannis, you answer was interesting, but doesn't seem to work for me. I wanted to only disable one of my subworkers at a time.
Lets assume we are working with the 'agent-lb' load balancer.
To view the worker status using this url:
server-name/jkmanager/?cmd=list&w=agent-lb
To disable the 'agent-n1' sub worker use this url:
server-name/jkmanager/?cmd=update&w=agent-lb&sw=agent-n1&vwa=1
To ensure that the worker is disabled wait for the redirect to the worker status page, and look in the 'Act' field for the sub worker, 'agent-n1'
To enable the 'agent-n1' sub worker use this url:
server-name/jkmanager/?cmd=update&w=agent-lb&sw=agent-n1&vwa=0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With