feat:桌面镜像制作脚本
parent
152463897f
commit
ea39abaa9d
|
|
@ -10,6 +10,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@Slf4j
|
||||
@RequestMapping("/vdi")
|
||||
|
|
@ -30,10 +32,15 @@ public class DeskImageController {
|
|||
|
||||
@GetMapping("/progress")
|
||||
@ApiOperation(value = "制作桌面镜像")
|
||||
public Double start(@RequestParam("pid") String pid) {
|
||||
public Double start(@RequestParam("name") String name) {
|
||||
System.out.println("查询进度");
|
||||
ImageVirtualUtils.progress(pid);
|
||||
return null;
|
||||
|
||||
Map<String, Object> resultMap = ImageVirtualUtils.progress(name);
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@ import java.util.Map;
|
|||
public class ImageVirtualUtils {
|
||||
|
||||
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;
|
||||
|
||||
|
|
@ -102,4 +103,41 @@ public class ImageVirtualUtils {
|
|||
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");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue