sergey-safarov opened a new issue, #286:
URL: https://github.com/apache/couchdb-docker/issues/286
When CouchDB used in container environment (AWS EKS/Fargate) for save
shutdown required signal to load-balancer to move load to the other nodes.
This can be done using curl request like
```sh
curl -X PUT \
-H "Content-type: application/json" \
-u admin:pass \
http://127.0.0.1:5984/_node/couchdb@${NODENAME}/_config/couchdb/maintenance_mode
\
-d '"nolb"'
```
But here need to be passed administrator login and password.
It will be fine to place containerized CouchDB node into maintenance mode
using USR singal or using socket on the filesystem.
Here is script which ready for K8s environment. Please package like
`/preStop.sh`.
```sh
#1/bin/sh
set -o errexit -o nounset -o pipefail
MAINTENANCE_MODE=${MAINTENANCE_MODE:-"nolb"}
NODENAME=${NODENAME:-"localhost.localdomain"}
COUCHDB_ERLANG_COOKIE=${COUCHDB_ERLANG_COOKIE:-"monster"}
LB_GRACE_PERIOD=${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
```
Additional info at
https://github.com/apache/couchdb/issues/5844
--
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]