Browse Source

fix sudo.enable=false Is invalid (#8388)

3.0.0/version-upgrade
ShuiMuNianHuaLP 3 years ago committed by GitHub
parent
commit
806333a11c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/AbstractCommandExecutor.java
  2. 10
      dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/util/OSUtils.java

10
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/AbstractCommandExecutor.java

@ -124,10 +124,12 @@ public abstract class AbstractCommandExecutor {
// merge error information to standard output stream // merge error information to standard output stream
processBuilder.redirectErrorStream(true); processBuilder.redirectErrorStream(true);
// setting up user to run commands // if sudo.enable=true,setting up user to run commands
command.add("sudo"); if (OSUtils.isSudoEnable()) {
command.add("-u"); command.add("sudo");
command.add(taskRequest.getTenantCode()); command.add("-u");
command.add(taskRequest.getTenantCode());
}
command.add(commandInterpreter()); command.add(commandInterpreter());
command.addAll(Collections.emptyList()); command.addAll(Collections.emptyList());
command.add(commandFile); command.add(commandFile);

10
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/util/OSUtils.java

@ -18,6 +18,7 @@
package org.apache.dolphinscheduler.plugin.task.util; package org.apache.dolphinscheduler.plugin.task.util;
import org.apache.dolphinscheduler.plugin.task.api.ShellExecutor; import org.apache.dolphinscheduler.plugin.task.api.ShellExecutor;
import org.apache.dolphinscheduler.spi.utils.PropertyUtils;
import org.apache.dolphinscheduler.spi.utils.StringUtils; import org.apache.dolphinscheduler.spi.utils.StringUtils;
import java.io.IOException; import java.io.IOException;
@ -40,6 +41,15 @@ public class OSUtils {
return StringUtils.isEmpty(tenantCode) ? command : "sudo -u " + tenantCode + " " + command; return StringUtils.isEmpty(tenantCode) ? command : "sudo -u " + tenantCode + " " + command;
} }
/**
* use sudo or not
*
* @return true is use sudo
*/
public static boolean isSudoEnable() {
return PropertyUtils.getBoolean("sudo.enable", Boolean.TRUE);
}
/** /**
* whether is macOS * whether is macOS
* *

Loading…
Cancel
Save