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}"