sergey-safarov commented on issue #5844:
URL: https://github.com/apache/couchdb/issues/5844#issuecomment-3751658174

   @willholley  i have modified your script
   ```sh
   #1/bin/sh
   
   set -o errexit -o nounset -o pipefail
   
   MAINTENANCE_MODE=nolb
   NODENAME=${NODENAME:-"localhost.localdomain"}
   COUCHDB_ERLANG_COOKIE=${COUCHDB_ERLANG_COOKIE:-"monster"}
   LB_GRACE_PERIOD=10 # seconds
   
   # if you need IPv6 support then you shoud export
   # ERL_FLAGS="-proto_dist inet6_tcp"
   
   code_maintenance_mode() {
   cat << EOF
   io:format("~p~n", [rpc:call('couchdb@${NODENAME}', config, set, 
["couchdb","maintenance_mode","${MAINTENANCE_MODE}",false])]), init:stop().
   EOF
   }
   
   code_fabric_end_changes() {
   cat << EOF
   io:format("~p~n", [rpc:call('couchdb@${NODENAME}', fabric, end_changes, 
[])]), init:stop().
   EOF
   }
   
   # Put node into MM until restart (do not persist).
   # This removes the pod from the load balancer backend
   
   echo "Begin pre-stop."
   echo -n "Setting maintenance mode: "
   
   erl \
     -setcookie ${COUCHDB_ERLANG_COOKIE} \
     -name pre_stop@${NODENAME} \
     -noshell \
     -eval "$(code_maintenance_mode)"
   
   
   while true; do
       # sleep first to allow LB to drain connections
       sleep ${LB_GRACE_PERIOD}
   
       # stop any in-flight _changes requests
       echo -n "Terminating _changes requests: "
       erl \
         -setcookie ${COUCHDB_ERLANG_COOKIE} \
         -name pre_stop@${NODENAME} \
         -noshell \
         -eval "$(code_fabric_end_changes)"
   
       connections=$(ss --no-header -nt state established "( sport = :5984 )"  
| wc -l)
       echo "Current connections on port 5984: $connections"
   
       if [ $connections -eq 0 ]; then
           echo "Connections dropped to 0. Exiting pre-stop."
           break
       fi
   done
   ```
   
   I think this can added into docker image as `/preStop.sh' and later called 
from k8s.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to