|
@@ -17,6 +17,7 @@
|
|
|
|
|
|
package org.apache.dolphinscheduler.plugin.task.api;
|
|
|
|
|
|
+import static org.apache.dolphinscheduler.plugin.task.api.ProcessUtils.getPidsStr;
|
|
|
import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.EXIT_CODE_FAILURE;
|
|
|
import static org.apache.dolphinscheduler.plugin.task.api.TaskConstants.EXIT_CODE_KILL;
|
|
|
|
|
@@ -233,10 +234,11 @@ public abstract class AbstractCommandExecutor {
|
|
|
ProcessUtils.kill(taskRequest);
|
|
|
result.setExitStatusCode(EXIT_CODE_FAILURE);
|
|
|
}
|
|
|
-
|
|
|
- logger.info(
|
|
|
- "process has exited, execute path:{}, processId:{} ,exitStatusCode:{} ,processWaitForStatus:{} ,processExitValue:{}",
|
|
|
- taskRequest.getExecutePath(), processId, result.getExitStatusCode(), status, process.exitValue());
|
|
|
+ int exitCode = process.exitValue();
|
|
|
+ String exitLogMessage = EXIT_CODE_KILL == exitCode ? "process has killed." : "process has exited.";
|
|
|
+ logger.info(exitLogMessage
|
|
|
+ + " execute path:{}, processId:{} ,exitStatusCode:{} ,processWaitForStatus:{} ,processExitValue:{}",
|
|
|
+ taskRequest.getExecutePath(), processId, result.getExitStatusCode(), status, exitCode);
|
|
|
return result;
|
|
|
|
|
|
}
|
|
@@ -263,16 +265,11 @@ public abstract class AbstractCommandExecutor {
|
|
|
logger.info("cancel process: {}", processId);
|
|
|
|
|
|
// kill , waiting for completion
|
|
|
- boolean killed = softKill(processId);
|
|
|
+ boolean alive = softKill(processId);
|
|
|
|
|
|
- if (!killed) {
|
|
|
+ if (alive) {
|
|
|
// hard kill
|
|
|
hardKill(processId);
|
|
|
-
|
|
|
- // destory
|
|
|
- process.destroy();
|
|
|
-
|
|
|
- process = null;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -308,12 +305,12 @@ public abstract class AbstractCommandExecutor {
|
|
|
private void hardKill(int processId) {
|
|
|
if (processId != 0 && process.isAlive()) {
|
|
|
try {
|
|
|
- String cmd = String.format("kill -9 %d", processId);
|
|
|
+ String cmd = String.format("kill -9 %s", getPidsStr(processId));
|
|
|
cmd = OSUtils.getSudoCmd(taskRequest.getTenantCode(), cmd);
|
|
|
logger.info("hard kill task:{}, process id:{}, cmd:{}", taskRequest.getTaskAppId(), processId, cmd);
|
|
|
|
|
|
- Runtime.getRuntime().exec(cmd);
|
|
|
- } catch (IOException e) {
|
|
|
+ OSUtils.exeCmd(cmd);
|
|
|
+ } catch (Exception e) {
|
|
|
logger.error("kill attempt failed ", e);
|
|
|
}
|
|
|
}
|