Skip to content

Commit

Permalink
[PLAT-15922] YBA Installer no longer block service control commands.
Browse files Browse the repository at this point in the history
Summary:
Service control commands (start, stop, restart, and status) do not need
to be blocked if the state is not 'installed'. There are debugging and general management
reasons to allow these commands to run in all states

Test Plan: manual testing

Reviewers: muthu, sanketh

Reviewed By: muthu

Subscribers: yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D39545
  • Loading branch information
shubin-yb committed Oct 31, 2024
1 parent 1c7bd3b commit 3d9b2e3
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 51 deletions.
6 changes: 3 additions & 3 deletions managed/yba-installer/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ var installCmd = &cobra.Command{
log.Fatal(err.Error())
}

getAndPrintStatus()
getAndPrintStatus(state)
log.Info("Successfully installed YugabyteDB Anywhere!")
},
}

func getAndPrintStatus() {
func getAndPrintStatus(state *ybactlstate.State) {
var statuses []common.Status
for _, name := range serviceOrder {
status, err := services[name].Status()
Expand All @@ -150,7 +150,7 @@ func getAndPrintStatus() {
}
}

common.PrintStatus(statuses...)
common.PrintStatus(state.CurrentStatus.String(), statuses...)
}

func init() {
Expand Down
2 changes: 1 addition & 1 deletion managed/yba-installer/cmd/replicated_migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ NOTE: THIS FEATURE IS EARLY ACCESS
}
}

common.PrintStatus(statuses...)
common.PrintStatus(state.CurrentStatus.String(), statuses...)
log.Info("Successfully installed YugabyteDB Anywhere!")

