|
@@ -4,9 +4,7 @@ import com.ruoyi.file.domain.FileUpdateInfo;
|
|
|
import com.ruoyi.file.service.FileUpdateInfoService;
|
|
|
import com.usky.common.core.bean.ApiResult;
|
|
|
import com.usky.common.core.bean.CommonPage;
|
|
|
-import io.swagger.annotations.ApiOperation;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.util.List;
|
|
@@ -15,16 +13,6 @@ import java.util.List;
|
|
|
@RequestMapping("/api/update")
|
|
|
public class FileUpdateInfoController {
|
|
|
|
|
|
- // 从配置文件中读取脚本名称
|
|
|
- @Value("${file.linuxrestart}")
|
|
|
- private String linuxContralScript;
|
|
|
-
|
|
|
- @Value("${file.windowsstop}")
|
|
|
- private String windowsStopScript;
|
|
|
-
|
|
|
- @Value("${file.windowsstart}")
|
|
|
- private String windowsStartScript;
|
|
|
-
|
|
|
@Autowired
|
|
|
private FileUpdateInfoService fileUpdateInfoService;
|
|
|
|
|
@@ -107,42 +95,10 @@ public class FileUpdateInfoController {
|
|
|
return ApiResult.error("未找到对应的文件信息,ID: " + id);
|
|
|
}
|
|
|
String fileName = fileUpdateInfo.getFileName();
|
|
|
- controlApplication(fileName, action);
|
|
|
+ fileUpdateInfoService.controlApplication(fileName, action);
|
|
|
return ApiResult.success("服务控制命令已发送: " + action);
|
|
|
} catch (Exception e) {
|
|
|
return ApiResult.error("控制服务失败: " + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- private void controlApplication(String fileName, String action) throws Exception {
|
|
|
- String osName = System.getProperty("os.name").toLowerCase();
|
|
|
-
|
|
|
- if (osName.contains("linux") || osName.contains("unix")) {
|
|
|
- // Linux 系统
|
|
|
- String command = "sh " + linuxContralScript + " " + action + " " + fileName;
|
|
|
- Runtime.getRuntime().exec(command);
|
|
|
- } else if (osName.contains("windows")) {
|
|
|
- // Windows 系统
|
|
|
- String command;
|
|
|
- switch (action.toLowerCase()) {
|
|
|
- case "start":
|
|
|
- command = windowsStartScript + " " + fileName;
|
|
|
- break;
|
|
|
- case "stop":
|
|
|
- command = windowsStopScript + " " + fileName;
|
|
|
- break;
|
|
|
- case "restart":
|
|
|
- // Windows 系统没有单独的重启脚本,需要先停止再启动
|
|
|
- Runtime.getRuntime().exec(windowsStopScript + " " + fileName);
|
|
|
- Thread.sleep(5000); // 等待 5 秒,确保服务停止
|
|
|
- Runtime.getRuntime().exec(windowsStartScript + " " + fileName);
|
|
|
- return;
|
|
|
- default:
|
|
|
- throw new IllegalArgumentException("不支持的操作类型: " + action);
|
|
|
- }
|
|
|
- Runtime.getRuntime().exec(command);
|
|
|
- } else {
|
|
|
- throw new Exception("不支持的操作系统: " + osName);
|
|
|
- }
|
|
|
- }
|
|
|
}
|