| | |
| | | **/
|
| | | @Slf4j(topic = "cmd")
|
| | | @Component
|
| | | public class startup implements ApplicationContextInitializer {
|
| | | public class startup{
|
| | |
|
| | | //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;
|
| | | //redis
|
| | | String redisName = "redis-server.exe";
|
| | | // //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;
|
| | | // //redis
|
| | | // String redisName = "redis-server.exe";
|
| | |
|
| | | /**
|
| | | * ç¨åºåå§åå¯å¨redis
|
| | | * åèä¹
|
| | | * 2023/9/22 10:38:41
|
| | | */
|
| | | @Override
|
| | | public void initialize(ConfigurableApplicationContext applicationContext) {
|
| | | if (Platform.isWindows()) {
|
| | | String workingDir = System.getProperty("user.dir") + File.separator + "server" + File.separator + "redis";
|
| | | String exePath = workingDir +File.separator+ redisName;
|
| | | List<String> cmd = new ArrayList<>();
|
| | | cmd.add(exePath);
|
| | | if (CmdUtils.isProcessRunning(redisName)) {
|
| | | // è¿ç¨å·²ç»å¨è¿è¡ï¼ç»æè¯¥è¿ç¨
|
| | | CmdUtils.stopProcess(redisName);
|
| | | }
|
| | | // å¯å¨åå°è¿ç¨
|
| | | CmdUtils.commandStart(workingDir, redisName, cmd, null);
|
| | | // å¯å¨cmdçªå£
|
| | | //String[] command = {"cmd", "/c", "start", exePath, "-H127.0.0.1:8000", "-o"};
|
| | | //CmdUtils.commandStart(command);
|
| | | }
|
| | | }
|
| | | // @Override
|
| | | // public void initialize(ConfigurableApplicationContext applicationContext) {
|
| | | // if (Platform.isWindows()) {
|
| | | // String workingDir = System.getProperty("user.dir") + File.separator + "server" + File.separator + "redis";
|
| | | // String exePath = workingDir +File.separator+ redisName;
|
| | | // List<String> cmd = new ArrayList<>();
|
| | | // cmd.add(exePath);
|
| | | // if (CmdUtils.isProcessRunning(redisName)) {
|
| | | // // è¿ç¨å·²ç»å¨è¿è¡ï¼ç»æè¯¥è¿ç¨
|
| | | // CmdUtils.stopProcess(redisName);
|
| | | // }
|
| | | // // å¯å¨åå°è¿ç¨
|
| | | // CmdUtils.commandStart(workingDir, redisName, cmd, null);
|
| | | // // å¯å¨cmdçªå£
|
| | | // //String[] command = {"cmd", "/c", "start", exePath, "-H127.0.0.1:8000", "-o"};
|
| | | // //CmdUtils.commandStart(command);
|
| | | // }
|
| | | // }
|
| | |
|
| | | @PostConstruct
|
| | | @Order(1)
|
| | | public void init() {
|
| | | if (minioEnabled) {
|
| | | log.info("åå§åå¯å¨minio");
|
| | | if (Platform.isWindows()) {
|
| | | String workingDir = System.getProperty("user.dir") + File.separator + "server" + File.separator + "minio";
|
| | | String exePath = workingDir + 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(workingDir, minioName, cmd, env);
|
| | | // å¯å¨cmdçªå£
|
| | | //String[] command = {"cmd", "/c", "start", exePath};
|
| | | //CmdUtils.commandStart(command);
|
| | | }
|
| | | }
|
| | | if (mediamtxEnabled) {
|
| | | log.info("åå§åå¯å¨mediaMTX");
|
| | | if (Platform.isWindows()) {
|
| | | String workingDir = System.getProperty("user.dir") + File.separator + "server" + File.separator + "mediamtx";
|
| | | String exePath = workingDir + File.separator + mediamtxName;
|
| | | String ymlPath = workingDir + File.separator + "mediamtx.yml";
|
| | | List<String> cmd = new ArrayList<>();
|
| | | cmd.add(exePath);
|
| | | // cmd.add(ymlPath);
|
| | | if (CmdUtils.isProcessRunning(mediamtxName)) {
|
| | | // è¿ç¨å·²ç»å¨è¿è¡ï¼ç»æè¯¥è¿ç¨
|
| | | CmdUtils.stopProcess(mediamtxName);
|
| | | }
|
| | | // å¯å¨åå°è¿ç¨
|
| | | CmdUtils.commandStart(workingDir, mediamtxName, cmd, null);
|
| | | // å¯å¨cmdçªå£
|
| | | //String[] command = {"cmd","/c","start",exePath,ymlPath};
|
| | | //CmdUtils.commandStart(command);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | @PreDestroy
|
| | | public void destroy() {
|
| | | if (minioEnabled) {
|
| | | log.info("鿝minio");
|
| | | if (CmdUtils.isProcessRunning(minioName)) {
|
| | | // è¿ç¨å·²ç»å¨è¿è¡ï¼ç»æè¯¥è¿ç¨
|
| | | CmdUtils.stopProcess(minioName);
|
| | | }
|
| | | }
|
| | | if (mediamtxEnabled) {
|
| | | log.info("鿝mediaMtx");
|
| | | if (CmdUtils.isProcessRunning(mediamtxName)) {
|
| | | // è¿ç¨å·²ç»å¨è¿è¡ï¼ç»æè¯¥è¿ç¨
|
| | | CmdUtils.stopProcess(mediamtxName);
|
| | | }
|
| | | }
|
| | | if (true) {
|
| | | log.info("鿝redis");
|
| | | if (CmdUtils.isProcessRunning(redisName)) {
|
| | | // è¿ç¨å·²ç»å¨è¿è¡ï¼ç»æè¯¥è¿ç¨
|
| | | CmdUtils.stopProcess(redisName);
|
| | | }
|
| | | }
|
| | | }
|
| | | // @PostConstruct
|
| | | // @Order(1)
|
| | | // public void init() {
|
| | | // if (minioEnabled) {
|
| | | // log.info("åå§åå¯å¨minio");
|
| | | // if (Platform.isWindows()) {
|
| | | // String workingDir = System.getProperty("user.dir") + File.separator + "server" + File.separator + "minio";
|
| | | // String exePath = workingDir + 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(workingDir, minioName, cmd, env);
|
| | | // // å¯å¨cmdçªå£
|
| | | // //String[] command = {"cmd", "/c", "start", exePath};
|
| | | // //CmdUtils.commandStart(command);
|
| | | // }
|
| | | // }
|
| | | // if (mediamtxEnabled) {
|
| | | // log.info("åå§åå¯å¨mediaMTX");
|
| | | // if (Platform.isWindows()) {
|
| | | // String workingDir = System.getProperty("user.dir") + File.separator + "server" + File.separator + "mediamtx";
|
| | | // String exePath = workingDir + File.separator + mediamtxName;
|
| | | // String ymlPath = workingDir + File.separator + "mediamtx.yml";
|
| | | // List<String> cmd = new ArrayList<>();
|
| | | // cmd.add(exePath);
|
| | | // // cmd.add(ymlPath);
|
| | | // if (CmdUtils.isProcessRunning(mediamtxName)) {
|
| | | // // è¿ç¨å·²ç»å¨è¿è¡ï¼ç»æè¯¥è¿ç¨
|
| | | // CmdUtils.stopProcess(mediamtxName);
|
| | | // }
|
| | | // // å¯å¨åå°è¿ç¨
|
| | | // CmdUtils.commandStart(workingDir, mediamtxName, cmd, null);
|
| | | // // å¯å¨cmdçªå£
|
| | | // //String[] command = {"cmd","/c","start",exePath,ymlPath};
|
| | | // //CmdUtils.commandStart(command);
|
| | | // }
|
| | | // }
|
| | | // }
|
| | | //
|
| | | // @PreDestroy
|
| | | // public void destroy() {
|
| | | // if (minioEnabled) {
|
| | | // log.info("鿝minio");
|
| | | // if (CmdUtils.isProcessRunning(minioName)) {
|
| | | // // è¿ç¨å·²ç»å¨è¿è¡ï¼ç»æè¯¥è¿ç¨
|
| | | // CmdUtils.stopProcess(minioName);
|
| | | // }
|
| | | // }
|
| | | // if (mediamtxEnabled) {
|
| | | // log.info("鿝mediaMtx");
|
| | | // if (CmdUtils.isProcessRunning(mediamtxName)) {
|
| | | // // è¿ç¨å·²ç»å¨è¿è¡ï¼ç»æè¯¥è¿ç¨
|
| | | // CmdUtils.stopProcess(mediamtxName);
|
| | | // }
|
| | | // }
|
| | | // if (true) {
|
| | | // log.info("鿝redis");
|
| | | // if (CmdUtils.isProcessRunning(redisName)) {
|
| | | // // è¿ç¨å·²ç»å¨è¿è¡ï¼ç»æè¯¥è¿ç¨
|
| | | // CmdUtils.stopProcess(redisName);
|
| | | // }
|
| | | // }
|
| | | // }
|
| | | }
|