// Update state
Expand Down
22 changes: 1 addition & 21 deletions managed/yba-installer/cmd/service_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ var startCmd = &cobra.Command{
if err != nil {
log.Fatal("unable to load yba installer state: " + err.Error())
}
if state.CurrentStatus != ybactlstate.InstalledStatus {
log.Fatal("cannot start services - need installed state got " +
state.CurrentStatus.String())
}

// Initialize if it has not already happened. Do this instead of normal start workflow
if !state.Initialized {
Expand Down Expand Up @@ -75,7 +71,7 @@ var startCmd = &cobra.Command{
if err := common.WaitForYBAReady(ybaCtl.Version()); err != nil {
log.Fatal("failed to wait for yba ready: " + err.Error())
}
getAndPrintStatus()
getAndPrintStatus(state)
// We can exit early, as initialize will also start the services
return
}
Expand Down Expand Up @@ -119,14 +115,6 @@ var stopCmd = &cobra.Command{
}
},
Run: func(cmd *cobra.Command, args []string) {
state, err := ybactlstate.Initialize()
if err != nil {
log.Fatal("unable to load yba installer state: " + err.Error())
}
if state.CurrentStatus != ybactlstate.InstalledStatus {
log.Fatal("cannot stop services - need installed state got " +
state.CurrentStatus.String())
}
if len(args) == 1 {
if err := services[args[0]].Stop(); err != nil {
log.Fatal("Failed to stop " + args[0] + ": " + err.Error())
Expand Down Expand Up @@ -160,14 +148,6 @@ var restartCmd = &cobra.Command{
}
},
Run: func(cmd *cobra.Command, args []string) {
state, err := ybactlstate.Initialize()
if err != nil {
log.Fatal("unable to load yba installer state: " + err.Error())
}
if state.CurrentStatus != ybactlstate.InstalledStatus {
log.Fatal("cannot restart services - need installed state got " +
state.CurrentStatus.String())
}
if len(args) == 1 {
if err := services[args[0]].Restart(); err != nil {
log.Fatal("Failed to restart " + args[0] + ": " + err.Error())
Expand Down
10 changes: 3 additions & 7 deletions managed/yba-installer/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,11 @@ var statusCmd = &cobra.Command{
Args: cobra.MatchAll(cobra.MaximumNArgs(1), cobra.OnlyValidArgs),
ValidArgs: []string{"postgres", "prometheus", "yb-platform"},
Run: func(cmd *cobra.Command, args []string) {
// Print status for given service.
state, err := ybactlstate.Initialize()
if err != nil {
log.Fatal("unable to load yba installer state: " + err.Error())
}
if state.CurrentStatus != ybactlstate.InstalledStatus {
log.Fatal("cannot check service status - need installed state got " +
state.CurrentStatus.String())
}
// Print status for given service.
if len(args) == 1 {
service, exists := services[args[0]]
if !exists {
Expand All @@ -47,7 +43,7 @@ var statusCmd = &cobra.Command{
if err != nil {
log.Fatal("Failed to get status: " + err.Error())
}
common.PrintStatus(status)
common.PrintStatus(state.CurrentStatus.String(), status)
} else {
// Print status for all services.
var statuses []common.Status
Expand All @@ -59,7 +55,7 @@ var statusCmd = &cobra.Command{
statuses = append(statuses, status)
}

common.PrintStatus(statuses...)
common.PrintStatus(state.CurrentStatus.String(), statuses...)
}
},
}
Expand Down
22 changes: 11 additions & 11 deletions managed/yba-installer/cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ func rollbackUpgrade(backupDir string, state *ybactlstate.State) {
RestoreBackupScriptHelper(backup, common.GetBaseInstall(), true, true, false, false, true,
fmt.Sprintf("%s/yba_installer/packages/yugabyte-%s/devops/bin/yb_platform_backup.sh",
common.GetActiveSymlink(), state.Version),
common.GetBaseInstall() + "/data/yb-platform",
common.GetActiveSymlink() + "/ybdb/bin/ysqlsh",
common.GetActiveSymlink() + "/pgsql/bin/pg_restore")
common.GetBaseInstall()+"/data/yb-platform",
common.GetActiveSymlink()+"/ybdb/bin/ysqlsh",
common.GetActiveSymlink()+"/pgsql/bin/pg_restore")
}

// Validate symlink
Expand Down Expand Up @@ -56,7 +56,7 @@ func rollbackUpgrade(backupDir string, state *ybactlstate.State) {
}

// reconfigure with the old binary
if out:= shell.Run(filepath.Join(common.YbactlInstallDir(), "yba-ctl"), "reconfigure"); !out.SucceededOrLog() {
if out := shell.Run(filepath.Join(common.YbactlInstallDir(), "yba-ctl"), "reconfigure"); !out.SucceededOrLog() {
log.Warn(fmt.Sprintf("failed to reconfigure with old yba version: %w", out.Error))
}

Expand Down Expand Up @@ -139,13 +139,13 @@ func upgradeCmd() *cobra.Command {
log.Info(fmt.Sprintf("Taking YBA backup to %s", backupDir))
if errB := CreateBackupScriptHelper(backupDir, common.GetBaseInstall(), true, true, false, true, false,
fmt.Sprintf("%s/yba_installer/packages/yugabyte-%s/devops/bin/yb_platform_backup.sh", common.GetActiveSymlink(), state.Version),
common.GetActiveSymlink() + "/ybdb/postgres/bin/ysql_dump",
common.GetActiveSymlink() + "/pgsql/bin/pg_dump"); errB != nil {
if rollback{
rollbackUpgrade("", state)
}
log.Fatal("Failed taking backup of YBA")
common.GetActiveSymlink()+"/ybdb/postgres/bin/ysql_dump",
common.GetActiveSymlink()+"/pgsql/bin/pg_dump"); errB != nil {
if rollback {
rollbackUpgrade("", state)
}
log.Fatal("Failed taking backup of YBA")
}
}

/* This is the postgres major version upgrade workflow!
Expand Down Expand Up @@ -246,7 +246,7 @@ func upgradeCmd() *cobra.Command {
log.Fatal(status.Service + " is not running! upgrade failed")
}
}
common.PrintStatus(statuses...)
common.PrintStatus(state.CurrentStatus.String(), statuses...)
// Here ends the postgres minor version/no upgrade workflow

state.CurrentStatus = ybactlstate.InstalledStatus
Expand Down
14 changes: 7 additions & 7 deletions managed/yba-installer/pkg/common/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ func IsHappyStatus(status Status) bool {
}

// PrintStatus will print the service status and other useful data
func PrintStatus(statuses ...Status) {
func PrintStatus(stateStatus string, statuses ...Status) {

// YBA-CTL Status
generalStatus()
generalStatus(stateStatus)
fmt.Fprintln(os.Stdout, "\nServices:")
// Service Status
statusHeader()
Expand Down Expand Up @@ -59,9 +59,9 @@ func statusHeader() {
fmt.Fprintln(StatusOutput, outString)
}

func generalStatus() {
func generalStatus(stateStatus string) {
outString := "YBA Url" + " \t" + "Install Root" + " \t" + "yba-ctl config" + " \t" +
"yba-ctl Logs" + " \t"
"yba-ctl Logs" + " \t" + "YBA Installer State" + " \t"
hostnames := SplitInput(viper.GetString("host"))
if hostnames == nil || len(hostnames) == 0 {
log.Fatal("Could not read host in yba-ctl.yml")
Expand All @@ -71,7 +71,7 @@ func generalStatus() {
ybaUrl += fmt.Sprintf(":%d", viper.GetInt("platform.port"))
}
statusString := ybaUrl + " \t" + GetBaseInstall() + " \t" + InputFile() + " \t" +
YbactlLogFile() + " \t"
YbactlLogFile() + " \t" + stateStatus + " \t"

fmt.Fprintln(StatusOutput, outString)
fmt.Fprintln(StatusOutput, statusString)
Expand All @@ -87,8 +87,8 @@ type Status struct {
ServiceFileLoc string
Status StatusType
LogFileLoc string
Since string
BinaryLoc string
Since string
BinaryLoc string
}

type StatusType string
Expand Down
2 changes: 1 addition & 1 deletion managed/yba-installer/pkg/ybactlstate/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ var migrations map[int]migrator = map[int]migrator{
asRoot: migrateAsRootConfig,
ybaWait: migrateYbaWait,
initialized: migrateInitialized,
asRootRetry: migrateAsRootConfig,
asRootRetry: migrateAsRootConfig,
}

func getMigrationHandler(toSchema int) migrator {
Expand Down

0 comments on commit 3d9b2e3

Please sign in to comment.