2017-08-31 17:22:33 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
RETRIES="{{ handler_health_rgw_check_retries }}"
|
|
|
|
DELAY="{{ handler_health_rgw_check_delay }}"
|
2021-03-03 22:43:50 +08:00
|
|
|
HOST_NAME="{{ ansible_facts['hostname'] }}"
|
2020-03-13 00:06:55 +08:00
|
|
|
RGW_NUMS={{ rgw_instances | length | int }}
|
2019-06-19 20:59:15 +08:00
|
|
|
RGW_FRONTEND_SSL_CERT={{ radosgw_frontend_ssl_certificate }}
|
|
|
|
if [ -n "$RGW_FRONTEND_SSL_CERT" ]; then
|
|
|
|
RGW_PROTOCOL=https
|
|
|
|
else
|
|
|
|
RGW_PROTOCOL=http
|
|
|
|
fi
|
2020-03-13 00:06:55 +08:00
|
|
|
INSTANCES_NAME=({% for i in rgw_instances %}{{ i.instance_name }} {% endfor %})
|
|
|
|
RGW_IPS=({% for i in rgw_instances %}{{ i.radosgw_address }} {% endfor %})
|
|
|
|
RGW_PORTS=({% for i in rgw_instances %}{{ i.radosgw_frontend_port }} {% endfor %})
|
2018-11-09 08:56:57 +08:00
|
|
|
declare -a DOCKER_EXECS
|
2020-03-13 00:06:55 +08:00
|
|
|
declare -a SOCKET_PREFIX
|
2018-11-09 08:56:57 +08:00
|
|
|
for ((i=0; i<${RGW_NUMS}; i++)); do
|
2020-03-13 00:06:55 +08:00
|
|
|
SOCKET_PREFIX[i]="/var/run/ceph/{{ cluster }}-client.rgw.${HOST_NAME}.${INSTANCES_NAME[i]}"
|
2018-11-09 08:56:57 +08:00
|
|
|
DOCKER_EXECS[i]=""
|
2019-05-08 04:33:21 +08:00
|
|
|
{% if containerized_deployment | bool %}
|
2020-03-13 00:06:55 +08:00
|
|
|
DOCKER_EXECS[i]="{{ container_binary }} exec ceph-rgw-${HOST_NAME}-${INSTANCES_NAME[i]}"
|
2017-09-28 00:22:15 +08:00
|
|
|
{% endif %}
|
2018-11-09 08:56:57 +08:00
|
|
|
done
|
2017-08-31 17:22:33 +08:00
|
|
|
|
2018-11-09 08:56:57 +08:00
|
|
|
check_socket() {
|
|
|
|
local i=$1
|
|
|
|
local succ=0
|
|
|
|
local count=10
|
|
|
|
# Wait and ensure the socket exists after restarting the daemon
|
|
|
|
while [ $count -ne 0 ]; do
|
2020-03-13 00:06:55 +08:00
|
|
|
SOCKET=$(grep ${SOCKET_PREFIX[i]} /proc/net/unix | awk '{ print $8 }')
|
2019-08-06 23:41:02 +08:00
|
|
|
if [ -n "${SOCKET}" ]; then
|
|
|
|
${DOCKER_EXECS[i]} test -S ${SOCKET} && succ=$((succ+1)) && break
|
|
|
|
fi
|
2018-11-09 08:56:57 +08:00
|
|
|
sleep $DELAY
|
|
|
|
let count=count-1
|
|
|
|
done
|
|
|
|
if [ $succ -ne 1 ]; then
|
2019-08-06 23:41:02 +08:00
|
|
|
echo "Socket file ${SOCKET} could not be found, which means Rados Gateway is not running. Showing ceph-rgw unit logs now:"
|
2020-03-13 00:06:55 +08:00
|
|
|
journalctl -u ceph-radosgw@rgw.${HOST_NAME}.${INSTANCES_NAME[i]}
|
2018-11-09 08:56:57 +08:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-08-31 17:22:33 +08:00
|
|
|
check_for_curl_or_wget() {
|
2018-11-09 08:56:57 +08:00
|
|
|
local i=$1
|
2024-03-13 06:42:05 +08:00
|
|
|
url="$RGW_PROTOCOL://${RGW_IPS[i]}:${RGW_PORTS[i]}"
|
2018-11-09 08:56:57 +08:00
|
|
|
if ${DOCKER_EXECS[i]} command -v wget &>/dev/null; then
|
2024-03-13 06:42:05 +08:00
|
|
|
rgw_test_result=$(${DOCKER_EXECS[i]} wget --no-check-certificate --tries 1 --quiet --server-response --spider -O /dev/null 2>&1 $url | awk 'NR==1{print $2}')
|
2018-11-09 08:56:57 +08:00
|
|
|
elif ${DOCKER_EXECS[i]} command -v curl &>/dev/null; then
|
2024-03-13 06:42:05 +08:00
|
|
|
rgw_test_result=$(${DOCKER_EXECS[i]} curl {{ '-g' if ip_version == 'ipv6' else '' }} -k -w "%{http_code}" --silent --output /dev/null $url)
|
2017-08-31 17:22:33 +08:00
|
|
|
else
|
2019-08-20 17:47:48 +08:00
|
|
|
echo "It seems that neither curl nor wget are available on your system."
|
2017-08-31 17:22:33 +08:00
|
|
|
echo "Cannot test rgw connection."
|
2024-03-13 06:42:05 +08:00
|
|
|
rgw_test_result=0
|
2017-08-31 17:22:33 +08:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
check_rest() {
|
2018-11-09 08:56:57 +08:00
|
|
|
local i=$1
|
|
|
|
local succ=0
|
2017-08-31 17:22:33 +08:00
|
|
|
while [ $RETRIES -ne 0 ]; do
|
2024-03-13 06:42:05 +08:00
|
|
|
check_for_curl_or_wget ${i}
|
2024-03-30 02:57:36 +08:00
|
|
|
if [ $rgw_test_result -eq 200 ] || [ $rgw_test_result -eq 404 ] || [ $rgw_test_result -eq 405 ]; then
|
2024-03-13 06:42:05 +08:00
|
|
|
succ=$((succ+1))
|
|
|
|
break
|
|
|
|
fi
|
2017-08-31 17:22:33 +08:00
|
|
|
sleep $DELAY
|
|
|
|
let RETRIES=RETRIES-1
|
|
|
|
done
|
2018-11-09 08:56:57 +08:00
|
|
|
if [ $succ -ne 1 ]; then
|
|
|
|
# If we reach this point, it means there is a problem with the connection to rgw
|
2020-03-13 00:06:55 +08:00
|
|
|
echo "Error connecting locally to Rados Gateway service: $RGW_PROTOCOL://${RGW_IPS[i]}:${RGW_PORTS[i]}"
|
2018-11-09 08:56:57 +08:00
|
|
|
exit 1
|
|
|
|
fi
|
2017-08-31 17:22:33 +08:00
|
|
|
}
|
|
|
|
|
2018-11-09 08:56:57 +08:00
|
|
|
for ((i=0; i<${RGW_NUMS}; i++)); do
|
2019-05-08 04:33:21 +08:00
|
|
|
# First, restart the daemon
|
2024-02-16 21:58:10 +08:00
|
|
|
|
|
|
|
# Check if systemd unit exists
|
2024-02-17 22:21:24 +08:00
|
|
|
# This is needed for new instances as the restart might trigger before the deployment
|
2024-02-16 21:58:10 +08:00
|
|
|
if systemctl list-units --full --all | grep -q "ceph-radosgw@rgw.${HOST_NAME}.${INSTANCES_NAME[i]}"; then
|
|
|
|
systemctl restart ceph-radosgw@rgw.${HOST_NAME}.${INSTANCES_NAME[i]}
|
|
|
|
else
|
|
|
|
echo "Systemd unit ceph-radosgw@rgw.${HOST_NAME}.${INSTANCES_NAME[i]} does not exist."
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2019-05-08 04:33:21 +08:00
|
|
|
# Check socket files
|
2018-11-09 08:56:57 +08:00
|
|
|
check_socket ${i}
|
2019-05-08 04:33:21 +08:00
|
|
|
# Check rest
|
2018-11-09 08:56:57 +08:00
|
|
|
check_rest ${i}
|
2017-08-31 17:22:33 +08:00
|
|
|
done
|