From 664a3e05297f66f480e495b1156269970cce3958 Mon Sep 17 00:00:00 2001
From: ‘liusuyi’ <1951119284@qq.com>
Date: 星期五, 22 九月 2023 10:53:07 +0800
Subject: [PATCH] 规范外部程序启动,增加redis随项目启动
---
/dev/null | 63 ----------
ruoyi-admin/src/main/resources/META-INF/spring.factories | 1
ard-work/src/main/java/com/ruoyi/cmd/startup.java | 170 ++++++++++++++++++++++++++++
ard-work/src/main/java/com/ruoyi/storage/minio/service/impl/StorageMinioEventServiceImpl.java | 47 -------
ard-work/src/main/java/com/ruoyi/media/service/impl/MediaServiceImpl.java | 39 ------
5 files changed, 171 insertions(+), 149 deletions(-)
diff --git a/ard-work/src/main/java/com/ruoyi/cmd/startup.java b/ard-work/src/main/java/com/ruoyi/cmd/startup.java
new file mode 100644
index 0000000..1f6c2c5
--- /dev/null
+++ b/ard-work/src/main/java/com/ruoyi/cmd/startup.java
@@ -0,0 +1,170 @@
+package com.ruoyi.cmd;
+
+import com.ruoyi.utils.process.CmdUtils;
+import com.sun.jna.Platform;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.ApplicationContextInitializer;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.stereotype.Component;
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Description: 澶栭儴绋嬪簭鍚姩
+ * @ClassName: startup
+ * @Author: 鍒樿嫃涔�
+ * @Date: 2023骞�09鏈�22鏃�9:56:57
+ **/
+@Slf4j(topic = "cmd")
+@Component
+public class startup implements ApplicationContextInitializer {
+
+ //minio
+ String minioName = "minio.exe";
+ @Value("${minio.accessKey}")
+ String accessKey;
+ @Value("${minio.secretKey}")
+ String secretKey;
+ @Value("${minio.path}")
+ String path;
+ @Value("${minio.enabled}")
+ Boolean minioEnabled;
+ //mediamtx
+ String mediamtxName = "mediamtx.exe";
+ @Value("${mediamtx.enabled}")
+ Boolean mediamtxEnabled;
+ //webrtc-streamer
+ String webrtcName = "webrtc-streamer.exe";
+ @Value("${webrtc.host}")
+ String webrtcHost;
+ @Value("${webrtc.enabled}")
+ Boolean webrtcEnabled;
+ //redis
+ String redisName = "redis-server.exe";
+ /**
+ * 绋嬪簭鍒濆鍖栧惎鍔╮edis
+ * 鍒樿嫃涔�
+ * 2023/9/22 10:38:41
+ */
+ @Override
+ public void initialize(ConfigurableApplicationContext applicationContext) {
+ if (Platform.isWindows()) {
+ String exePath = System.getProperty("user.dir") + File.separator + "lib" + File.separator + "redis" + File.separator + redisName;
+ List<String> cmd = new ArrayList<>();
+ cmd.add(exePath);
+ if (CmdUtils.isProcessRunning(redisName)) {
+ // 杩涚▼宸茬粡鍦ㄨ繍琛岋紝缁撴潫璇ヨ繘绋�
+ CmdUtils.stopProcess(redisName);
+ }
+ // 鍚姩鍚庡彴杩涚▼
+ CmdUtils.commandStart(redisName, cmd, null);
+ // 鍚姩cmd绐楀彛
+// String[] command = {"cmd", "/c", "start", exePath, "-H127.0.0.1:8000", "-o"};
+// CmdUtils.commandStart(command);
+ }
+ }
+
+ @PostConstruct
+ public void init() {
+ if (minioEnabled) {
+ log.debug("鍒濆鍖栧惎鍔╩inio");
+ if (Platform.isWindows()) {
+ String exePath = System.getProperty("user.dir") + File.separator + "lib" + File.separator + "minio" + File.separator + minioName;
+ Map<String, String> env = new HashMap<>();
+ env.put("MINIO_ROOT_USER", accessKey);
+ env.put("MINIO_ROOT_PASSWORD", secretKey);
+ List<String> cmd = new ArrayList<>();
+ cmd.add(exePath);
+ cmd.add("server");
+ cmd.add(path);
+ cmd.add("--console-address=0.0.0.0:9000");
+ cmd.add("--address=0.0.0.0:9001");
+ if (CmdUtils.isProcessRunning(minioName)) {
+ // 杩涚▼宸茬粡鍦ㄨ繍琛岋紝缁撴潫璇ヨ繘绋�
+ CmdUtils.stopProcess(minioName);
+ }
+ // 鍚姩鍚庡彴杩涚▼
+ CmdUtils.commandStart(minioName, cmd, env);
+ // 鍚姩cmd绐楀彛
+ //String[] command = {"cmd", "/c", "start", exePath};
+ //CmdUtils.commandStart(command);
+ }
+ }
+ if (mediamtxEnabled) {
+ log.debug("鍒濆鍖栧惎鍔╩ediaMTX");
+ if (Platform.isWindows()) {
+ String exePath = System.getProperty("user.dir") + File.separator + "lib" + File.separator + "mediamtx" + File.separator + mediamtxName;
+ 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);
+ if (CmdUtils.isProcessRunning(mediamtxName)) {
+ // 杩涚▼宸茬粡鍦ㄨ繍琛岋紝缁撴潫璇ヨ繘绋�
+ CmdUtils.stopProcess(mediamtxName);
+ }
+ // 鍚姩鍚庡彴杩涚▼
+ CmdUtils.commandStart(mediamtxName, cmd, null);
+ // 鍚姩cmd绐楀彛
+// String[] command = {"cmd","/c","start",exePath,ymlPath};
+// CmdUtils.commandStart(command);
+ }
+ }
+ if (webrtcEnabled) {
+ if (Platform.isWindows()) {
+ String exePath = System.getProperty("user.dir") + File.separator + "lib" + File.separator + "webrtc" + File.separator + webrtcName;
+ List<String> cmd = new ArrayList<>();
+ cmd.add(exePath);
+ cmd.add("-H" + webrtcHost);
+ cmd.add("-o");
+ if (CmdUtils.isProcessRunning(webrtcName)) {
+ // 杩涚▼宸茬粡鍦ㄨ繍琛岋紝缁撴潫璇ヨ繘绋�
+ CmdUtils.stopProcess(webrtcName);
+ }
+ // 鍚姩鍚庡彴杩涚▼
+ CmdUtils.commandStart(webrtcName, cmd, null);
+ // 鍚姩cmd绐楀彛
+// String[] command = {"cmd", "/c", "start", exePath, "-H127.0.0.1:8000", "-o"};
+// CmdUtils.commandStart(command);
+ }
+ }
+ }
+
+ @PreDestroy
+ public void destroy() {
+ if (minioEnabled) {
+ log.info("閿�姣乵inio");
+ if (CmdUtils.isProcessRunning(minioName)) {
+ // 杩涚▼宸茬粡鍦ㄨ繍琛岋紝缁撴潫璇ヨ繘绋�
+ CmdUtils.stopProcess(minioName);
+ }
+ }
+ if (mediamtxEnabled) {
+ log.info("閿�姣乵ediaMtx");
+ if (CmdUtils.isProcessRunning(mediamtxName)) {
+ // 杩涚▼宸茬粡鍦ㄨ繍琛岋紝缁撴潫璇ヨ繘绋�
+ CmdUtils.stopProcess(mediamtxName);
+ }
+ }
+ if (webrtcEnabled) {
+ log.info("閿�姣亀ebrtc-streamer");
+ if (CmdUtils.isProcessRunning(webrtcName)) {
+ // 杩涚▼宸茬粡鍦ㄨ繍琛岋紝缁撴潫璇ヨ繘绋�
+ CmdUtils.stopProcess(webrtcName);
+ }
+ }
+ if (true) {
+ log.info("閿�姣乺edis");
+ if (CmdUtils.isProcessRunning(redisName)) {
+ // 杩涚▼宸茬粡鍦ㄨ繍琛岋紝缁撴潫璇ヨ繘绋�
+ CmdUtils.stopProcess(redisName);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/ard-work/src/main/java/com/ruoyi/media/service/impl/MediaServiceImpl.java b/ard-work/src/main/java/com/ruoyi/media/service/impl/MediaServiceImpl.java
index 71aa270..6f48201 100644
--- a/ard-work/src/main/java/com/ruoyi/media/service/impl/MediaServiceImpl.java
+++ b/ard-work/src/main/java/com/ruoyi/media/service/impl/MediaServiceImpl.java
@@ -44,12 +44,8 @@
@Value("${mediamtx.host}")
String mediamtxHost;
- @Value("${mediamtx.enabled}")
- Boolean mediamtxEnabled;
@Value("${mediamtx.software_decoding}")
Boolean softwareDecoding;
-
- String processName = "mediamtx.exe";
@Override
public void run(ApplicationArguments args) {
@@ -70,41 +66,6 @@
}
} catch (Exception ex) {
log.error("鍔犺浇娴佸獟浣撳垪琛ㄥ紓甯�:" + ex.getMessage());
- }
- }
-
- @PostConstruct
- public void initMediaMtx() {
- if (mediamtxEnabled) {
- log.debug("鍒濆鍖栧惎鍔╩ediaMTX");
- 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);
- 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);
- }
}
}
diff --git a/ard-work/src/main/java/com/ruoyi/media/service/impl/WebrtcService.java b/ard-work/src/main/java/com/ruoyi/media/service/impl/WebrtcService.java
deleted file mode 100644
index 0a0c592..0000000
--- a/ard-work/src/main/java/com/ruoyi/media/service/impl/WebrtcService.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package com.ruoyi.media.service.impl;
-
-import com.ruoyi.utils.process.CmdUtils;
-import com.sun.jna.Platform;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Component;
-
-import javax.annotation.PostConstruct;
-import javax.annotation.PreDestroy;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @Description:
- * @ClassName: webrtcService
- * @Author: 鍒樿嫃涔�
- * @Date: 2023骞�07鏈�26鏃�13:43:07
- * @Version: 1.0
- **/
-@Component
-@Slf4j(topic = "cmd")
-public class WebrtcService {
- String processName = "webrtc-streamer.exe";
- @Value("${webrtc.host}")
- String webrtcHost;
- @Value("${webrtc.enabled}")
- Boolean webrtcEnabled;
-
- @PostConstruct
- public void init() {
- if (webrtcEnabled) {
- if (Platform.isWindows()) {
- String exePath = System.getProperty("user.dir") + File.separator + "lib" + File.separator + "webrtc" + File.separator + processName;
- List<String> cmd = new ArrayList<>();
- cmd.add(exePath);
- cmd.add("-H" + webrtcHost);
- cmd.add("-o");
- if (CmdUtils.isProcessRunning(processName)) {
- // 杩涚▼宸茬粡鍦ㄨ繍琛岋紝缁撴潫璇ヨ繘绋�
- CmdUtils.stopProcess(processName);
- }
- // 鍚姩鍚庡彴杩涚▼
- CmdUtils.commandStart(processName, cmd, null);
- // 鍚姩cmd绐楀彛
-// String[] command = {"cmd", "/c", "start", exePath, "-H127.0.0.1:8000", "-o"};
-// CmdUtils.commandStart(command);
- }
- }
- }
-
- @PreDestroy
- public void destroyMediaMtx() {
- if (webrtcEnabled) {
- log.info("閿�姣亀ebrtc-streamer");
- if (CmdUtils.isProcessRunning(processName)) {
- // 杩涚▼宸茬粡鍦ㄨ繍琛岋紝缁撴潫璇ヨ繘绋�
- CmdUtils.stopProcess(processName);
- }
- }
- }
-}
diff --git a/ard-work/src/main/java/com/ruoyi/storage/minio/service/impl/StorageMinioEventServiceImpl.java b/ard-work/src/main/java/com/ruoyi/storage/minio/service/impl/StorageMinioEventServiceImpl.java
index d88e965..d5f2c06 100644
--- a/ard-work/src/main/java/com/ruoyi/storage/minio/service/impl/StorageMinioEventServiceImpl.java
+++ b/ard-work/src/main/java/com/ruoyi/storage/minio/service/impl/StorageMinioEventServiceImpl.java
@@ -39,53 +39,6 @@
@Resource
private StorageMinioEventMapper storageMinioEventMapper;
- @Value("${minio.accessKey}")
- String accessKey;
- @Value("${minio.secretKey}")
- String secretKey;
- @Value("${minio.path}")
- String path;
- @Value("${minio.enabled}")
- Boolean enabled;
- String processName = "minio.exe";
- @PostConstruct
- public void initMinio() {
- if (enabled) {
- log.debug("鍒濆鍖栧惎鍔╩inio");
-
- if (Platform.isWindows()) {
- String exePath = System.getProperty("user.dir") + File.separator + "lib" + File.separator + "minio" + File.separator + processName;
- Map<String, String> env=new HashMap<>();
- env.put("MINIO_ROOT_USER",accessKey);
- env.put("MINIO_ROOT_PASSWORD",secretKey);
- List<String> cmd = new ArrayList<>();
- cmd.add(exePath);
- cmd.add("server");
- cmd.add(path);
- cmd.add("--console-address=0.0.0.0:9000");
- cmd.add("--address=0.0.0.0:9001");
- if (CmdUtils.isProcessRunning(processName)) {
- // 杩涚▼宸茬粡鍦ㄨ繍琛岋紝缁撴潫璇ヨ繘绋�
- CmdUtils.stopProcess(processName);
- }
- // 鍚姩鍚庡彴杩涚▼
- CmdUtils.commandStart(processName, cmd, env);
- // 鍚姩cmd绐楀彛
- //String[] command = {"cmd", "/c", "start", exePath};
- //CmdUtils.commandStart(command);
- }
- }
- }
- @PreDestroy
- public void destroyMinio() {
- if (enabled) {
- log.info("閿�姣乵inio");
- if (CmdUtils.isProcessRunning(processName)) {
- // 杩涚▼宸茬粡鍦ㄨ繍琛岋紝缁撴潫璇ヨ繘绋�
- CmdUtils.stopProcess(processName);
- }
- }
- }
/**
* 鏌ヨ瀛樺偍浜嬩欢
diff --git a/ruoyi-admin/src/main/resources/META-INF/spring.factories b/ruoyi-admin/src/main/resources/META-INF/spring.factories
new file mode 100644
index 0000000..57aeb71
--- /dev/null
+++ b/ruoyi-admin/src/main/resources/META-INF/spring.factories
@@ -0,0 +1 @@
+org.springframework.context.ApplicationContextInitializer=com.ruoyi.cmd.startup
\ No newline at end of file
--
Gitblit v1.9.3