Zond: детектирование проблемного запуска процесса
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
group = 'asys'
|
||||
version = '0.7.9-SNAPSHOT'
|
||||
version = '0.7.10-SNAPSHOT'
|
||||
|
||||
apply plugin: 'application'
|
||||
|
||||
|
||||
@@ -55,4 +55,12 @@ public class Config {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public long getLong(String key) {
|
||||
try {
|
||||
return Long.parseLong(properties.getProperty(key));
|
||||
} catch (NumberFormatException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ public class PingMonitor {
|
||||
|
||||
lastPingTime = 0;
|
||||
});
|
||||
this.threadPingMon.start();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
|
||||
@@ -22,6 +22,7 @@ public class ZondCommandHandler implements CommandHandler {
|
||||
private Thread threadExec;
|
||||
private Server server;
|
||||
private PipeInputStream proxyStdIn;
|
||||
private PingMonitor pingMonitor;
|
||||
|
||||
ZondCommandHandler(PipeInputStream proxyStdIn) {
|
||||
this.proxyStdIn = proxyStdIn;
|
||||
@@ -47,31 +48,7 @@ public class ZondCommandHandler implements CommandHandler {
|
||||
Connector.getInstance().shutdown();
|
||||
Shell.getInstance().shutdown();
|
||||
} else if (line.equalsIgnoreCase("start")) {
|
||||
if (watchdog == null) {
|
||||
watchdog = new ZondExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT, proxyStdIn);
|
||||
executor.setWatchdog(watchdog);
|
||||
|
||||
Runnable task = () -> {
|
||||
int code = 0;
|
||||
try {
|
||||
server = new Server();
|
||||
server.start(Config.getInstance().getInt("bridge.port"));
|
||||
|
||||
code = executor.execute(commandLine);
|
||||
} catch (ExecuteException ignore) {
|
||||
} catch (IOException e) {
|
||||
Shell.getInstance().getOutput().println("Exception message: " + e.getMessage());
|
||||
code = -99;
|
||||
}
|
||||
|
||||
server.shutdown();
|
||||
server = null;
|
||||
watchdog = null;
|
||||
Shell.getInstance().getOutput().println("Process finished. Code: " + code);
|
||||
};
|
||||
threadExec = new Thread(task, "Zond Exec");
|
||||
threadExec.start();
|
||||
}
|
||||
startProcess();
|
||||
} else if (line.equalsIgnoreCase("kill")) {
|
||||
if (watchdog != null) {
|
||||
server.shutdown();
|
||||
@@ -97,4 +74,56 @@ public class ZondCommandHandler implements CommandHandler {
|
||||
this.executor = executor;
|
||||
this.commandLine = commandLine;
|
||||
}
|
||||
|
||||
private void startProcess() {
|
||||
if (watchdog == null) {
|
||||
watchdog = new ZondExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT, proxyStdIn);
|
||||
executor.setWatchdog(watchdog);
|
||||
final long delay = Config.getInstance().getLong("pingmonitor.delay");
|
||||
pingMonitor = new PingMonitor(delay);
|
||||
|
||||
Runnable task = () -> {
|
||||
short _try = 0;
|
||||
|
||||
do {
|
||||
int code = 0;
|
||||
long deadTime = System.currentTimeMillis() + delay;
|
||||
|
||||
try {
|
||||
server = new Server();
|
||||
server.start(Config.getInstance().getInt("bridge.port"));
|
||||
|
||||
pingMonitor.start(() -> {});
|
||||
code = executor.execute(commandLine);
|
||||
} catch (ExecuteException ignore) {
|
||||
} catch (IOException e) {
|
||||
Shell.getInstance().getOutput().println("Exception message: " + e.getMessage());
|
||||
code = -99;
|
||||
}
|
||||
|
||||
server.shutdown();
|
||||
pingMonitor.stop();
|
||||
server = null;
|
||||
watchdog = null;
|
||||
Shell.getInstance().getOutput().println("Process finished. Code: " + code);
|
||||
|
||||
if (System.currentTimeMillis() <= deadTime) {
|
||||
Shell.getInstance().getOutput().println("[!] Premature end process.");
|
||||
_try++;
|
||||
if (_try < 2) {
|
||||
Shell.getInstance().getOutput().println("[!] Try start process again...");
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} while (_try < 2);
|
||||
|
||||
if (_try == 2) {
|
||||
Shell.getInstance().getOutput().println("[!] Discovered the problem when starting the process");
|
||||
}
|
||||
};
|
||||
threadExec = new Thread(task, "Zond Exec");
|
||||
threadExec.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user