Fix app crash on startup when /bookdrop volume is not mounted (#2873)
This commit is contained in:
+2
-1
@@ -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"
|
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
|
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
|
||||||
RUN chmod +x /usr/local/bin/entrypoint.sh
|
RUN chmod +x /usr/local/bin/entrypoint.sh
|
||||||
|
|||||||
+28
-14
@@ -30,6 +30,7 @@ public class BookdropMonitoringService {
|
|||||||
private volatile boolean running;
|
private volatile boolean running;
|
||||||
private WatchKey watchKey;
|
private WatchKey watchKey;
|
||||||
private volatile boolean paused;
|
private volatile boolean paused;
|
||||||
|
private volatile boolean disabled;
|
||||||
|
|
||||||
public BookdropMonitoringService(
|
public BookdropMonitoringService(
|
||||||
AppProperties appProperties,
|
AppProperties appProperties,
|
||||||
@@ -42,29 +43,36 @@ public class BookdropMonitoringService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void start() throws IOException {
|
public void start() {
|
||||||
bookdrop = Path.of(appProperties.getBookdropFolder());
|
bookdrop = Path.of(appProperties.getBookdropFolder());
|
||||||
if (Files.notExists(bookdrop)) {
|
if (Files.notExists(bookdrop)) {
|
||||||
try {
|
try {
|
||||||
Files.createDirectories(bookdrop);
|
Files.createDirectories(bookdrop);
|
||||||
log.info("Created missing bookdrop folder: {}", bookdrop);
|
log.info("Created missing bookdrop folder: {}", bookdrop);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("Failed to create bookdrop folder: {}", bookdrop, e);
|
log.warn("Bookdrop folder is not available at '{}'. Bookdrop monitoring is disabled. " +
|
||||||
throw e;
|
"Mount a volume at this path to enable it.", bookdrop);
|
||||||
|
this.disabled = true;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.info("Starting bookdrop folder monitor: {}", bookdrop);
|
try {
|
||||||
this.watchService = FileSystems.getDefault().newWatchService();
|
log.info("Starting bookdrop folder monitor: {}", bookdrop);
|
||||||
this.watchKey = bookdrop.register(watchService,
|
this.watchService = FileSystems.getDefault().newWatchService();
|
||||||
StandardWatchEventKinds.ENTRY_CREATE,
|
this.watchKey = bookdrop.register(watchService,
|
||||||
StandardWatchEventKinds.ENTRY_DELETE);
|
StandardWatchEventKinds.ENTRY_CREATE,
|
||||||
this.running = true;
|
StandardWatchEventKinds.ENTRY_DELETE);
|
||||||
this.paused = false;
|
this.running = true;
|
||||||
this.watchThread = new Thread(this::processEvents, "BookdropFolderWatcher");
|
this.paused = false;
|
||||||
this.watchThread.setDaemon(true);
|
this.watchThread = new Thread(this::processEvents, "BookdropFolderWatcher");
|
||||||
this.watchThread.start();
|
this.watchThread.setDaemon(true);
|
||||||
scanExistingBookdropFiles();
|
this.watchThread.start();
|
||||||
|
scanExistingBookdropFiles();
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.warn("Failed to start bookdrop folder monitor. Bookdrop monitoring is disabled.", e);
|
||||||
|
this.disabled = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreDestroy
|
@PreDestroy
|
||||||
@@ -84,6 +92,7 @@ public class BookdropMonitoringService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void pauseMonitoring() {
|
public synchronized void pauseMonitoring() {
|
||||||
|
if (disabled) return;
|
||||||
if (!paused) {
|
if (!paused) {
|
||||||
if (watchKey != null) {
|
if (watchKey != null) {
|
||||||
watchKey.cancel();
|
watchKey.cancel();
|
||||||
@@ -97,6 +106,7 @@ public class BookdropMonitoringService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void resumeMonitoring() {
|
public synchronized void resumeMonitoring() {
|
||||||
|
if (disabled) return;
|
||||||
if (paused) {
|
if (paused) {
|
||||||
try {
|
try {
|
||||||
watchKey = bookdrop.register(watchService,
|
watchKey = bookdrop.register(watchService,
|
||||||
@@ -190,6 +200,10 @@ public class BookdropMonitoringService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void rescanBookdropFolder() {
|
public void rescanBookdropFolder() {
|
||||||
|
if (disabled) {
|
||||||
|
log.warn("Bookdrop monitoring is disabled. Skipping rescan.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
log.info("Rescan of Bookdrop folder triggered.");
|
log.info("Rescan of Bookdrop folder triggered.");
|
||||||
scanExistingBookdropFiles();
|
scanExistingBookdropFiles();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user