willholley commented on issue #5844:
URL: https://github.com/apache/couchdb/issues/5844#issuecomment-3743838995

   For safe shutdown, you could use a 
[preStop](https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/)
 hook. We use this to trigger a script similar to (so note the below is not 
tested!):
   
   ```bash
   #!/bin/bash
   set -e
   
   # Put node into MM until restart (do not persist).
   # This removes the pod from the load balancer backends.
   echo "Begin pre-stop."
   echo "Setting maintenance mode."
   echo 'config:set("couchdb","maintenance_mode","true",false).' | erl_call -e 
   
   # Loop forever or until connections drain completely
   # Kubernetes will send a SIGKILL after terminationGracePeriodSeconds (set to 
10 minutes)
   while true; do
       # sleep first to allow LB to drain connections
       sleep 10
   
       # stop any in-flight _changes requests
       echo "Terminating _changes requests."
       echo 'fabric end_changes().' | erl_call -e
   
       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
   ```


-- 
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