Browse Source

bin shell script create

shjung 9 months ago
parent
commit
3c6a296e80

+ 2 - 0
conf/rota-utic-client-trace.cfg

@@ -0,0 +1,2 @@
+#DUMP=L01,...
+DUMP=

+ 2 - 0
conf/rota-utic-server-trace.cfg

@@ -0,0 +1,2 @@
+#DUMP=L01,...
+DUMP=

+ 2 - 0
rota-utic-client/conf/rota-utic-client-trace.cfg

@@ -0,0 +1,2 @@
+#DUMP=L01,...
+DUMP=

+ 26 - 3
rota-utic-client/src/main/java/com/its/rota/utic/client/RotaUticClientApplication.java

@@ -8,18 +8,25 @@ import com.its.rota.utic.client.xnet.client.process.work.DataPacketProcess;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.DisposableBean;
 import org.springframework.beans.factory.InitializingBean;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.support.BeanDefinitionRegistry;
 import org.springframework.boot.Banner;
 import org.springframework.boot.CommandLineRunner;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.builder.SpringApplicationBuilder;
 import org.springframework.boot.context.ApplicationPidFileWriter;
+import org.springframework.context.ApplicationContext;
 import org.springframework.context.ApplicationListener;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.context.event.ContextClosedEvent;
 import org.springframework.transaction.annotation.EnableTransactionManagement;
 
 import java.text.SimpleDateFormat;
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
 import java.util.Date;
 
 @Slf4j
@@ -65,7 +72,10 @@ public class RotaUticClientApplication implements CommandLineRunner, Application
 
         ItsAsnClientCommService itsAsnClientCommService = SpringUtils.getBean(ItsAsnClientCommService.class);
         itsAsnClientCommService.run();
-
+        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
+            log.error("on shutdown hook.");
+            terminateApplication();
+        }));
     }
 
     public void terminateApplication() {
@@ -75,8 +85,21 @@ public class RotaUticClientApplication implements CommandLineRunner, Application
 
     @Override
     public void onApplicationEvent(ContextClosedEvent contextClosedEvent) {
-        SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-        log.error("Application Terminated: {}, {}", sdfDate.format(new Date()), contextClosedEvent);
+        try {
+            SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+            LocalDateTime dateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(contextClosedEvent.getTimestamp()), ZoneId.systemDefault());
+            String formattedDateTime = dateTime.format(formatter);
+            log.error("ContextClosedEvent Application Terminated: {}, {}", sdfDate.format(new Date()), contextClosedEvent);
+            log.error("ContextClosedEvent Source: " + contextClosedEvent.getSource());
+            log.error("ContextClosedEvent Timestamp: " + formattedDateTime);
+
+            ApplicationContext applicationContext = contextClosedEvent.getApplicationContext();
+            BeanDefinitionRegistry beanFactory = (BeanDefinitionRegistry) applicationContext.getAutowireCapableBeanFactory();
+        }
+        catch (Throwable e) {
+            log.error("spring context destroy error", e);
+        }
         terminateApplication();
     }
 

+ 64 - 0
rota-utic-client/src/main/java/com/its/rota/utic/client/config/TraceConfig.java

@@ -0,0 +1,64 @@
+package com.its.rota.utic.client.config;
+
+import com.its.common.utils.StringUtils;
+import com.its.rota.utic.client.dto.CenterDto;
+import com.its.rota.utic.client.repository.ApplicationRepository;
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import lombok.Setter;
+import lombok.ToString;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+import java.io.FileInputStream;
+import java.util.List;
+import java.util.Properties;
+
+@Slf4j
+@Getter
+@Setter
+@ToString
+@RequiredArgsConstructor
+@Component
+public class TraceConfig {
+
+    private final ApplicationRepository repo;
+
+    private Properties getProperties() {
+        String workingDir = System.getProperty("user.dir");
+        Properties props = new Properties();
+        try {
+            FileInputStream in = new FileInputStream(workingDir + "/conf/evps-comm-server-trace.cfg");
+            props.load(in);
+            in.close();
+        }
+        catch(Exception e) {
+            log.error("{}.getProperties Exception: {}", this.getClass().getSimpleName(), e.toString());
+        }
+        return props;
+    }
+
+    public void loadTraceInfo() {
+        try {
+            this.repo.getRegionCenterMap().forEach((key, center) -> center.setCommLogging(false));
+
+            Properties props = getProperties();
+            String dumps = props.getProperty("DUMP",  "").trim();
+            if (dumps.isEmpty()) {
+                return;
+            }
+
+            List<String> regionCds = StringUtils.split(dumps, ",");
+            regionCds.forEach(id -> {
+                CenterDto center = this.repo.getRegionCenterMap().get(id.trim());
+                if (center != null) {
+                    center.setCommLogging(true);
+                }
+            });
+        }
+        catch(Exception e) {
+            log.error("{}.loadTraceInfo Exception: {}", this.getClass().getSimpleName(), e.toString());
+        }
+    }
+
+}

