From dadca1fb7ab75219e7e1203553f7d02f6b5b5eec Mon Sep 17 00:00:00 2001 From: renxb Date: Sat, 19 Oct 2024 13:44:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=92=8Cdaemon=E7=9A=84?= =?UTF-8?q?=E5=90=AF=E5=8A=A8=E7=8A=B6=E6=80=81=E5=85=B1=E4=BA=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/iec/edp/caf/CAFBootstrap.java | 38 ++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/caf-bootstrap/src/main/java/io/iec/edp/caf/CAFBootstrap.java b/caf-bootstrap/src/main/java/io/iec/edp/caf/CAFBootstrap.java index 6b9f7684..5778c493 100644 --- a/caf-bootstrap/src/main/java/io/iec/edp/caf/CAFBootstrap.java +++ b/caf-bootstrap/src/main/java/io/iec/edp/caf/CAFBootstrap.java @@ -19,6 +19,7 @@ package io.iec.edp.caf; import io.iec.edp.caf.autoconfigure.EnvironmentPreparedConfiguration; import io.iec.edp.caf.autoconfigure.PackageScanConfiguration; +import io.iec.edp.caf.common.JSONSerializer; import io.iec.edp.caf.commons.event.StartupCompletedEvent; import io.iec.edp.caf.commons.event.StartupCompletedTask; import io.iec.edp.caf.commons.runtime.CafEnvironment; @@ -43,6 +44,11 @@ import org.springframework.core.Ordered; import org.springframework.lang.NonNull; import java.io.File; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.HashMap; import java.util.Map; @@ -77,23 +83,45 @@ public class CAFBootstrap { AppManager.enableAppManager(Thread.currentThread()); } //启动程序 - context = springApplication.run(args); - beanFactory = context.getBeanFactory(); - //输出启动日志 StartupInfoLogger.logStarted(beanFactory); - //设置临时目录 setTempDir(); - + recordDuStartInfo(); //触发事件 StartupEventPublisher eventPublisher = beanFactory.getBean(StartupEventPublisher.class); eventPublisher.onStartupCompleted(new StartupCompletedEvent(new StartupCompletedTask())); //todo 兼容老的启动后事件 eventPublisher.onStartupCompleted(new io.iec.edp.caf.boot.event.startup.StartupCompletedEvent(new StartupCompletedTask())); } + private static void recordDuStartInfo() { + var duName = System.getProperty("deployment-unit.name"); + if (duName != null && duName.length() > 0) { + String serverPath = CafEnvironment.getBasePath(); + + Map map = new HashMap(); + if (duName != null && duName.length() > 0) { + map.put(duName, "true"); + } + String json = JSONSerializer.serialize(map); + Path jsonFilePath = Paths.get(serverPath, new String[] { "logs", duName, "start.json" }); + + try { + if (!Files.exists(jsonFilePath)) { + + if (!Files.exists(jsonFilePath.getParent())) { + Files.createDirectories(jsonFilePath.getParent()); + } + Files.createFile(jsonFilePath); + } + Files.write(jsonFilePath, json.getBytes(StandardCharsets.UTF_8)); + } catch (IOException e) { + log.error("Writing file error:", e); + } + } + } @Bean @ConditionalOnProperty("caf-boot.server.allow-bean-initialization-time-tracking") -- Gitee