From 763c11f00cb295f8d9a5e7eee34fc566fd403c97 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Sat, 31 May 2025 05:45:34 +0200 Subject: [PATCH] Update 99-run.sh --- postgres_15/rootfs/etc/cont-init.d/99-run.sh | 25 +++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/postgres_15/rootfs/etc/cont-init.d/99-run.sh b/postgres_15/rootfs/etc/cont-init.d/99-run.sh index eb4c8f097..1ab4a239d 100755 --- a/postgres_15/rootfs/etc/cont-init.d/99-run.sh +++ b/postgres_15/rootfs/etc/cont-init.d/99-run.sh @@ -132,25 +132,38 @@ wait_for_postgres() { restart_immich_addons_if_flagged() { if [ -f "$RESTART_FLAG_FILE" ]; then bashio::log.warning "Detected pending Immich add-on restart flag. Restarting all running Immich add-ons..." - local addons slug found=0 - addons=$(curl -s -H "Authorization: Bearer $SUPERVISOR_TOKEN" http://supervisor/addons) + + local addons_json slug found=0 + + # Get the add-ons list, fail on HTTP errors, show errors if API call fails + addons_json=$(curl -fsSL -H "Authorization: Bearer $SUPERVISOR_TOKEN" http://supervisor/addons) || { + bashio::log.error "Supervisor API call failed or unauthorized: $addons_json" + rm -f "$RESTART_FLAG_FILE" + return 1 + } + if command -v jq >/dev/null; then - for slug in $(echo "$addons" | jq -r '.data.addons[] | select(.state=="started") | .slug'); do + # Use correct JSON path for modern Supervisor API + for slug in $(echo "$addons_json" | jq -r '.addons[] | select(.state=="started") | .slug'); do if [[ "$slug" == *immich* ]]; then bashio::log.info "Restarting addon $slug" - curl -s -X POST -H "Authorization: Bearer $SUPERVISOR_TOKEN" "http://supervisor/addons/$slug/restart" + curl -fsSL -X POST -H "Authorization: Bearer $SUPERVISOR_TOKEN" \ + "http://supervisor/addons/$slug/restart" found=1 fi done else - for slug in $(echo "$addons" | grep -o '"slug":"[^"]*"' | cut -d: -f2 | tr -d '"'); do + # Fallback: grep/cut for legacy environments, less robust + for slug in $(echo "$addons_json" | grep -o '"slug":"[^"]*"' | cut -d: -f2 | tr -d '"'); do if [[ "$slug" == *immich* ]]; then bashio::log.info "Restarting addon $slug" - curl -s -X POST -H "Authorization: Bearer $SUPERVISOR_TOKEN" "http://supervisor/addons/$slug/restart" + curl -fsSL -X POST -H "Authorization: Bearer $SUPERVISOR_TOKEN" \ + "http://supervisor/addons/$slug/restart" found=1 fi done fi + if [ "$found" -eq 0 ]; then bashio::log.info "No Immich-related addon found running." fi