+ 12 - 0
rota-utic-client/src/main/java/com/its/rota/utic/client/scheduler/ApplicationScheduler.java

@@ -2,6 +2,7 @@ package com.its.rota.utic.client.scheduler;
 
 import com.its.common.annotation.ScheduleElapsed;
 import com.its.rota.utic.client.config.SchedulingConfig;
+import com.its.rota.utic.client.config.TraceConfig;
 import com.its.rota.utic.client.process.dbms.DbmsData;
 import com.its.rota.utic.client.process.dbms.DbmsDataProcess;
 import com.its.rota.utic.client.repository.ApplicationRepository;
@@ -20,6 +21,7 @@ import javax.annotation.PreDestroy;
 @Component
 public class ApplicationScheduler {
 
+    private final TraceConfig traceConfig;
     private final SchedulingConfig config;
     private final DbmsDataProcess dbmsDataProcess;
 
@@ -82,5 +84,15 @@ public class ApplicationScheduler {
         }
     }
 
+    @Async
+    @Scheduled(cron = "30 * * * * *")  // 1분주기 작업 실행
+    public void loadTraceConfig() {
+        try {
+            this.traceConfig.loadTraceInfo();
+        }
+        catch(Exception e) {
+            log.error("ApplicationScheduler.loadTraceConfig: Exception {}", e.getMessage());
+        }
+    }
 
 }

+ 0 - 13
rota-utic-client/src/main/resources/logback-spring-appender.xml

@@ -86,19 +86,6 @@
         </rollingPolicy>
     </appender>
 
-    <appender name="FILE_STATISTICS" class="ch.qos.logback.core.rolling.RollingFileAppender">
-        <file>${LOG_PATH}${LOG_FILE_NAME_STATISTICS}</file>
-        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
-            <charset>${LOG_CHARSET}</charset>
-            <pattern>${LOG_PATTERN_STATISTICS}</pattern>
-        </encoder>
-        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
-            <fileNamePattern>${LOG_BACKUP_PATH}${LOG_FILE_NAME_STATISTICS}.${LOG_FILE_NAME_PATTERN}</fileNamePattern>
-            <maxFileSize>${MAX_FILESIZE}</maxFileSize>
-            <maxHistory>${MAX_HISTORY}</maxHistory>
-        </rollingPolicy>
-    </appender>
-
     <appender name="FILE_SCHEDULE" class="ch.qos.logback.core.rolling.RollingFileAppender">
         <file>${LOG_PATH}${LOG_FILE_NAME_SCHEDULE}</file>
         <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">

+ 1 - 11
rota-utic-client/src/main/resources/logback-spring.xml

@@ -40,11 +40,6 @@
             <appender-ref ref="FILE_ERROR"/>
         </root>
 
-        <logger name="${APP_CLASS_PATH}.service" level="INFO" additivity="false">
-            <appender-ref ref="FILE_STATISTICS"/>
-            <appender-ref ref="FILE_ERROR"/>
-        </logger>
-
         <logger name="${APP_CLASS_PATH}.scheduler" level="INFO" additivity="false">
             <appender-ref ref="FILE_SCHEDULE"/>
             <appender-ref ref="FILE_ERROR"/>
@@ -68,12 +63,6 @@
             <appender-ref ref="FILE_ERROR"/>
         </root>
 
-        <logger name="${APP_CLASS_PATH}.service" level="INFO" additivity="false">
-            <appender-ref ref="CONSOLE"/>
-            <appender-ref ref="FILE_STATISTICS"/>
-            <appender-ref ref="FILE_ERROR"/>
-        </logger>
-
         <logger name="${APP_CLASS_PATH}.scheduler" level="INFO" additivity="false">
             <appender-ref ref="CONSOLE"/>
             <appender-ref ref="FILE_SCHEDULE"/>
@@ -87,6 +76,7 @@
         </logger>
 
         <logger name="${APP_CLASS_PATH}.xnet" level="INFO" additivity="false">
+            <appender-ref ref="CONSOLE"/>
             <appender-ref ref="FILE_PACKET"/>
             <appender-ref ref="FILE_ERROR"/>
         </logger>

+ 2 - 0
rota-utic-server/conf/rota-utic-server-trace.cfg

@@ -0,0 +1,2 @@
+#DUMP=L01,...
+DUMP=

+ 1 - 1
rota-utic-server/reference/stat.sh

@@ -1,6 +1,6 @@
 #!/bin/sh
 
