ceph-ansible/roles/ceph-handler/templates/restart_rgw_daemon.sh.j2

90 lines
4.0 KiB
Django/Jinja

#!/bin/bash
RETRIES="{{ handler_health_rgw_check_retries }}"
DELAY="{{ handler_health_rgw_check_delay }}"
RGW_NAME="{{ ansible_hostname }}"
RGW_PORT="{{ radosgw_frontend_port }}"
{% if containerized_deployment %}
DOCKER_EXEC="docker exec ceph-rgw-{{ ansible_hostname }}"
{% endif %}
# Backward compatibility
$DOCKER_EXEC test -S /var/run/ceph/{{ cluster }}-client.rgw.{{ ansible_fqdn }}.asok && SOCKET=/var/run/ceph/{{ cluster }}-client.rgw.{{ ansible_fqdn }}.asok
$DOCKER_EXEC test -S /var/run/ceph/{{ cluster }}-client.rgw.{{ ansible_hostname }}.asok && SOCKET=/var/run/ceph/{{ cluster }}-client.rgw.{{ ansible_hostname }}.asok
{% if hostvars[inventory_hostname]['radosgw_address_block'] is defined and hostvars[inventory_hostname]['radosgw_address_block'] != 'subnet' %}
{% if ip_version == 'ipv4' %}
RGW_IP={{ hostvars[inventory_hostname]['ansible_all_' + ip_version + '_addresses'] | ipaddr(radosgw_address_block) | first }} \
{% elif ip_version == 'ipv6' %}
RGW_IP=[{{ hostvars[inventory_hostname]['ansible_all_' + ip_version + '_addresses'] | ipaddr(radosgw_address_block) | last }}] \
{% endif %}
{% elif radosgw_address_block is defined and radosgw_address_block != 'subnet' -%}
{% if ip_version == 'ipv4' %}
RGW_IP={{ hostvars[inventory_hostname]['ansible_all_' + ip_version + '_addresses'] | ipaddr(radosgw_address_block) | first }} \
{% elif ip_version == 'ipv6' %}
RGW_IP=[{{ hostvars[inventory_hostname]['ansible_all_' + ip_version + '_addresses'] | ipaddr(radosgw_address_block) | last }}] \
{% endif %}
{% elif hostvars[inventory_hostname]['radosgw_address'] is defined and hostvars[inventory_hostname]['radosgw_address'] != 'address' -%}
{% if ip_version == 'ipv4' %}
RGW_IP={{ hostvars[inventory_hostname]['radosgw_address'] }} \
{% elif ip_version == 'ipv6' %}
RGW_IP=[{{ hostvars[inventory_hostname]['radosgw_address'] }}] \
{% endif %}
{% elif radosgw_address is defined and radosgw_address != 'address' -%}
{% if ip_version == 'ipv4' %}
RGW_IP={{ radosgw_address }} \
{% elif ip_version == 'ipv6' %}
RGW_IP=[{{ radosgw_address }}] \
{% endif %}
{% elif hostvars[inventory_hostname]['radosgw_interface'] is defined -%}
{% set interface = 'ansible_' + (hostvars[inventory_hostname]['radosgw_interface'] | replace('-', '_')) %}
{% if ip_version == 'ipv4' %}
RGW_IP={{ hostvars[inventory_hostname][interface][ip_version]['address'] }} \
{% elif ip_version == 'ipv6' %}
RGW_IP=[{{ hostvars[inventory_hostname][interface][ip_version][0]['address'] }}] \
{% endif %}
{% else %}
{% set interface = 'ansible_' + (radosgw_interface | replace('-', '_')) %}
{% if ip_version == 'ipv4' %}
RGW_IP={{ hostvars[inventory_hostname][interface][ip_version]['address'] }} \
{% elif ip_version == 'ipv6' %}
RGW_IP=[{{ hostvars[inventory_hostname][interface][ip_version][0]['address'] }}] \
{% endif %}
{% endif %}
check_for_curl_or_wget() {
if $DOCKER_EXEC command -v wget &>/dev/null; then
rgw_test_command="wget --quiet"
elif $DOCKER_EXEC command -v curl &>/dev/null; then
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() {
check_for_curl_or_wget
while [ $RETRIES -ne 0 ]; do
test "$rgw_test_command http://$RGW_IP:$RGW_PORT" && exit 0
sleep $DELAY
let RETRIES=RETRIES-1
done
# If we reach this point, it means there is a problem with the connection to rgw
echo "Error connecting locally to Rados Gateway service: http://$rgw_listen"
exit 1
}
# First, restart the daemon
systemctl restart ceph-radosgw@rgw.${RGW_NAME}
COUNT=10
# Wait and ensure the socket exists after restarting the daemon
while [ $COUNT -ne 0 ]; do
$DOCKER_EXEC test -S $SOCKET && check_rest
sleep $DELAY
let COUNT=COUNT-1
done
echo "Socket file ${SOCKET} could not be found, which means Rados Gateway is not running. Showing ceph-rgw unit logs now:"
journalctl -u ceph-radosgw@rgw.${RGW_NAME}
exit 1