|
@@ -0,0 +1,90 @@
|
|
|
+package com.jiayue.ipfcst.console.service;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import com.jiayue.ipfcst.common.data.dto.ProcessResult;
|
|
|
+import com.jiayue.ipfcst.common.data.util.ShellUtil;
|
|
|
+import com.jiayue.ipfcst.fileupload.util.FileUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class ExteranlApplicationsService {
|
|
|
+
|
|
|
+ public ProcessResult status(String iden) {
|
|
|
+ String script = FileUtil.getBinPath() + File.separator + "status-" + iden + ".sh";
|
|
|
+ File file = new File(script);
|
|
|
+ ProcessResult processResult = new ProcessResult();
|
|
|
+ if (file.exists() && file.isFile()) {
|
|
|
+ processResult = runScript(script);
|
|
|
+ } else {
|
|
|
+ processResult.setExitCode(1);
|
|
|
+ processResult.output = CollUtil.newArrayList("文件" + file.getName() + "不存在!");
|
|
|
+ }
|
|
|
+ return processResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ProcessResult restart(String iden) {
|
|
|
+ String script = FileUtil.getBinPath() + File.separator + "restart-" + iden + ".sh";
|
|
|
+ File file = new File(script);
|
|
|
+ ProcessResult processResult = new ProcessResult();
|
|
|
+ if (file.exists() && file.isFile()) {
|
|
|
+ processResult = runScript(script);
|
|
|
+ } else {
|
|
|
+ processResult.setExitCode(1);
|
|
|
+ processResult.output = CollUtil.newArrayList("文件" + file.getName() + "不存在!");
|
|
|
+ }
|
|
|
+ return processResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ProcessResult start(String iden) {
|
|
|
+ String script = FileUtil.getBinPath() + File.separator + "start-" + iden + ".sh";
|
|
|
+ File file = new File(script);
|
|
|
+ ProcessResult processResult = new ProcessResult();
|
|
|
+ if (file.exists() && file.isFile()) {
|
|
|
+ processResult = runScript(script);
|
|
|
+ } else {
|
|
|
+ processResult.setExitCode(1);
|
|
|
+ processResult.output = CollUtil.newArrayList("文件" + file.getName() + "不存在!");
|
|
|
+ }
|
|
|
+ return processResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ProcessResult stop(String iden) {
|
|
|
+ String script = FileUtil.getBinPath() + File.separator + "stop-" + iden + ".sh";
|
|
|
+ File file = new File(script);
|
|
|
+ ProcessResult processResult = new ProcessResult();
|
|
|
+ if (file.exists() && file.isFile()) {
|
|
|
+ processResult = runScript(script);
|
|
|
+ } else {
|
|
|
+ processResult.setExitCode(1);
|
|
|
+ processResult.output = CollUtil.newArrayList("文件" + file.getName() + "不存在!");
|
|
|
+ }
|
|
|
+ return processResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ private ProcessResult runScript(String script) {
|
|
|
+ List<String> cmds = new ArrayList<>();
|
|
|
+ cmds.add("sh");
|
|
|
+ cmds.add("-c");
|
|
|
+ cmds.add(script);
|
|
|
+ return ShellUtil.runRuntime(cmds);
|
|
|
+ }
|
|
|
+
|
|
|
+ private ProcessResult getPid(String iden) {
|
|
|
+ List<String> cmds = new ArrayList<>();
|
|
|
+ Map<String, String> envs = new HashMap<>();
|
|
|
+ envs.put("LC_ALL", "zh_CN.UTF-8");
|
|
|
+ envs.put("LANG", "zh_CN.UTF-8");
|
|
|
+ cmds.add("sh");
|
|
|
+ cmds.add("-c");
|
|
|
+ cmds.add("pgrep -fl " + iden);
|
|
|
+ return ShellUtil.runProcess(cmds, envs, new File(FileUtil.getBinPath()));
|
|
|
+ }
|
|
|
+}
|