|  | @@ -267,7 +267,7 @@ public class FileUpdateInfoServiceImpl implements FileUpdateInfoService {
 | 
	
		
			
				|  |  |                  case "restart":
 | 
	
		
			
				|  |  |                      // Windows 系统没有单独的重启脚本,需要先停止再启动
 | 
	
		
			
				|  |  |                      Runtime.getRuntime().exec(windowsStopScript + " " + fileName);
 | 
	
		
			
				|  |  | -                    Thread.sleep(5000); // 等待 5 秒,确保服务停止
 | 
	
		
			
				|  |  | +                    Thread.sleep(3000); // 等待 3 秒,确保服务停止
 | 
	
		
			
				|  |  |                      Runtime.getRuntime().exec(windowsStartScript + " " + fileName);
 | 
	
		
			
				|  |  |                      return;
 | 
	
		
			
				|  |  |                  default:
 | 
	
	
		
			
				|  | @@ -277,6 +277,31 @@ public class FileUpdateInfoServiceImpl implements FileUpdateInfoService {
 | 
	
		
			
				|  |  |          } else {
 | 
	
		
			
				|  |  |              throw new Exception("不支持的操作系统: " + osName);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 等待操作完成
 | 
	
		
			
				|  |  | +        long startTime = System.currentTimeMillis();
 | 
	
		
			
				|  |  | +        long timeout = 8000; // 最长等待时间 8 秒
 | 
	
		
			
				|  |  | +        boolean isActionCompleted = false;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        while (System.currentTimeMillis() - startTime < timeout) {
 | 
	
		
			
				|  |  | +            int currentStatus = getFileStatus(fileName); // 获取当前服务状态
 | 
	
		
			
				|  |  | +            if (action.equals("start") && currentStatus == 1) {
 | 
	
		
			
				|  |  | +                isActionCompleted = true;
 | 
	
		
			
				|  |  | +                break; // 服务已启动
 | 
	
		
			
				|  |  | +            } else if (action.equals("stop") && currentStatus == 2) {
 | 
	
		
			
				|  |  | +                isActionCompleted = true;
 | 
	
		
			
				|  |  | +                break; // 服务已停止
 | 
	
		
			
				|  |  | +            } else if (action.equals("restart") && currentStatus == 1) {
 | 
	
		
			
				|  |  | +                isActionCompleted = true;
 | 
	
		
			
				|  |  | +                break; // 服务已重启
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            Thread.sleep(500); // 每隔 500 毫秒检测一次状态
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if (!isActionCompleted) {
 | 
	
		
			
				|  |  | +            throw new Exception("操作超时,服务状态未达到预期");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      //扫描服务所在目录下的文件
 | 
	
	
		
			
				|  | @@ -333,7 +358,6 @@ public class FileUpdateInfoServiceImpl implements FileUpdateInfoService {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      // 检测服务运行状态并更新到数据库
 | 
	
		
			
				|  |  | -// 检测服务运行状态并更新到数据库
 | 
	
		
			
				|  |  |      private void checkServiceStatus(FileUpdateInfo fileUpdateInfo) {
 | 
	
		
			
				|  |  |          String fileName = fileUpdateInfo.getFileName();
 | 
	
		
			
				|  |  |          int fileStatus = getFileStatus(fileName); // 调用方法获取文件运行状态
 | 
	
	
		
			
				|  | @@ -342,7 +366,8 @@ public class FileUpdateInfoServiceImpl implements FileUpdateInfoService {
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      // 获取文件运行状态
 | 
	
		
			
				|  |  | -    private int getFileStatus(String fileName) {
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public int getFileStatus(String fileName) {
 | 
	
		
			
				|  |  |          String osName = System.getProperty("os.name").toLowerCase();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          if (osName.contains("linux") || osName.contains("unix")) {
 | 
	
	
		
			
				|  | @@ -354,16 +379,11 @@ public class FileUpdateInfoServiceImpl implements FileUpdateInfoService {
 | 
	
		
			
				|  |  |                  String line;
 | 
	
		
			
				|  |  |                  boolean isRunning = false;
 | 
	
		
			
				|  |  |                  while ((line = reader.readLine()) != null) {
 | 
	
		
			
				|  |  | -                    logger.info("Process output: {}", line);
 | 
	
		
			
				|  |  |                      if (line != null && !line.isEmpty()) {
 | 
	
		
			
				|  |  |                          isRunning = true;
 | 
	
		
			
				|  |  | -                        logger.info("Service is running: {}", fileName);
 | 
	
		
			
				|  |  |                          break;
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  | -                if (!isRunning) {
 | 
	
		
			
				|  |  | -                    logger.info("Service is not running: {}", fileName);
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  |                  return isRunning ? 1 : 2; // 1: 运行中,2: 已停止
 | 
	
		
			
				|  |  |              } catch (IOException e) {
 | 
	
		
			
				|  |  |                  logger.error("Failed to execute command: {}", command, e);
 | 
	
	
		
			
				|  | @@ -377,13 +397,10 @@ public class FileUpdateInfoServiceImpl implements FileUpdateInfoService {
 | 
	
		
			
				|  |  |                  String line;
 | 
	
		
			
				|  |  |                  boolean isRunning = false;
 | 
	
		
			
				|  |  |                  while ((line = reader.readLine()) != null) {
 | 
	
		
			
				|  |  | -                    logger.info("Service query output: {}", line);
 | 
	
		
			
				|  |  |                      if (line.contains("RUNNING")) {
 | 
	
		
			
				|  |  |                          isRunning = true;
 | 
	
		
			
				|  |  | -                        logger.info("Service is running: {}", fileName);
 | 
	
		
			
				|  |  |                          break;
 | 
	
		
			
				|  |  |                      } else if (line.contains("STOPPED")) {
 | 
	
		
			
				|  |  | -                        logger.info("Service is stopped: {}", fileName);
 | 
	
		
			
				|  |  |                          break;
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  |                  }
 |