2017-08-31 17:22:33 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
RETRIES="{{ handler_health_rgw_check_retries }}"
|
|
|
|
DELAY="{{ handler_health_rgw_check_delay }}"
|
2018-11-09 08:56:57 +08:00
|
|
|
HOST_NAME="{{ ansible_hostname }}"
|
|
|
|
RGW_NUMS={{ radosgw_num_instances }}
|
|
|
|
RGW_BASE_PORT={{ radosgw_frontend_port }}
|
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
|
2018-11-09 08:56:57 +08:00
|
|
|
declare -a DOCKER_EXECS
|
|
|
|
for ((i=0; i<${RGW_NUMS}; i++)); do
|
|
|
|
DOCKER_EXECS[i]=""
|
2019-05-08 04:33:21 +08:00
|
|
|
{% if containerized_deployment | bool %}
|
2018-11-09 08:56:57 +08:00
|
|
|
CONTAINER_NAME="ceph-rgw-${HOST_NAME}-rgw${i}"
|
|
|
|
DOCKER_EXECS[i]="{{ container_binary }} exec ${CONTAINER_NAME}"
|
2017-09-28 00:22:15 +08:00
|
|
|
{% endif %}
|
2018-11-09 08:56:57 +08:00
|
|
|
done
|
|
|
|
declare -a SOCKETS
|
2018-10-03 22:09:33 +08:00
|
|
|
RGW_IP={{ hostvars[inventory_hostname]['_radosgw_address'] }}
|
2019-07-03 23:26:42 +08:00
|
|
|
SOCKET_PREFIX="/var/run/ceph/{{ cluster }}-client.rgw.${HOST_NAME}.rgw"
|
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
|
2019-05-08 04:33:21 +08:00
|
|
|
${DOCKER_EXECS[i]} test -S ${SOCKET_PREFIX}${i}.*.*.asok && SOCKETS[i]=$(stat --printf=%n ${SOCKET_PREFIX}${i}.*.*.asok)
|
2018-11-09 08:56:57 +08:00
|
|
|
${DOCKER_EXECS[i]} test -S ${SOCKETS[i]} && succ=$((succ+1)) && break
|
|
|
|
sleep $DELAY
|
|
|
|
let count=count-1
|
|
|
|
done
|
|
|
|
if [ $succ -ne 1 ]; then
|
|
|
|
echo "Socket file ${SOCKETS[i]} could not be found, which means Rados Gateway is not running. Showing ceph-rgw unit logs now:"
|
|
|
|
journalctl -u ceph-radosgw@rgw.${HOST_NAME}.rgw${i}
|
|
|
|
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
|
|
|
|
if ${DOCKER_EXECS[i]} command -v wget &>/dev/null; then
|
2019-05-08 04:33:21 +08:00
|
|
|
rgw_test_command="wget --tries 1 --quiet -O /dev/null"
|
2018-11-09 08:56:57 +08:00
|
|
|
elif ${DOCKER_EXECS[i]} command -v curl &>/dev/null; then
|
2017-08-31 17:22:33 +08:00
|
|
|
rgw_test_command="curl --fail --silent --output /dev/null"
|
|
|
|
else
|
|
|
|
echo "It seems that neither curl or wget are available on your system."
|
|
|
|
echo "Cannot test rgw connection."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
check_rest() {
|
2018-11-09 08:56:57 +08:00
|
|
|
local i=$1
|
|
|
|
check_for_curl_or_wget ${i}
|
|
|
|
local succ=0
|
2017-08-31 17:22:33 +08:00
|
|
|
while [ $RETRIES -ne 0 ]; do
|
2019-05-08 04:33:21 +08:00
|
|
|
${DOCKER_EXECS[i]} $rgw_test_command $RGW_PROTOCOL://$RGW_IP:$((RGW_BASE_PORT+i)) && succ=$((succ+1)) && break
|
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
|
2019-05-08 04:33:21 +08:00
|
|
|
echo "Error connecting locally to Rados Gateway service: $RGW_PROTOCOL://$RGW_IP:$((RGW_BASE_PORT+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
|
|
|
SOCKETS[i]="EMPTY_SOCKET"
|
|
|
|
# First, restart the daemon
|
2018-11-09 08:56:57 +08:00
|
|
|
systemctl restart ceph-radosgw@rgw.${HOST_NAME}.rgw${i}
|
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
|