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

switch/metrics
ShuiMuNianHuaLP 2022-02-17 15:23:21 +08:00 committed by GitHub
parent d9129297ab
commit 806333a11c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 4 deletions

View File

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

View File

@ -18,6 +18,7 @@
package org.apache.dolphinscheduler.plugin.task.util;
import org.apache.dolphinscheduler.plugin.task.api.ShellExecutor;
import org.apache.dolphinscheduler.spi.utils.PropertyUtils;
import org.apache.dolphinscheduler.spi.utils.StringUtils;
import java.io.IOException;
@ -40,6 +41,15 @@ public class OSUtils {
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
*