Просмотр исходного кода

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

ShuiMuNianHuaLP 3 лет назад
Родитель
Сommit
806333a11c

+ 6 - 4
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
         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);

+ 10 - 0
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;
 
 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
      *