天蓬老师2017-04-18 09:31:42
You can make an independent interface service and execute a start and stop script, so that you can achieve the effect you want
高洛峰2017-04-18 09:31:42
Directly use java to call the system command to restart tomcat
The code is probably like this:
public static void runShell(final String cmd) throws IOException, InterruptedException {
executorService.execute(new Runnable() {
@Override
public void run() {
try {
Runtime run = Runtime.getRuntime();
Process p = run.exec(cmd);
BufferedInputStream in = new BufferedInputStream(p.getInputStream());
BufferedReader inBr = new BufferedReader(new InputStreamReader(in));
String lineStr;
while ((lineStr = inBr.readLine()) != null) {
logger.info(lineStr);// 打印输出信息
}
//检查命令是否执行失败。
if (p.waitFor() != 0) {
if (p.exitValue() == 1) {// 0表示正常结束,1:非正常结束
logger.error(cmd + "命令执行失败!");
}
}
inBr.close();
in.close();
} catch (Exception e) {
logger.error("调用系统命令失败!", e);
}
}
});
}
ringa_lee2017-04-18 09:31:42
Restarting the web program is nothing more than ending the process, executing the system exit 4 function, and then executing the main method to start the container. This program must be independent