Skip to content

Commit

Permalink
chron: 默认开启文件监控
Browse files Browse the repository at this point in the history
  • Loading branch information
jamebal committed May 8, 2024
1 parent 065e916 commit 6baa3e9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
FROM jmal/jdk17_ffmpeg:latest

ARG VERSION

ENV MONGODB_URI "mongodb://mongo:27017/jmalcloud"
ENV RUN_ENVIRONMENT prod

ARG VERSION
ENV FILE_MONITOR true
ENV FILE_ROOT_DIR /jmalcloud/files

ADD target/clouddisk-${VERSION}.jar /usr/local/

Expand All @@ -22,4 +25,4 @@ ENV DOCKER_DEFAULT_PLATFORM=linux/amd64,linux/arm64

EXPOSE 8088

CMD java -Dfile.encoding=UTF-8 -Dloader.path=/usr/local/clouddisk-lib -jar -Xms50m -Xmx512m /usr/local/clouddisk-$VERSION.jar --spring.profiles.active=$RUN_ENVIRONMENT --spring.data.mongodb.uri=$MONGODB_URI --file.monitor=false --file.rootDir=/jmalcloud/files --file.ip2region-db-path=/jmalcloud/ip2region.xdb
CMD java -Dfile.encoding=UTF-8 -Dloader.path=/usr/local/clouddisk-lib -jar -Xms50m -Xmx512m /usr/local/clouddisk-${VERSION}.jar --spring.profiles.active=${RUN_ENVIRONMENT} --spring.data.mongodb.uri=${MONGODB_URI} --file.monitor=${FILE_MONITOR} --file.rootDir=${FILE_ROOT_DIR} --file.ip2region-db-path=/jmalcloud/ip2region.xdb
7 changes: 5 additions & 2 deletions docker/jmalcloud-nvidia/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
FROM jmal/jdk17_ffmpeg_nvidia:latest

ARG VERSION

ENV MONGODB_URI "mongodb://mongo:27017/jmalcloud"
ENV RUN_ENVIRONMENT prod

ARG VERSION
ENV FILE_MONITOR true
ENV FILE_ROOT_DIR /jmalcloud/files

ADD target/clouddisk-${VERSION}.jar /usr/local/

Expand All @@ -22,4 +25,4 @@ ENV DOCKER_DEFAULT_PLATFORM=linux/amd64,linux/arm64

EXPOSE 8088

CMD java -Dfile.encoding=UTF-8 -Dloader.path=/usr/local/clouddisk-lib -jar -Xms50m -Xmx512m /usr/local/clouddisk-$VERSION.jar --spring.profiles.active=$RUN_ENVIRONMENT --spring.data.mongodb.uri=$MONGODB_URI --file.monitor=false --file.rootDir=/jmalcloud/files --file.ip2region-db-path=/jmalcloud/ip2region.xdb
CMD java -Dfile.encoding=UTF-8 -Dloader.path=/usr/local/clouddisk-lib -jar -Xms50m -Xmx512m /usr/local/clouddisk-${VERSION}.jar --spring.profiles.active=${RUN_ENVIRONMENT} --spring.data.mongodb.uri=${MONGODB_URI} --file.monitor=${FILE_MONITOR} --file.rootDir=${FILE_ROOT_DIR} --file.ip2region-db-path=/jmalcloud/ip2region.xdb
7 changes: 4 additions & 3 deletions src/main/java/com/jmal/clouddisk/listener/FileMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,14 @@ public void init() throws Exception {
// 轮询间隔(秒)
long interval = TimeUnit.SECONDS.toMillis(fileProperties.getTimeInterval());
FILTER_DIR_SET.add(fileProperties.getChunkFileDir());
FILTER_DIR_SET.add(fileProperties.getLuceneIndexDir());
newObserver();
//创建文件变化监听器
monitor = new FileAlterationMonitor(interval, observer);
// 开始监控
monitor.start();
isMonitor = true;
log.info("\r\n文件监控服务已开启:\r\n轮询间隔:{}秒\n监控目录:{}\n忽略目录:{}", fileProperties.getTimeInterval(), rootDir, rootDir + File.separator + fileProperties.getChunkFileDir());
log.info("\r\n文件监控服务已开启:\r\n轮询间隔:{}秒\n监控目录:{}\n忽略目录:{}", fileProperties.getTimeInterval(), rootDir, FILTER_DIR_SET);
}

private void newObserver() {
Expand All @@ -126,7 +127,7 @@ private void reloadObserver() {
try {
newObserver();
fastInterval();
log.info("reload FileMonitor, filterDir: {}", FILTER_DIR_SET);
log.info("reload FileMonitor, ignoreDir: {}", FILTER_DIR_SET);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
Expand Down Expand Up @@ -187,7 +188,7 @@ private void slowlyInterval() throws Exception {
monitor = null;
monitor = new FileAlterationMonitor(DateUnit.MINUTE.getMillis() * 30, observer);
monitor.start();
log.info("轮询间隔改为30分钟");
log.info("轮询间隔改为3分钟");
isMonitor = false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/file.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ file:
# lucene索引存储目录
luceneIndexDir: luceneIndex
# 是否开启文件监控, 默认关闭(开启会损耗性能), 开启的好处在于使用webDAV、FTP等修改文件会自动同步, 如果需要用webDAV建议开启
monitor: false
monitor: true
# 文件监控扫描时间间隔(秒)
timeInterval: 3
# FTP server 端口号
Expand Down

0 comments on commit 6baa3e9

Please sign in to comment.