From c7c5d2bf8d7e33e14ca3c12662177d0800d81552 Mon Sep 17 00:00:00 2001 From: Justin Oros Date: Mon, 20 Apr 2026 22:26:28 -0700 Subject: [PATCH] setup-opds.sh: replace fixed sleep watchdog with retry loop that restarts dir2opds until books are visible inside container --- hub/setup-opds.sh | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/hub/setup-opds.sh b/hub/setup-opds.sh index 597ae82..498dcf5 100755 --- a/hub/setup-opds.sh +++ b/hub/setup-opds.sh @@ -311,21 +311,38 @@ header "Setting Up Mount Watchdog" WATCHDOG_SCRIPT="/usr/local/bin/opds-watchdog.sh" cat > "$WATCHDOG_SCRIPT" << EOF #!/usr/bin/env bash -BOOKS_PATH="${BOOKS_PATH}" SERVER_NAME="${OPDS_SERVER}" -if [ -d "\$BOOKS_PATH" ] && [ -z "\$(ls -A "\$BOOKS_PATH" 2>/dev/null)" ]; then +MAX_WAIT=300 +ELAPSED=0 +while [ \$ELAPSED -lt \$MAX_WAIT ]; do + COUNT=\$(docker exec "\$SERVER_NAME" ls /books 2>/dev/null | wc -l) + if [ "\$COUNT" -gt 0 ]; then + exit 0 + fi docker restart "\$SERVER_NAME" 2>/dev/null || true -fi + sleep 15 + ELAPSED=\$((ELAPSED + 15)) +done EOF chmod +x "$WATCHDOG_SCRIPT" -CRON_LINE="@reboot sleep 120 && $WATCHDOG_SCRIPT" +MOUNT_SCRIPT="/home/${HUB_USER}/mount-$(basename ${MOUNT_POINT:-grace}).sh" +cat > "$MOUNT_SCRIPT" << EOF +#!/usr/bin/env bash +sleep 90 +/usr/bin/rclone mount ${OPDS_SERVER}-remote: ${MOUNT_POINT:-/home/${HUB_USER}/mnt/grace} --config /home/${HUB_USER}/.config/rclone/rclone.conf --vfs-cache-mode writes --allow-other --allow-non-empty --daemon +EOF +chmod +x "$MOUNT_SCRIPT" +chown "$HUB_USER":"$HUB_USER" "$MOUNT_SCRIPT" + +CRON_LINE="@reboot $WATCHDOG_SCRIPT" EXISTING_ROOT_CRON=$(crontab -l 2>/dev/null || true) if ! echo "$EXISTING_ROOT_CRON" | grep -qF "opds-watchdog"; then { echo "$EXISTING_ROOT_CRON"; echo "$CRON_LINE"; } | crontab - - info "Watchdog crontab entry added — restarts $OPDS_SERVER if mount is empty on boot." + info "Watchdog crontab entry added — restarts $OPDS_SERVER until books are visible." else - info "Watchdog crontab entry already exists." + crontab -l 2>/dev/null | grep -v "opds-watchdog" | { cat; echo "$CRON_LINE"; } | crontab - + info "Watchdog crontab entry updated." fi header "OPDS Setup Complete"