From 8bf19b134886229815616502af97a42170c108a1 Mon Sep 17 00:00:00 2001 From: Pedro Tavares de Carvalho Date: Tue, 1 Oct 2024 19:37:26 -0300 Subject: [PATCH] ENG-14432: Unregisters disabled services from local registry (#28) * unregisters services * adds condition * other fixes * removes unnecessary configuration * changes when to clean up registry * removes prefix * adds redirection * removes storage manager as well * adds warning instead of failing * redirects stdout * ignore error --- install-linux.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/install-linux.sh b/install-linux.sh index b2940fc..28130cc 100755 --- a/install-linux.sh +++ b/install-linux.sh @@ -5,6 +5,9 @@ CYRAL_CONTROL_PLANE_GRPC_PORT=443 CYRAL_STORAGE_MANAGER_PORT=8090 CYRAL_STORAGE_MANAGER_IGNORED_CONFIGS="storage-manager log-shipper" CYRAL_STORAGE_MANAGER_PROXY_ENABLED="${CYRAL_STORAGE_MANAGER_PROXY_ENABLED:-true}" + +CYRAL_REGISTRY_DATABASE="/etc/cyral/conf.d/sidecar.db" +CYRAL_REGISTRY_BUCKET="service-registry" NL=$'\n' get_os_type() { @@ -373,6 +376,23 @@ disable_unsupported_services() { fi } +cleanup_local_registry() { + if command -v /opt/cyral/bin/cyral-local-discovery-cli &>/dev/null; then + echo "Cleaning up local registry" + readarray -t WIRES < <(find /etc/cyral/ -type d -name "*-wire" -printf "%f\n") + wires_to_disable=$(for wire in "${WIRES[@]}"; do if [[ ! "$CYRAL_REPOSITORIES_SUPPORTED" =~ $(echo "$wire" | cut -d- -f2) ]]; then echo -n "$wire "; fi; done) + for wire in "${WIRES[@]}"; do + if [[ -n "$wires_to_disable" ]] && [[ " ${wires_to_disable} " == *" ${wire} "* ]]; then + /opt/cyral/bin/cyral-local-discovery-cli unregister "${wire#cyral-}" --db "$CYRAL_REGISTRY_DATABASE" --bucket "$CYRAL_REGISTRY_BUCKET" + fi + done + + if [[ "$CYRAL_STORAGE_MANAGER_PROXY_ENABLED" != "true" ]]; then + /opt/cyral/bin/cyral-local-discovery-cli unregister "storage-proxy" --db "$CYRAL_REGISTRY_DATABASE" --bucket "$CYRAL_REGISTRY_BUCKET" 2>/dev/null || true + fi + fi +} + # After performing everything we need to restart the cyral services restart_services() { # We need to reload any of our changes to the systemd files before restarting @@ -390,6 +410,7 @@ do_post_install() { update_config_files sleep 3 # some os's (ubuntu) seem to have a problem if this is too quick restart_services + cleanup_local_registry } get_argument_value() {