You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by ji...@apache.org on 2022/02/17 07:23:34 UTC

[dolphinscheduler] branch dev updated: fix sudo.enable=false Is invalid (#8388)

This is an automated email from the ASF dual-hosted git repository.

jinyleechina pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git


The following commit(s) were added to refs/heads/dev by this push:
     new 806333a  fix sudo.enable=false Is invalid (#8388)
806333a is described below

commit 806333a11c03e5757d0c8dc56b5d1ca62fbacd1d
Author: ShuiMuNianHuaLP <46...@users.noreply.github.com>
AuthorDate: Thu Feb 17 15:23:21 2022 +0800

    fix sudo.enable=false Is invalid (#8388)
---
 .../plugin/task/api/AbstractCommandExecutor.java               | 10 ++++++----
 .../org/apache/dolphinscheduler/plugin/task/util/OSUtils.java  | 10 ++++++++++
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/AbstractCommandExecutor.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/AbstractCommandExecutor.java
index fa8b248..4873435 100644
--- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/AbstractCommandExecutor.java
+++ b/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);
diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/util/OSUtils.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/util/OSUtils.java
index e8c66a7..f34268d 100644
--- a/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/util/OSUtils.java
+++ b/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;
@@ -41,6 +42,15 @@ public class OSUtils {
     }
 
     /**
+     * use sudo or not
+     *
+     * @return true is use sudo
+     */
+    public static boolean isSudoEnable() {
+        return PropertyUtils.getBoolean("sudo.enable", Boolean.TRUE);
+    }
+
+    /**
      * whether is macOS
      *
      * @return true if mac