Modify SM ETCD health check

This change is done to check etcd health,
through client url endpoint instead of systemctl.

Closes-Bug: 1930456
Signed-off-by: Jose Infanzon <jose.infanzon@windriver.com>
Change-Id: I8321fec80c1d4d80edb7af27c68c2ff1311c8b31
This commit is contained in:
Jose Infanzon 2021-06-01 16:10:09 -03:00
parent 3f1484556b
commit aa9885f422
2 changed files with 24 additions and 3 deletions

View File

@ -20,11 +20,31 @@ DESC="ETCD highly-available key value database"
SERVICE="etcd.service"
PIDFILE="/var/run/etcd.pid"
UPGRADE_SWACT_FILE="/opt/etcd/.upgrade_etcd"
ETCD_CONFIG_FILE="/etc/etcd/etcd.conf"
if [ ! -f "$ETCD_CONFIG_FILE" ]; then
logger "$ETCD_CONFIG_FILE: file does not exist"
exit 1
fi
IFS=', ' read -r -a URLS <<< $(awk -F '=' '/^ETCD_LISTEN_CLIENT_URLS/ {print $2}' ${ETCD_CONFIG_FILE} | tr -d '"')
if [ ${#URLS[@]} -le 0 ]; then
logger "$0: ETCD_LISTEN_CLIENT_URLS not configured"
exit 1
fi
ETCD_LISTEN_CLIENT_URL="${URLS[-1]}"
status()
{
if [ "`systemctl is-active etcd.service`" = "active" ]; then
if [[ $ETCD_LISTEN_CLIENT_URL =~ "https" ]]; then
etcd_health="$(etcdctl --ca-file /etc/etcd/ca.crt -cert-file /etc/etcd/etcd-server.crt --key-file /etc/etcd/etcd-server.key --endpoints="$ETCD_LISTEN_CLIENT_URL" cluster-health 2>&1 | head -n 1)"
else
etcd_health="$(etcdctl --endpoints="$ETCD_LISTEN_CLIENT_URL" cluster-health 2>&1 | head -n 1)"
fi
if [[ $etcd_health =~ "is healthy" ]]; then
RETVAL=0
echo "$DESC is running"
return
@ -34,6 +54,7 @@ status()
fi
}
start()
{
if [ -e $PIDFILE ]; then

View File

@ -57,10 +57,10 @@ class platform::etcd::init (
$key_file = '/etc/etcd/etcd-server.key'
$trusted_ca_file = '/etc/etcd/ca.crt'
if $bind_address_version == $::platform::params::ipv6 {
$client_url = "https://[${bind_address}]:${port}"
$client_url = "https://[${bind_address}]:${port},https://[127.0.0.1]:${port}"
}
else {
$client_url = "https://${bind_address}:${port}"
$client_url = "https://${bind_address}:${port},https://127.0.0.1:${port}"
}
}
else {