You are here: Home / Documentation / How To's / Script to restart ZEO clients and manipulate pound to prevent user-visible downtime

Script to restart ZEO clients and manipulate pound to prevent user-visible downtime

by nguyen — published Oct 04, 2011 10:50 AM, last modified Aug 16, 2016 10:50 AM
what we run in production here - /root/bin/restart-plone-4.0.2-zeo-clients.sh
#!/bin/sh                                                                                                                                                                         
COMMAND=$*
FASTMODE=0
[ "$COMMAND" = "help" -o "$COMMAND" = "-h" -o "$COMMAND" = "-u" ] && (echo "$0 -u | -h | help | fast"; echo ""; echo "    help: show this message"; echo "    fast: restart every\
thing urgently, without waiting for sessions"; echo "" ) && exit 0
[ "$COMMAND" = "fast" ] && FASTMODE=1
echo "FASTMODE = $FASTMODE"
[ $FASTMODE -eq 0 ] && echo "Running in slowpoke mode"
[ $FASTMODE -eq 1 ] && echo "Running in fast mode"

#                                                                                                                                                                                 
# show the before                                                                                                                                                                 
#                                                                                                                                                                                 

echo "BEFORE:"
/usr/local/sbin/poundctl -c /tmp/pound.ctl | awk '/1. http Listener 0.0.0.0:12000/ {ok=1} /2. http Listener 0.0.0.0:16000 a/ {ok=0} {if (ok == 1) {print $0}}'
/root/bin/show_plone_4.0.2_zeo_clients.sh

#                                                                                                                                                                                 
# now do client3                                                                                                                                                                  
#                                                                                                                                                                                 
echo "RESTARTING ZOPE CLIENT 3"
/opt/Plone-4.0.2-2/zeocluster/bin/client3 stop
/usr/sbin/logrotate /opt/Plone-4.0.2-2/zeocluster/logrotate-client3.conf && echo "Rotated log file OK"
/opt/Plone-4.0.2-2/zeocluster/bin/client3 start

#                                                                                                                                                                                 
# do client1                                                                                                                                                                      
#                                                                                                                                                                                 

echo "DISABLING POUND CLIENT 0"
/usr/local/sbin/poundctl -c /tmp/pound.ctl -b 1 0 0

# check if there are sessions                                                                                                                                                     
[ $FASTMODE -eq 0 ] && echo "CHECKING FOR POUND CLIENT 0 SESSIONS" && /usr/local/sbin/poundctl -c /tmp/pound.ctl | awk '/1. http Listener 0.0.0.0:12000/ {ok=1} /2. http Listener\
 0.0.0.0:16000 a/ {ok=0} {if (ok == 1) {print $0}}' | grep Session | grep ' 0$' && sleep 300

echo "RESTARTING ZOPE CLIENT 1"
/opt/Plone-4.0.2-2/zeocluster/bin/client1 stop
/usr/sbin/logrotate /opt/Plone-4.0.2-2/zeocluster/logrotate-client1.conf && echo "Rotated log file OK"
/opt/Plone-4.0.2-2/zeocluster/bin/client1 start

[ $FASTMODE -eq 0 ] && echo "SLEEPING FOR ONE MINUTE" && sleep 60

# prime it                                                                                                                                                                        
echo "PRIMING SOME OF THE SITES"
wget -O /tmp/throwaway http://localhost:12080/sites1/squirrel

echo "REENABLING POUND CLIENT 0"
/usr/local/sbin/poundctl -c /tmp/pound.ctl -B 1 0 0

#                                                                                                                                                                                 
# now do client2                                                                                                                                                                  
#                                                                                                                                                                                 

echo "DISABLING POUND CLIENT 1"
/usr/local/sbin/poundctl -c /tmp/pound.ctl -b 1 0 1

# check if there are sessions                                                                                                                                                     
[ $FASTMODE -eq 0 ] && echo "CHECKING FOR POUND CLIENT 1 SESSIONS" && /usr/local/sbin/poundctl -c /tmp/pound.ctl | awk '/1. http Listener 0.0.0.0:12000/ {ok=1} /2. http Listener\
 0.0.0.0:16000 a/ {ok=0} {if (ok == 1) {print $0}}' | grep Session | grep ' 1$' && sleep 300

echo "RESTARTING ZOPE CLIENT 2"
/opt/Plone-4.0.2-2/zeocluster/bin/client2 stop
/usr/sbin/logrotate /opt/Plone-4.0.2-2/zeocluster/logrotate-client2.conf && echo "Rotated log file OK"
/opt/Plone-4.0.2-2/zeocluster/bin/client2 start

[ $FASTMODE -eq 0 ] && echo "SLEEPING FOR ONE MINUTE" && sleep 60

# prime it                                                                                                                                                                        
echo "PRIMING SOME OF THE SITES"
wget -O /tmp/throwaway http://localhost:12081/sites1/squirrel

echo "REENABLING POUND CLIENT 1"
/usr/local/sbin/poundctl -c /tmp/pound.ctl -B 1 0 1

#                                                                                                                                                                                 
# show the after                                                                                                                                                                  
#                                                                                                                                                                                 
echo "AFTER:"
/usr/local/sbin/poundctl -c /tmp/pound.ctl | awk '/1. http Listener 0.0.0.0:12000/ {ok=1} /2. http Listener 0.0.0.0:16000 a/ {ok=0} {if (ok == 1) {print $0}}'
/root/bin/show_plone_4.0.2_zeo_clients.sh
 
Navigation