From fdd2fb3b388548fc20d1f7e1e0578466448b35ca Mon Sep 17 00:00:00 2001 From: Damien Ciabrini Date: Fri, 28 May 2021 00:25:25 +0200 Subject: [PATCH] Fix config parsing in memcached healthcheck When memcached is configured to listen on multiple IP, or is configured with TLS-e, make sure the healthcheck parses the right IP to connect to and its associated port. Change-Id: Ia0baf8501884d9ed2324938c9acbb30d1687cf27 Closes-Bug: #1929881 (cherry picked from commit 3f84495b8f8dc0a20148dfa8eaaa22d750ada39d) --- healthcheck/memcached | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/healthcheck/memcached b/healthcheck/memcached index 725367a0e..16b2d470e 100755 --- a/healthcheck/memcached +++ b/healthcheck/memcached @@ -1,7 +1,21 @@ #!/bin/bash . ${HEALTHCHECK_SCRIPTS:-/usr/share/openstack-tripleo-common/healthcheck}/common.sh -listen_addr=$(wrap_ipv6 $(awk 'match($0, /-l +([0-9a-fA-F\.\:]+) /, a) {print a[1]}' /etc/sysconfig/memcached)) +# if memcached has TLS enabled, look for a notls ip entry in the options +listen_addr=$(awk 'match($0, /notls:([0-9a-fA-F\.\:]+):11211[, ]/, a) {print a[1]}' /etc/sysconfig/memcached) -echo "version" | socat - TCP:$listen_addr:11211 1>/dev/null +if [ -z "$listen_addr" ]; then + # otherwise look for the first ip available among all the possible ones + # passed to the -l option + listen_addr=$(awk 'match($0, /-l +([0-9a-fA-F\.\:]+)[, ]/, a) {print a[1]}' /etc/sysconfig/memcached) + # get the configured memcached port or the default one + port=$(awk -F= '$1=="PORT" {gsub(/"/, "",$2); print $2}' /etc/sysconfig/memcached) + port=${port:-11211} +else + # with TLS-e, TripleO always exposes the notls IP on port 11211 + port=11211 +fi +listen_addr=$(wrap_ipv6 $listen_addr) + +echo "version" | socat - TCP:$listen_addr:$port 1>/dev/null exit $?