Update the script to get rid of timeout issue
This commit is contained in:
parent
293c07ed76
commit
1de45c32f1
1 changed files with 34 additions and 5 deletions
|
|
@ -6,6 +6,10 @@
|
||||||
# Location: /usr/scripts/plex32/plex32_update_check.sh
|
# 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"
|
HOSTNAME="plex32"
|
||||||
SMTP_SERVER="smtppro.zoho.com"
|
SMTP_SERVER="smtppro.zoho.com"
|
||||||
SMTP_PORT="465"
|
SMTP_PORT="465"
|
||||||
|
|
@ -50,21 +54,46 @@ PLEX_FAILED=false
|
||||||
PLEX_UPDATE_AVAILABLE=false
|
PLEX_UPDATE_AVAILABLE=false
|
||||||
PLEX_ERROR_HTML=""
|
PLEX_ERROR_HTML=""
|
||||||
|
|
||||||
|
# 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_OUTPUT=$(docker pull lscr.io/linuxserver/plex:latest 2>&1)
|
||||||
PLEX_PULL_STATUS=$?
|
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")
|
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)
|
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
|
if [ $PLEX_PULL_STATUS -ne 0 ]; then
|
||||||
PLEX_FAILED=true
|
PLEX_FAILED=true
|
||||||
PLEX_STATUS_TEXT="Check failed — see error detail below"
|
PLEX_STATUS_TEXT="Check failed after $PLEX_PULL_MAX_RETRIES attempts — see error detail below"
|
||||||
echo "[ERROR] docker pull exited $PLEX_PULL_STATUS. Full output:"
|
echo "[ERROR] docker pull failed after $PLEX_PULL_MAX_RETRIES attempts. Final output:"
|
||||||
echo "$PLEX_PULL_OUTPUT"
|
echo "$PLEX_PULL_OUTPUT"
|
||||||
PLEX_ERROR_HTML="<div style='margin-top:8px;padding:10px 14px;background:#fff1f2;border-left:4px solid #b91c1c;border-radius:4px;'><div style='font-size:11px;font-weight:700;color:#b91c1c;text-transform:uppercase;letter-spacing:.5px;margin-bottom:6px;'>⚠ Docker Pull Error (exit $PLEX_PULL_STATUS)</div><pre style='margin:0;font-family:monospace;font-size:12px;color:#7f1d1d;white-space:pre-wrap;'>$(echo "$PLEX_PULL_OUTPUT" | sed 's/&/\&/g; s/</\</g; s/>/\>/g')</pre></div>"
|
PLEX_ERROR_HTML="<div style='margin-top:8px;padding:10px 14px;background:#fff1f2;border-left:4px solid #b91c1c;border-radius:4px;'><div style='font-size:11px;font-weight:700;color:#b91c1c;text-transform:uppercase;letter-spacing:.5px;margin-bottom:6px;'>⚠ Docker Pull Error (exit $PLEX_PULL_STATUS, after $PLEX_PULL_MAX_RETRIES attempts)</div><pre style='margin:0;font-family:monospace;font-size:12px;color:#7f1d1d;white-space:pre-wrap;'>$(echo "$PLEX_PULL_OUTPUT" | sed 's/&/\&/g; s/</\</g; s/>/\>/g')</pre></div>"
|
||||||
elif echo "$PLEX_PULL_OUTPUT" | grep -q "Pull complete"; then
|
elif echo "$PLEX_PULL_OUTPUT" | grep -q "Pull complete"; then
|
||||||
PLEX_UPDATE_AVAILABLE=true
|
PLEX_UPDATE_AVAILABLE=true
|
||||||
PLEX_STATUS_TEXT="Update available — new image pulled"
|
PLEX_STATUS_TEXT="Update available — new image pulled"
|
||||||
|
if [ $plex_pull_attempt -gt 1 ]; then
|
||||||
|
PLEX_STATUS_TEXT="$PLEX_STATUS_TEXT (succeeded on retry, attempt $plex_pull_attempt)"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
PLEX_STATUS_TEXT="Up to date"
|
PLEX_STATUS_TEXT="Up to date"
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue