feat:桌面镜像制作脚本

master
汤全昆 2025-09-02 14:50:30 +08:00
parent 152463897f
commit ea39abaa9d
2 changed files with 51 additions and 6 deletions

View File

@ -10,6 +10,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
@RestController @RestController
@Slf4j @Slf4j
@RequestMapping("/vdi") @RequestMapping("/vdi")
@ -30,10 +32,15 @@ public class DeskImageController {
@GetMapping("/progress") @GetMapping("/progress")
@ApiOperation(value = "制作桌面镜像") @ApiOperation(value = "制作桌面镜像")
public Double start(@RequestParam("pid") String pid) { public Double start(@RequestParam("name") String name) {
System.out.println("查询进度"); System.out.println("查询进度");
ImageVirtualUtils.progress(pid); Map<String, Object> resultMap = ImageVirtualUtils.progress(name);
return null; if(resultMap.get("process")!=null && (Double)resultMap.get("process") == 100){
String pid = (String) resultMap.get("pid");
ImageVirtualUtils.killProgress(pid);
return 100.0;
} else {
return (Double) resultMap.get("process");
}
} }
} }

View File

@ -16,7 +16,8 @@ import java.util.Map;
public class ImageVirtualUtils { public class ImageVirtualUtils {
private static final String BT_SCRIPT_PATH = "/var/lib/vdi/nodejs/convert_image.sh"; private static final String BT_SCRIPT_PATH = "/var/lib/vdi/nodejs/convert_image.sh";
private static final String JSON_PATH = "/var/lib/vdi/nodejs/json/"; // private static final String JSON_PATH = "/var/lib/vdi/nodejs/json/";
private static final String JSON_PATH = "D:\\code\\";
private static final Long WAIT_START_TIME = 8000L; private static final Long WAIT_START_TIME = 8000L;
@ -102,4 +103,41 @@ public class ImageVirtualUtils {
return null; return null;
} }
} }
public static boolean killProgress(String pid){
try {
// 验证PID参数
if (pid == null || pid.trim().isEmpty()) {
System.err.println("PID不能为空");
return false;
}
// 构造kill命令
ProcessBuilder pb = new ProcessBuilder("kill", "-9", pid);
// 启动进程
Process process = pb.start();
// 等待命令执行完成
int exitCode = process.waitFor();
// exitCode为0表示命令执行成功
if (exitCode == 0) {
System.out.println("成功杀掉进程 PID: " + pid);
return true;
} else {
System.err.println("杀掉进程失败 PID: " + pid + ", 退出码: " + exitCode);
return false;
}
} catch (Exception e) {
e.printStackTrace();
System.err.println("杀掉进程时发生异常 PID: " + pid);
return false;
}
}
public static void main(String[] args) {
Map map = progress("test.json");
}
} }