-export SERVICE_NAME=its-rota-
+export SERVICE_NAME=rota-utic-
 
 ps -eaf | grep $SERVICE_NAME | grep -v grep | grep -v tail | grep -v kafka | grep java | wc -l
 

+ 26 - 3
rota-utic-server/src/main/java/com/its/rota/utic/server/RotaUticServerApplication.java

@@ -8,18 +8,25 @@ import com.its.rota.utic.server.xnet.server.process.work.DataPacketProcess;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.DisposableBean;
 import org.springframework.beans.factory.InitializingBean;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.support.BeanDefinitionRegistry;
 import org.springframework.boot.Banner;
 import org.springframework.boot.CommandLineRunner;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.builder.SpringApplicationBuilder;
 import org.springframework.boot.context.ApplicationPidFileWriter;
+import org.springframework.context.ApplicationContext;
 import org.springframework.context.ApplicationListener;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.context.event.ContextClosedEvent;
 import org.springframework.transaction.annotation.EnableTransactionManagement;
 
 import java.text.SimpleDateFormat;
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
 import java.util.Date;
 
 @Slf4j
@@ -65,7 +72,10 @@ public class RotaUticServerApplication implements CommandLineRunner, Application
 
         ItsAsnCommServerService itsAsnCommServerService = SpringUtils.getBean(ItsAsnCommServerService.class);
         itsAsnCommServerService.run();
-
+        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
+            log.error("on shutdown hook.");
+            terminateApplication();
+        }));
     }
 
     public void terminateApplication() {
@@ -78,8 +88,21 @@ public class RotaUticServerApplication implements CommandLineRunner, Application
 
     @Override
     public void onApplicationEvent(ContextClosedEvent contextClosedEvent) {
-        SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-        log.error("Application Terminated: {}, {}", sdfDate.format(new Date()), contextClosedEvent);
+        try {
+            SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+            LocalDateTime dateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(contextClosedEvent.getTimestamp()), ZoneId.systemDefault());
+            String formattedDateTime = dateTime.format(formatter);
+            log.error("ContextClosedEvent Application Terminated: {}, {}", sdfDate.format(new Date()), contextClosedEvent);
+            log.error("ContextClosedEvent Source: " + contextClosedEvent.getSource());
+            log.error("ContextClosedEvent Timestamp: " + formattedDateTime);
+
+            ApplicationContext applicationContext = contextClosedEvent.getApplicationContext();
+            BeanDefinitionRegistry beanFactory = (BeanDefinitionRegistry) applicationContext.getAutowireCapableBeanFactory();
+        }
+        catch (Throwable e) {
+            log.error("spring context destroy error", e);
+        }
         terminateApplication();
     }
 

+ 64 - 0
rota-utic-server/src/main/java/com/its/rota/utic/server/config/TraceConfig.java

@@ -0,0 +1,64 @@
+package com.its.rota.utic.server.config;
+
+import com.its.common.utils.StringUtils;
+import com.its.rota.utic.server.dto.CenterDto;
+import com.its.rota.utic.server.repository.ApplicationRepository;
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import lombok.Setter;
+import lombok.ToString;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+import java.io.FileInputStream;
+import java.util.List;
+import java.util.Properties;
+
+@Slf4j
+@Getter
+@Setter
+@ToString
+@RequiredArgsConstructor
+@Component
+public class TraceConfig {
+
+    private final ApplicationRepository repo;
+
+    private Properties getProperties() {
+        String workingDir = System.getProperty("user.dir");
+        Properties props = new Properties();
+        try {
+            FileInputStream in = new FileInputStream(workingDir + "/conf/evps-comm-server-trace.cfg");
+            props.load(in);
+            in.close();
+        }
+        catch(Exception e) {
+            log.error("{}.getProperties Exception: {}", this.getClass().getSimpleName(), e.toString());
+        }
+        return props;
+    }
+
+    public void loadTraceInfo() {
+        try {
+            this.repo.getCenterMap().forEach((key, center) -> center.setCommLogging(false));
+
+            Properties props = getProperties();
+            String dumps = props.getProperty("DUMP",  "").trim();
+            if (dumps.isEmpty()) {
+                return;
+            }
+
+            List<String> regionCds = StringUtils.split(dumps, ",");
+            regionCds.forEach(id -> {
+                CenterDto center = this.repo.getCenterMap().get(id.trim());
+                if (center != null) {
+                    center.setCommLogging(true);
+                }
+            });
+        }
+        catch(Exception e) {
+            log.error("{}.loadTraceInfo Exception: {}", this.getClass().getSimpleName(), e.toString());
+        }
+    }
+
+}

