Skip to content

Commit

Permalink
[PLAT-16668] Improving root check for yba-ctl preflight
Browse files Browse the repository at this point in the history
Summary: Our root check wasn't properly handling preflight case where previous install did not have as_root set, so this diff removes the requirement for only handling no as_root when running certain commands, as if it's not set we are not getting good results from the config anyways and it is causing yba-ctl to error in confusing situations.

Test Plan: Upgrade from 2.20.4 to 2024.2.1 and ensure preflight checks now pass with change.

Reviewers: dshubin, sanketh

Reviewed By: dshubin

Subscribers: yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D41697
  • Loading branch information
mchiddy committed Feb 5, 2025
1 parent 5c3ca57 commit a5731d6
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions managed/yba-installer/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ func handleRootCheck(cmdName string) {
log.Fatal("Could not determine current user: " + err.Error())
}

if !viper.IsSet("as_root") && cmdName == "yba-ctl upgrade" {
// Upgrading from before "as_root" exists. perform legacy check for /opt/yba-ctl
if !viper.IsSet("as_root") {
// Upgrading from before "as_root" exists. /opt/yba-ctl is source of truth, not viper
_, err := os.Stat(common.YbactlRootInstallDir)
if user.Uid == "0" && err != nil {
log.Fatal("no root install found at /opt/yba-ctl, cannot upgrade with root")
Expand All @@ -140,10 +140,7 @@ func handleRootCheck(cmdName string) {
}
log.Debug("legacy root check passed for upgrade")
return
}

// First, validate that the user (root access) matches the config 'as_root'
if user.Uid == "0" && !viper.GetBool("as_root") {
} else if user.Uid == "0" && !viper.GetBool("as_root") {
log.Fatal("running as root user with 'as_root' set to false is not supported")
} else if user.Uid != "0" &&
(viper.GetBool("as_root") || common.Exists(common.YbactlRootInstallDir)) {
Expand Down

0 comments on commit a5731d6

Please sign in to comment.