diff --git a/plex32_update_check.sh b/plex32_update_check.sh index 8fd7a5f..abcfd6a 100644 --- a/plex32_update_check.sh +++ b/plex32_update_check.sh @@ -6,6 +6,10 @@ # Location: /usr/scripts/plex32/plex32_update_check.sh # ============================================================= +# Explicit PATH for root's cron environment (minimal default PATH +# under cron doesn't reliably match the interactive shell PATH). +export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + HOSTNAME="plex32" SMTP_SERVER="smtppro.zoho.com" SMTP_PORT="465" @@ -50,21 +54,46 @@ PLEX_FAILED=false PLEX_UPDATE_AVAILABLE=false PLEX_ERROR_HTML="" -PLEX_PULL_OUTPUT=$(docker pull lscr.io/linuxserver/plex:latest 2>&1) -PLEX_PULL_STATUS=$? +# lscr.io occasionally returns "error from registry: unauthorized" on the +# final manifest step of a large multi-layer pull, even after every layer +# downloaded successfully — a transient token/rate-limit issue on their end, +# not a credentials problem. Retry a few times before treating it as a real +# failure, since it usually resolves within one or two attempts. +PLEX_PULL_MAX_RETRIES=3 +PLEX_PULL_RETRY_DELAY=30 +plex_pull_attempt=1 +PLEX_PULL_STATUS=1 +PLEX_PULL_OUTPUT="" + +while [ $plex_pull_attempt -le $PLEX_PULL_MAX_RETRIES ]; do + PLEX_PULL_OUTPUT=$(docker pull lscr.io/linuxserver/plex:latest 2>&1) + PLEX_PULL_STATUS=$? + if [ $PLEX_PULL_STATUS -eq 0 ]; then + break + fi + echo "[WARN] docker pull attempt $plex_pull_attempt/$PLEX_PULL_MAX_RETRIES failed (exit $PLEX_PULL_STATUS)." + if [ $plex_pull_attempt -lt $PLEX_PULL_MAX_RETRIES ]; then + echo "[WARN] Retrying in ${PLEX_PULL_RETRY_DELAY}s..." + sleep $PLEX_PULL_RETRY_DELAY + fi + plex_pull_attempt=$((plex_pull_attempt + 1)) +done PLEX_IMAGE_VERSION=$(docker inspect lscr.io/linuxserver/plex:latest --format '{{index .Config.Labels "build_version"}}' 2>/dev/null || echo "unknown") CURRENT_IMAGE_DATE=$(docker inspect --format='{{.Created}}' lscr.io/linuxserver/plex:latest 2>/dev/null | cut -d'T' -f1) if [ $PLEX_PULL_STATUS -ne 0 ]; then PLEX_FAILED=true - PLEX_STATUS_TEXT="Check failed — see error detail below" - echo "[ERROR] docker pull exited $PLEX_PULL_STATUS. Full output:" + PLEX_STATUS_TEXT="Check failed after $PLEX_PULL_MAX_RETRIES attempts — see error detail below" + echo "[ERROR] docker pull failed after $PLEX_PULL_MAX_RETRIES attempts. Final output:" echo "$PLEX_PULL_OUTPUT" - PLEX_ERROR_HTML="
$(echo "$PLEX_PULL_OUTPUT" | sed 's/&/\&/g; s/\</g; s/>/\>/g')
$(echo "$PLEX_PULL_OUTPUT" | sed 's/&/\&/g; s/\</g; s/>/\>/g')