From 8211dbd8bce1c79f6c7ee1618581ba1e45184d5f Mon Sep 17 00:00:00 2001 From: Daniel Shubin Date: Fri, 11 Oct 2024 17:48:54 +0000 Subject: [PATCH] [BACKPORT 2.20.7][PLAT-15695] os rehydration fails with root install dir change Summary: Original commit: None / D38962 Because it is possible to change the root install directory on a rehydration, yba-installer will set the config to enable path fixup. Also fixed a bug with the prometheus log file symlink Test Plan: os rehydration with upgrade + root install change. Reviewers: muthu, sanketh Reviewed By: muthu Subscribers: yugaware Differential Revision: https://phorge.dev.yugabyte.com/D38966 --- managed/yba-installer/cmd/prometheus.go | 25 +++++++++++++------- managed/yba-installer/cmd/service_control.go | 10 ++++++++ 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/managed/yba-installer/cmd/prometheus.go b/managed/yba-installer/cmd/prometheus.go index 448665a864bf..03bddb3a148d 100644 --- a/managed/yba-installer/cmd/prometheus.go +++ b/managed/yba-installer/cmd/prometheus.go @@ -31,7 +31,7 @@ type prometheusDirectories struct { DataDir string PromDir string cronScript string - LogDir string + LogDir string } func newPrometheusDirectories() prometheusDirectories { @@ -48,7 +48,7 @@ func newPrometheusDirectories() prometheusDirectories { PromDir: common.GetSoftwareRoot() + "/prometheus", cronScript: filepath.Join( common.GetInstallerSoftwareDir(), common.CronDir, "managePrometheus.sh"), - LogDir: logDir, + LogDir: logDir, } } @@ -134,6 +134,10 @@ func (prom Prometheus) Initialize() error { return err } + if err := prom.createDataSymlinks(); err != nil { + return err + } + if err := prom.Start(); err != nil { return err } @@ -536,12 +540,6 @@ func (prom Prometheus) createPrometheusSymlinks() error { {promPkg, prom.PromDir, "consoles"}, {promPkg, prom.PromDir, "console_libraries"}, } - // for root the log file is in /var/log in case of SELinux - if (common.HasSudoAccess()) { - links = append(links, struct { - pkgDir, linkDir, binary string - }{prom.LogDir, filepath.Join(common.GetBaseInstall(), "data/logs"), "prometheus.log"}) - } for _, link := range links { if err := common.CreateSymlink(link.pkgDir, link.linkDir, link.binary); err != nil { log.Error("failed to create symlink for " + link.binary + ": " + err.Error()) @@ -559,6 +557,17 @@ func (prom Prometheus) createPrometheusSymlinks() error { return nil } +func (prom Prometheus) createDataSymlinks() error { + if common.HasSudoAccess() { + // for root the log file is in /var/log in case of SELinux + if err := common.CreateSymlink(prom.LogDir, + filepath.Join(common.GetBaseInstall(), "data/logs"), "prometheus.log"); err != nil { + return err + } + } + return nil +} + func (prom Prometheus) migrateReplicatedDirs() error { if err := common.MkdirAll(prom.DataDir, common.DirMode); err != nil { return fmt.Errorf("failed to create %s: %w", prom.DataDir, err) diff --git a/managed/yba-installer/cmd/service_control.go b/managed/yba-installer/cmd/service_control.go index 603e12d1bb52..6f5ac1dd4983 100644 --- a/managed/yba-installer/cmd/service_control.go +++ b/managed/yba-installer/cmd/service_control.go @@ -5,6 +5,7 @@ import ( "github.com/spf13/cobra" "github.com/yugabyte/yugabyte-db/managed/yba-installer/pkg/common" + "github.com/yugabyte/yugabyte-db/managed/yba-installer/pkg/config" log "github.com/yugabyte/yugabyte-db/managed/yba-installer/pkg/logging" "github.com/yugabyte/yugabyte-db/managed/yba-installer/pkg/preflight" "github.com/yugabyte/yugabyte-db/managed/yba-installer/pkg/preflight/checks" @@ -47,11 +48,20 @@ var startCmd = &cobra.Command{ if preflight.ShouldFail(results) { log.Fatal("preflight failed") } + if err := common.Chown(common.GetDataRoot(), "yugabyte", "yugabyte", true); err != nil { + log.Fatal("Failed to change ownership of data directory: " + err.Error()) + } log.Info("Initializing YBA before starting services") if err := common.Initialize(); err != nil { log.Fatal("Failed to initialize common components: " + err.Error()) } for _, name := range serviceOrder { + if name == "yb-platform" { + log.Info("Generating yb-platform config with fixPaths set to true") + plat := services[name].(Platform) + plat.FixPaths = true + config.GenerateTemplate(plat) + } if err := services[name].Initialize(); err != nil { log.Fatal("Failed to initialize " + name + ": " + err.Error()) }