+ 12 - 0
rota-utic-server/src/main/java/com/its/rota/utic/server/scheduler/ApplicationScheduler.java

@@ -2,6 +2,7 @@ package com.its.rota.utic.server.scheduler;
 
 import com.its.common.annotation.ScheduleElapsed;
 import com.its.rota.utic.server.config.SchedulingConfig;
+import com.its.rota.utic.server.config.TraceConfig;
 import com.its.rota.utic.server.process.dbms.DbmsData;
 import com.its.rota.utic.server.process.dbms.DbmsDataProcess;
 import com.its.rota.utic.server.repository.ApplicationRepository;
@@ -21,6 +22,7 @@ import javax.annotation.PreDestroy;
 @Component
 public class ApplicationScheduler {
 
+    private final TraceConfig traceConfig;
     private final SchedulingConfig config;
     private final DbmsDataProcess dbmsDataProcess;
     private final ItsRotaServerService itsRotaServerService;
@@ -91,4 +93,14 @@ public class ApplicationScheduler {
         }
     }
 
+    @Async
+    @Scheduled(cron = "30 * * * * *")  // 1분주기 작업 실행
+    public void loadTraceConfig() {
+        try {
+            this.traceConfig.loadTraceInfo();
+        }
+        catch(Exception e) {
+            log.error("ApplicationScheduler.loadTraceConfig: Exception {}", e.getMessage());
+        }
+    }
 }

+ 0 - 5
rota-utic-server/src/main/java/com/its/rota/utic/server/service/ItsRotaServerService.java

@@ -40,11 +40,6 @@ public class ItsRotaServerService {
         log.info("ItsRotaServerService.init: ..end.");
     }
 
-    @PreDestroy
-    public void destroyService() {
-        log.error("ItsRotaServerService.destroy. system terminated.......");
-    }
-
     public void resetCenterTrafficSend() {
         long baseTime = System.currentTimeMillis();
         List<String> keySet = new ArrayList<>(this.repo.getCenterMap().keySet());

+ 0 - 13
rota-utic-server/src/main/resources/logback-spring-appender.xml

@@ -86,19 +86,6 @@
         </rollingPolicy>
     </appender>
 
-    <appender name="FILE_STATISTICS" class="ch.qos.logback.core.rolling.RollingFileAppender">
-        <file>${LOG_PATH}${LOG_FILE_NAME_STATISTICS}</file>
-        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
-            <charset>${LOG_CHARSET}</charset>
-            <pattern>${LOG_PATTERN_STATISTICS}</pattern>
-        </encoder>
-        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
-            <fileNamePattern>${LOG_BACKUP_PATH}${LOG_FILE_NAME_STATISTICS}.${LOG_FILE_NAME_PATTERN}</fileNamePattern>
-            <maxFileSize>${MAX_FILESIZE}</maxFileSize>
-            <maxHistory>${MAX_HISTORY}</maxHistory>
-        </rollingPolicy>
-    </appender>
-
     <appender name="FILE_SCHEDULE" class="ch.qos.logback.core.rolling.RollingFileAppender">
         <file>${LOG_PATH}${LOG_FILE_NAME_SCHEDULE}</file>
         <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">

+ 1 - 11
rota-utic-server/src/main/resources/logback-spring.xml

@@ -40,11 +40,6 @@
             <appender-ref ref="FILE_ERROR"/>
         </root>
 
-        <logger name="${APP_CLASS_PATH}.service" level="INFO" additivity="false">
-            <appender-ref ref="FILE_STATISTICS"/>
-            <appender-ref ref="FILE_ERROR"/>
-        </logger>
-
         <logger name="${APP_CLASS_PATH}.scheduler" level="INFO" additivity="false">
             <appender-ref ref="FILE_SCHEDULE"/>
             <appender-ref ref="FILE_ERROR"/>
@@ -68,12 +63,6 @@
             <appender-ref ref="FILE_ERROR"/>
         </root>
 
-        <logger name="${APP_CLASS_PATH}.service" level="INFO" additivity="false">
-            <appender-ref ref="CONSOLE"/>
-            <appender-ref ref="FILE_STATISTICS"/>
-            <appender-ref ref="FILE_ERROR"/>
-        </logger>
-
         <logger name="${APP_CLASS_PATH}.scheduler" level="INFO" additivity="false">
             <appender-ref ref="CONSOLE"/>
             <appender-ref ref="FILE_SCHEDULE"/>
@@ -87,6 +76,7 @@
         </logger>
 
         <logger name="${APP_CLASS_PATH}.xnet" level="INFO" additivity="false">
+            <appender-ref ref="CONSOLE"/>
             <appender-ref ref="FILE_PACKET"/>
             <appender-ref ref="FILE_ERROR"/>
         </logger>