From 3908bc4df3356b5a9cf8ec46438ca05881202e5c Mon Sep 17 00:00:00 2001 From: ACX <8075870+acx10@users.noreply.github.com> Date: Mon, 23 Feb 2026 12:51:26 -0700 Subject: [PATCH] Fix app crash on startup when /bookdrop volume is not mounted (#2873) --- Dockerfile | 3 +- .../bookdrop/BookdropMonitoringService.java | 42 ++++++++++++------- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7f24ba74e..a45739992 100644 --- a/Dockerfile +++ b/Dockerfile @@ -56,7 +56,8 @@ LABEL org.opencontainers.image.title="BookLore" \ ENV JAVA_TOOL_OPTIONS="-XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:+UseStringDeduplication -XX:+UseContainerSupport -XX:+UseCompactObjectHeaders -XX:MaxRAMPercentage=75.0" -RUN apk update && apk add --no-cache su-exec +RUN apk update && apk add --no-cache su-exec && \ + mkdir -p /bookdrop COPY entrypoint.sh /usr/local/bin/entrypoint.sh RUN chmod +x /usr/local/bin/entrypoint.sh diff --git a/booklore-api/src/main/java/org/booklore/service/bookdrop/BookdropMonitoringService.java b/booklore-api/src/main/java/org/booklore/service/bookdrop/BookdropMonitoringService.java index c74fdc339..e1d4187ca 100644 --- a/booklore-api/src/main/java/org/booklore/service/bookdrop/BookdropMonitoringService.java +++ b/booklore-api/src/main/java/org/booklore/service/bookdrop/BookdropMonitoringService.java @@ -30,6 +30,7 @@ public class BookdropMonitoringService { private volatile boolean running; private WatchKey watchKey; private volatile boolean paused; + private volatile boolean disabled; public BookdropMonitoringService( AppProperties appProperties, @@ -42,29 +43,36 @@ public class BookdropMonitoringService { } @PostConstruct - public void start() throws IOException { + public void start() { bookdrop = Path.of(appProperties.getBookdropFolder()); if (Files.notExists(bookdrop)) { try { Files.createDirectories(bookdrop); log.info("Created missing bookdrop folder: {}", bookdrop); } catch (IOException e) { - log.error("Failed to create bookdrop folder: {}", bookdrop, e); - throw e; + log.warn("Bookdrop folder is not available at '{}'. Bookdrop monitoring is disabled. " + + "Mount a volume at this path to enable it.", bookdrop); + this.disabled = true; + return; } } - log.info("Starting bookdrop folder monitor: {}", bookdrop); - this.watchService = FileSystems.getDefault().newWatchService(); - this.watchKey = bookdrop.register(watchService, - StandardWatchEventKinds.ENTRY_CREATE, - StandardWatchEventKinds.ENTRY_DELETE); - this.running = true; - this.paused = false; - this.watchThread = new Thread(this::processEvents, "BookdropFolderWatcher"); - this.watchThread.setDaemon(true); - this.watchThread.start(); - scanExistingBookdropFiles(); + try { + log.info("Starting bookdrop folder monitor: {}", bookdrop); + this.watchService = FileSystems.getDefault().newWatchService(); + this.watchKey = bookdrop.register(watchService, + StandardWatchEventKinds.ENTRY_CREATE, + StandardWatchEventKinds.ENTRY_DELETE); + this.running = true; + this.paused = false; + this.watchThread = new Thread(this::processEvents, "BookdropFolderWatcher"); + this.watchThread.setDaemon(true); + this.watchThread.start(); + scanExistingBookdropFiles(); + } catch (IOException e) { + log.warn("Failed to start bookdrop folder monitor. Bookdrop monitoring is disabled.", e); + this.disabled = true; + } } @PreDestroy @@ -84,6 +92,7 @@ public class BookdropMonitoringService { } public synchronized void pauseMonitoring() { + if (disabled) return; if (!paused) { if (watchKey != null) { watchKey.cancel(); @@ -97,6 +106,7 @@ public class BookdropMonitoringService { } public synchronized void resumeMonitoring() { + if (disabled) return; if (paused) { try { watchKey = bookdrop.register(watchService, @@ -190,6 +200,10 @@ public class BookdropMonitoringService { } public void rescanBookdropFolder() { + if (disabled) { + log.warn("Bookdrop monitoring is disabled. Skipping rescan."); + return; + } log.info("Rescan of Bookdrop folder triggered."); scanExistingBookdropFiles(); }