#!/bin/bash

EUREKA_URL="$EUREKA_DEFAULT_ZONE""apps/$SERVER_NAME/$HOSTNAME:$SERVER_NAME:$SERVER_PORT/status?value=OUT_OF_SERVICE"
echo "Setting service status to OUT_OF_SERVICE at $EUREKA_URL"
RESULT=$(curl -X PUT $EUREKA_URL -w "%{http_code}" -o /dev/null)
if [ "$RESULT" -eq 200 ]; then
    echo "Service status set to OUT_OF_SERVICE successfully"
else
    echo "Failed to set service status. HTTP code: $RESULT"
    exit 1
fi

sleep 20

SHUTDOWN_URL="http://localhost:$SERVER_MANAGEMENT_PORT/actuator/shutdown"
echo "Shutting down service at $SHUTDOWN_URL"
RESULT=$(curl -X POST $SHUTDOWN_URL -w "%{http_code}" -o /dev/null)
if [ "$RESULT" -eq 200 ]; then
    echo "Service shut down successfully"
else
    echo "Failed to shut down service. HTTP code: $RESULT"
    exit 1
fi