Skip to content

Commit

Permalink
[BACKPORT 2.20.7][PLAT-15695] os rehydration fails with root install …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
shubin-yb committed Oct 11, 2024
1 parent 2e3aea0 commit 8211dbd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
25 changes: 17 additions & 8 deletions managed/yba-installer/cmd/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type prometheusDirectories struct {
DataDir string
PromDir string
cronScript string
LogDir string
LogDir string
}

func newPrometheusDirectories() prometheusDirectories {
Expand All @@ -48,7 +48,7 @@ func newPrometheusDirectories() prometheusDirectories {
PromDir: common.GetSoftwareRoot() + "/prometheus",
cronScript: filepath.Join(
common.GetInstallerSoftwareDir(), common.CronDir, "managePrometheus.sh"),
LogDir: logDir,
LogDir: logDir,
}
}

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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())
Expand All @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions managed/yba-installer/cmd/service_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
}
Expand Down

0 comments on commit 8211dbd

Please sign in to comment.