generated from root/miduo_server
停服脚本优化1.0
parent
06f72e173b
commit
305ac14988
|
@ -5,10 +5,9 @@ import com.jmfy.model.CServerOpenTime;
|
|||
import com.jmfy.model.ServerInfo;
|
||||
import com.jmfy.model.vo.ServerInfoVo;
|
||||
import com.jmfy.redisProperties.RedisUserKey;
|
||||
import com.jmfy.utils.Constants;
|
||||
import com.jmfy.utils.JsonUtil;
|
||||
import com.jmfy.utils.RedisUtil;
|
||||
import com.jmfy.utils.SeqUtils;
|
||||
import com.jmfy.utils.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
@ -28,6 +27,8 @@ import java.util.List;
|
|||
|
||||
@Controller
|
||||
public class ServerInfoController {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ServerInfoController.class);
|
||||
|
||||
@Resource
|
||||
private ServerInfoDao serverInfoDao;
|
||||
|
||||
|
@ -68,9 +69,9 @@ public class ServerInfoController {
|
|||
}else if(serverInfo.getOpen_type()!=null&&serverInfo.getOpen_type().equals(Constants.SERVEROPEN_NUM)) {
|
||||
openT = "按量开服";
|
||||
}
|
||||
if(null!=openT)
|
||||
if(null!=openT) {
|
||||
serverInfoVo.setOpen_type(openT);
|
||||
|
||||
}
|
||||
}
|
||||
map.addAttribute("serverInfos", serverInfoVos);
|
||||
return "findServerInfo";
|
||||
|
@ -256,30 +257,21 @@ public class ServerInfoController {
|
|||
if (serverInfo.getIP() == null || "".equals(serverInfo.getIP())
|
||||
|| serverInfo.getServer_id() == null || "".equals(serverInfo.getServer_id())
|
||||
|| serverInfo.getCoreName() == null || "".equals(serverInfo.getCoreName())){
|
||||
System.err.printf("删除操作参数不全,执行失败:参数:%s",serverInfo.toString());
|
||||
LOGGER.error("删除操作参数不全,执行失败:参数:{}",serverInfo.toString());
|
||||
return wait;
|
||||
}
|
||||
String command = "sh " + path + " 500 " + serverInfo.getIP() + " " + serverInfo.getServer_id() + " " + serverInfo.getCoreName();
|
||||
List<String> processList = new ArrayList<>();
|
||||
try {
|
||||
Process exec = Runtime.getRuntime().exec(command);
|
||||
BufferedReader input = new BufferedReader(new InputStreamReader(exec.getInputStream()));
|
||||
String line = "";
|
||||
while ((line = input.readLine()) != null) {
|
||||
processList.add(line);
|
||||
}
|
||||
System.out.printf("删除操作完成:命令:{%s}\n",command);
|
||||
LOGGER.info("========================== 停服脚本执行结果开始 ===========================");
|
||||
new DealProcessSream(exec.getInputStream()).start();
|
||||
LOGGER.info("=========================== 停服脚本执行结果结束 ==========================");
|
||||
exec.waitFor();
|
||||
wait = 0;
|
||||
input.close();
|
||||
} catch (IOException e) {
|
||||
System.err.printf("删除操作失败:命令:{%s},报错:{%s}\n",command,e.getMessage());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
System.out.println("========================== 停服脚本执行结果开始 ===========================");
|
||||
processList.forEach(System.out::println);
|
||||
System.out.println("=========================== 停服脚本执行结果结束 ==========================");
|
||||
|
||||
LOGGER.info("删除操作完成:命令:{}",command);
|
||||
return wait;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
package com.jmfy.utils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
/**
|
||||
* @Author hj
|
||||
* @Date 2021/6/24 11:55
|
||||
* @Description:
|
||||
* @Version 1.0
|
||||
*/
|
||||
public class DealProcessSream extends Thread {
|
||||
private InputStream inputStream;
|
||||
|
||||
public DealProcessSream(InputStream inputStream) {
|
||||
this.inputStream = inputStream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
InputStreamReader inputStreamReader = null;
|
||||
BufferedReader br = null;
|
||||
try {
|
||||
inputStreamReader = new InputStreamReader(
|
||||
inputStream);
|
||||
br = new BufferedReader(inputStreamReader);
|
||||
// 打印信息
|
||||
String line = null;
|
||||
while ((line = br.readLine()) != null) {
|
||||
System.out.println(line);
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
}finally {
|
||||
try {
|
||||
if (br != null){
|
||||
br.close();
|
||||
}
|
||||
if (inputStreamReader != null){
|
||||
inputStreamReader.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue