setup-opds.sh: add boot watchdog cron to restart dir2opds if books mount is empty after reboot

This commit is contained in:
Justin Oros
2026-04-20 20:45:54 -07:00
parent 40d24158b6
commit 1c6e12e2d6

View File

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