From 1c6e12e2d661ead7cfba38bf747865df581ccb9c Mon Sep 17 00:00:00 2001 From: Justin Oros Date: Mon, 20 Apr 2026 20:45:54 -0700 Subject: [PATCH] setup-opds.sh: add boot watchdog cron to restart dir2opds if books mount is empty after reboot --- hub/setup-opds.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/hub/setup-opds.sh b/hub/setup-opds.sh index 6de4ea3..c42ce55 100755 --- a/hub/setup-opds.sh +++ b/hub/setup-opds.sh @@ -306,6 +306,28 @@ fi sleep 3 docker logs caddy-opds --tail 5 2>/dev/null || true +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 + docker restart "\$SERVER_NAME" 2>/dev/null || true +fi +EOF +chmod +x "$WATCHDOG_SCRIPT" + +CRON_LINE="@reboot sleep 30 && $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." +else + info "Watchdog crontab entry already exists." +fi + header "OPDS Setup Complete" echo "" echo -e " OPDS URL: ${GREEN}https://${OPDS_DOMAIN}${NC}"