终端重启,执行jenkins-update.bat脚本(需要修改不必要的命令)

segment2.0
linrf 2 years ago
parent 9638c227f7
commit 495b43953a

@ -19,7 +19,6 @@ import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import java.io.IOException;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -152,15 +151,15 @@ public class ClientHandler extends SimpleChannelInboundHandler<CommMsg<Serializa
log.info("【终端客户端-收到调度器消息】收到更新采集器文件命令,内容={}", messageContent); log.info("【终端客户端-收到调度器消息】收到更新采集器文件命令,内容={}", messageContent);
} }
private void virtualRestart(String messageContent) throws IOException { private void virtualRestart(String messageContent) throws Exception {
log.info("【终端客户端-收到调度器消息】收到虚拟机重启命令,内容={}", messageContent); log.info("【终端客户端-收到调度器消息】收到虚拟机重启命令,内容={}", messageContent);
StartUpExeUtils.restartComputer(); String result = StartUpExeUtils.restartComputer();
CommMsg<Serializable> collectorRestartMsg = CommMsg.builder() CommMsg<Serializable> collectorRestartMsg = CommMsg.builder()
.content("重启虚拟机,操作成功!") .content(result)
.messageTime(DateUtil.formatDateTime(new Date())) .messageTime(DateUtil.formatDateTime(new Date()))
.messageType(VIRTUAL_RESTART) .messageType(VIRTUAL_RESTART)
.build(); .build();
nettyClient.getCollectorChannelCacheMap().writeAndFlush(messageContent, collectorRestartMsg); nettyClient.sendMessage(collectorRestartMsg);
} }
private void collectorRestart(String messageContent) { private void collectorRestart(String messageContent) {
@ -188,7 +187,7 @@ public class ClientHandler extends SimpleChannelInboundHandler<CommMsg<Serializa
.messageTime(DateUtil.formatDateTime(new Date())) .messageTime(DateUtil.formatDateTime(new Date()))
.messageType(COLLECTOR_RESTART) .messageType(COLLECTOR_RESTART)
.build(); .build();
nettyClient.getCollectorChannelCacheMap().writeAndFlush(messageContent, collectorRestartMsg); nettyClient.sendMessage(collectorRestartMsg);
} }
} }
} }

@ -32,8 +32,18 @@ public class StartUpExeUtils {
} }
//重启虚拟机 //重启虚拟机
public static void restartComputer() throws IOException { public static String restartComputer() throws IOException, InterruptedException {
Runtime.getRuntime().exec("shutdown /r /t 0"); Process process = Runtime.getRuntime().exec("shutdown /r /t 0");
int exitCode = process.waitFor();
if (exitCode == 0) {
System.out.println("Command executed successfully.");
return "Command executed successfully.";
} else {
System.out.println("Command execution failed.");
return "Command executed failed.";
}
} }
//仅启动exe客户端不检查进程 //仅启动exe客户端不检查进程

Loading…
Cancel
Save