Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use absolute path for sudo command #1515 #1516

Merged
merged 1 commit into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions components/playground/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ var (
)

const (
mode = "mode"
withMonitor = "monitor"
mode = "mode"
withMonitor = "monitor"
withoutMonitor = "without-monitor"

// instance numbers
Expand Down
6 changes: 3 additions & 3 deletions pkg/cluster/executor/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ var _ ctxt.Executor = &Local{}
func (l *Local) Execute(ctx context.Context, cmd string, sudo bool, timeout ...time.Duration) ([]byte, []byte, error) {
// try to acquire root permission
if l.Sudo || sudo {
cmd = fmt.Sprintf("sudo -H -u root bash -c 'cd; %s'", cmd)
cmd = fmt.Sprintf("/usr/bin/sudo -H -u root bash -c 'cd; %s'", cmd)
} else {
cmd = fmt.Sprintf("sudo -H -u %s bash -c 'cd; %s'", l.Config.User, cmd)
cmd = fmt.Sprintf("/usr/bin/sudo -H -u %s bash -c 'cd; %s'", l.Config.User, cmd)
}

// set a basic PATH in case it's empty on login
Expand Down Expand Up @@ -114,7 +114,7 @@ func (l *Local) Transfer(ctx context.Context, src, dst string, download bool, li
if download || user.Username == l.Config.User {
cmd = fmt.Sprintf("cp %s %s", src, dst)
} else {
cmd = fmt.Sprintf("sudo -H -u root bash -c \"cp %[1]s %[2]s && chown %[3]s:$(id -g -n %[3]s) %[2]s\"", src, dst, l.Config.User)
cmd = fmt.Sprintf("/usr/bin/sudo -H -u root bash -c \"cp %[1]s %[2]s && chown %[3]s:$(id -g -n %[3]s) %[2]s\"", src, dst, l.Config.User)
}

command := exec.Command("/bin/sh", "-c", cmd)
Expand Down
4 changes: 2 additions & 2 deletions pkg/cluster/executor/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (e *EasySSHExecutor) initialize(config SSHConfig) {
func (e *EasySSHExecutor) Execute(ctx context.Context, cmd string, sudo bool, timeout ...time.Duration) ([]byte, []byte, error) {
// try to acquire root permission
if e.Sudo || sudo {
cmd = fmt.Sprintf("sudo -H bash -c \"%s\"", cmd)
cmd = fmt.Sprintf("/usr/bin/sudo -H bash -c \"%s\"", cmd)
}

// set a basic PATH in case it's empty on login
Expand Down Expand Up @@ -276,7 +276,7 @@ func (e *NativeSSHExecutor) Execute(ctx context.Context, cmd string, sudo bool,

// try to acquire root permission
if e.Sudo || sudo {
cmd = fmt.Sprintf("sudo -H bash -c \"%s\"", cmd)
cmd = fmt.Sprintf("/usr/bin/sudo -H bash -c \"%s\"", cmd)
}

// set a basic PATH in case it's empty on login
Expand Down
2 changes: 1 addition & 1 deletion pkg/cluster/operation/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ func CheckDirPermission(ctx context.Context, e ctxt.Executor, user, path string)

_, stderr, err := e.Execute(ctx,
fmt.Sprintf(
"sudo -u %[1]s touch %[2]s/.tiup_cluster_check_file && rm -f %[2]s/.tiup_cluster_check_file",
"/usr/bin/sudo -u %[1]s touch %[2]s/.tiup_cluster_check_file && rm -f %[2]s/.tiup_cluster_check_file",
user,
path,
),
Expand Down