From 3975da343b27ac03df285ecbb1093579d929e4b9 Mon Sep 17 00:00:00 2001
From: Administrator <1144154118@qq.com>
Date: 星期五, 11 八月 2023 11:59:08 +0800
Subject: [PATCH] 巡检计划修改
---
ard-work/src/main/java/com/ruoyi/media/service/impl/MediaService.java | 43 ++++++++++++++++++++++++++++++-------------
1 files changed, 30 insertions(+), 13 deletions(-)
diff --git a/ard-work/src/main/java/com/ruoyi/media/service/impl/MediaService.java b/ard-work/src/main/java/com/ruoyi/media/service/impl/MediaService.java
index 3bdf604..c4be437 100644
--- a/ard-work/src/main/java/com/ruoyi/media/service/impl/MediaService.java
+++ b/ard-work/src/main/java/com/ruoyi/media/service/impl/MediaService.java
@@ -15,6 +15,7 @@
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import java.io.BufferedReader;
import java.io.File;
@@ -33,33 +34,49 @@
* @Version: 1.0
**/
@Service
-@Slf4j
+@Slf4j(topic = "cmd")
public class MediaService implements IMediaService {
@Resource
MediaClient mediaClient;
@Value("${mediamtx.host}")
String mediamtxHost;
+ @Value("${mediamtx.enabled}")
+ Boolean mediamtxEnabled;
+
+ String processName = "mediamtx.exe";
@PostConstruct
public void initMediaMtx() {
- if (Platform.isWindows()) {
- String processName="mediamtx.exe";
- String exePath = System.getProperty("user.dir") + File.separator + "lib" + File.separator + "mediamtx" + File.separator + "mediamtx.exe";
- String ymlPath = System.getProperty("user.dir") + File.separator + "lib" + File.separator + "mediamtx" + File.separator + "mediamtx.yml";
+ if (mediamtxEnabled) {
+ if (Platform.isWindows()) {
+ String exePath = System.getProperty("user.dir") + File.separator + "lib" + File.separator + "mediamtx" + File.separator + "mediamtx.exe";
+ String ymlPath = System.getProperty("user.dir") + File.separator + "lib" + File.separator + "mediamtx" + File.separator + "mediamtx.yml";
- List<String> cmd = new ArrayList<>();
- cmd.add(exePath);
- cmd.add(ymlPath);
+ List<String> cmd = new ArrayList<>();
+ cmd.add(exePath);
+ cmd.add(ymlPath);
+ if (CmdUtils.isProcessRunning(processName)) {
+ // 杩涚▼宸茬粡鍦ㄨ繍琛岋紝缁撴潫璇ヨ繘绋�
+ CmdUtils.stopProcess(processName);
+ }
+ // 鍚姩鍚庡彴杩涚▼
+ CmdUtils.commandStart(processName, cmd, null);
+ // 鍚姩cmd绐楀彛
+// String[] command = {"cmd","/c","start",exePath,ymlPath};
+// CmdUtils.commandStart(command);
+ }
+ }
+ }
+
+ @PreDestroy
+ public void destroyMediaMtx() {
+ if (mediamtxEnabled) {
+ log.info("閿�姣乵ediaMtx");
if (CmdUtils.isProcessRunning(processName)) {
// 杩涚▼宸茬粡鍦ㄨ繍琛岋紝缁撴潫璇ヨ繘绋�
CmdUtils.stopProcess(processName);
}
- // 鍚姩鍚庡彴杩涚▼
- CmdUtils.commandStart(processName,cmd);
- // 鍚姩cmd绐楀彛
-// String[] command = {"cmd","/c","start",exePath,ymlPath};
-// CmdUtils.commandStart(command);
}
}
--
Gitblit v1.9.3