Skip to content

Commit

Permalink
[PLAT-15029] yba installer split data and software directory setup
Browse files Browse the repository at this point in the history
Summary:
Split install into 2 steps. 1 that will layout all the software directory and 1 that will layout
all the data directory and start the services. These will be known as install and initialize respectively.

The goal will be soon expose these are 2 different steps, allowing for a "data-less" install

Test Plan: tested install, upgrade, and replication migration

Reviewers: muthu, sanketh

Reviewed By: muthu

Subscribers: yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D37747
  • Loading branch information
shubin-yb committed Sep 4, 2024
1 parent c587efd commit 31e09f3
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 66 deletions.
3 changes: 3 additions & 0 deletions managed/yba-installer/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ var installCmd = &cobra.Command{
if err := services[name].Install(); err != nil {
log.Fatal("Failed while installing " + name + ": " + err.Error())
}
if err := services[name].Initialize(); err != nil {
log.Fatal("Failed while initializing " + name + ": " + err.Error())
}
log.Info("Completed installing component " + name)
}

Expand Down
73 changes: 41 additions & 32 deletions managed/yba-installer/cmd/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,25 +111,16 @@ func (plat Platform) Install() error {
log.Info("Starting Platform install")
config.GenerateTemplate(plat)

if err := plat.createNecessaryDirectories(); err != nil {
if err := plat.createSoftwareDirectories(); err != nil {
return err
}

if err := plat.untarDevopsAndYugawarePackages(); err != nil {
return err
}
if err := plat.copyYbcPackages(); err != nil {
return err
}
if err := plat.copyNodeAgentPackages(); err != nil {
return err
}
if err := plat.renameAndCreateSymlinks(); err != nil {
return err
}
if err := createPemFormatKeyAndCert(); err != nil {
return err
}

//Create the platform.log file so that we can start platform as
//a background process for non-root.
Expand All @@ -152,10 +143,28 @@ func (plat Platform) Install() error {
}
}

log.Info("Finishing Platform install")
return nil
}

func (plat Platform) Initialize() error {
log.Info("Starting Platform initialize")
if err := plat.createDataDirectiories(); err != nil {
return err
}
if err := plat.copyYbcPackages(); err != nil {
return err
}
if err := plat.copyNodeAgentPackages(); err != nil {
return err
}
if err := createPemFormatKeyAndCert(); err != nil {
return err
}
if err := plat.Start(); err != nil {
return err
}
log.Info("Finishing Platform install")
log.Info("Finishing Platform initialize")
return nil
}

Expand All @@ -168,32 +177,26 @@ func (plat Platform) SetDataDirPerms() error {
return nil
}

func (plat Platform) createNecessaryDirectories() error {
func (plat Platform) createSoftwareDirectories() error {
dirs := []string{
common.GetSoftwareRoot() + "/yb-platform",
plat.devopsDir(),
plat.yugawareDir(),
}
return common.CreateDirs(dirs)
}

func (plat Platform) createDataDirectiories() error {
dirs := []string{
common.GetBaseInstall() + "/data/yb-platform",
common.GetBaseInstall() + "/data/yb-platform/releases",
common.GetBaseInstall() + "/data/yb-platform/ybc",
common.GetBaseInstall() + "/data/yb-platform/ybc/release",
common.GetBaseInstall() + "/data/yb-platform/ybc/releases",
common.GetBaseInstall() + "/data/yb-platform/node-agent",
common.GetBaseInstall() + "/data/yb-platform/node-agent/releases",
plat.devopsDir(),
plat.yugawareDir(),
}
userName := viper.GetString("service_username")
for _, dir := range dirs {
if _, err := os.Stat(dir); errors.Is(err, os.ErrNotExist) {
if mkErr := common.MkdirAll(dir, common.DirMode); mkErr != nil {
log.Error("failed to make " + dir + ": " + err.Error())
return mkErr
}
if common.HasSudoAccess() {
if chErr := common.Chown(dir, userName, userName, true); chErr != nil {
log.Error("failed to set ownership of " + dir + ": " + chErr.Error())
return chErr
}
}
}
}
return nil
return common.CreateDirs(dirs)
}

func (plat Platform) untarDevopsAndYugawarePackages() error {
Expand Down Expand Up @@ -435,7 +438,10 @@ func (plat Platform) Upgrade() error {
if err := config.GenerateTemplate(plat); err != nil {
return err
} // systemctl reload is not needed, start handles it for us.
if err := plat.createNecessaryDirectories(); err != nil {
if err := plat.createSoftwareDirectories(); err != nil {
return err
}
if err := plat.createDataDirectiories(); err != nil {
return err
}
if err := plat.untarDevopsAndYugawarePackages(); err != nil {
Expand Down Expand Up @@ -491,7 +497,10 @@ func changeAllPermissions(user string) error {
func (plat Platform) MigrateFromReplicated() error {
config.GenerateTemplate(plat)

if err := plat.createNecessaryDirectories(); err != nil {
if err := plat.createSoftwareDirectories(); err != nil {
return err
}
if err := plat.createDataDirectiories(); err != nil {
return err
}
if err := plat.untarDevopsAndYugawarePackages(); err != nil {
Expand Down
11 changes: 9 additions & 2 deletions managed/yba-installer/cmd/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,20 @@ func (pg Postgres) getPgUserName() string {

// Install postgres and create the yugaware DB for YBA.
func (pg Postgres) Install() error {
log.Info("Starting Postgres install")
config.GenerateTemplate(pg)
if err := pg.extractPostgresPackage(); err != nil {
return err
}
log.Info("Finished Postgres install")
return nil
}

func (pg Postgres) Initialize() error {
log.Info("Starting Postgres initialize")
if err := pg.createFilesAndDirs(); err != nil {
return err
}

// First let initdb create its config and data files in the software/pg../conf location
if err := pg.runInitDB(); err != nil {
return err
Expand Down Expand Up @@ -144,6 +149,8 @@ func (pg Postgres) Install() error {
if viper.GetBool("postgres.install.enabled") {
pg.createYugawareDatabase()
}

log.Info("Finishing Postgres initialize")
return nil
}

Expand Down Expand Up @@ -651,7 +658,7 @@ func (pg Postgres) createYugawareDatabase() {
}

func (pg Postgres) createFilesAndDirs() error {
f, err := common.Create(common.GetBaseInstall() + "/data/logs/postgres.log")
f, err := common.Create(pg.LogFile)
if err != nil && !errors.Is(err, os.ErrExist) {
log.Error("Failed to create postgres logfile: " + err.Error())
return err
Expand Down
15 changes: 11 additions & 4 deletions managed/yba-installer/cmd/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ func (prom Prometheus) Install() error {
if err := prom.moveAndExtractPrometheusPackage(); err != nil {
return err
}
if err := prom.createDataDirs(); err != nil {
return err
}
if err := prom.createPrometheusSymlinks(); err != nil {
return err
}
Expand All @@ -123,10 +120,20 @@ func (prom Prometheus) Install() error {
}
}

log.Info("Finishing Prometheus install")
return nil
}

func (prom Prometheus) Initialize() error {
log.Info("Starting Prometheus initialize")
if err := prom.createDataDirs(); err != nil {
return err
}

if err := prom.Start(); err != nil {
return err
}
log.Info("Finishing Prometheus install")
log.Info("Finishing Prometheus initialize")
return nil
}

Expand Down
5 changes: 5 additions & 0 deletions managed/yba-installer/cmd/ybdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@ func (ybdb Ybdb) Install() error {
return nil
}

// Initialize ybdb - no op
func (ybdb Ybdb) Initialize() error {
return nil
}

// Install ybdb and create the yugaware DB for YBA.
func (ybdb Ybdb) createYugawareDatabase() error {
cmd := ybdb.ysqlBin
Expand Down
57 changes: 29 additions & 28 deletions managed/yba-installer/pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ func Install(version string) error {
return fmt.Errorf("could not set ownership of %s: %v", YbactlLogFile(), err)
}

if err := createInstallDirs(); err != nil {
if err := createSoftwareInstallDirs(); err != nil {
return err
}

if err := createDataInstallDirs(); err != nil {
return err
}
if err := copyBits(version); err != nil {
Expand Down Expand Up @@ -97,16 +101,37 @@ func Install(version string) error {
return nil
}

func createInstallDirs() error {
createDirs := []string{
func createSoftwareInstallDirs() error {
dirs := []string{
GetSoftwareRoot(),
dm.WorkingDirectory(),
GetInstallerSoftwareDir(),
GetBaseInstall(),
}
if err := CreateDirs(dirs); err != nil {
return err
}
// Remove the symlink if one exists
SetActiveInstallSymlink()
return nil
}

func createDataInstallDirs() error {
dirs := []string{
filepath.Join(GetBaseInstall(), "data"),
filepath.Join(GetBaseInstall(), "data/logs"),
}
return CreateDirs(dirs)
}

func createUpgradeDirs() error {
dirs := []string{
GetInstallerSoftwareDir(),
GetBaseInstall(),
}
return CreateDirs(dirs)
}

func CreateDirs(createDirs []string) error {
for _, dir := range createDirs {
_, err := os.Stat(dir)
if os.IsNotExist(err) {
Expand All @@ -124,30 +149,6 @@ func createInstallDirs() error {
}
}
}

// Remove the symlink if one exists
SetActiveInstallSymlink()
return nil
}

func createUpgradeDirs() error {
createDirs := []string{
GetInstallerSoftwareDir(),
}

for _, dir := range createDirs {
if err := MkdirAll(dir, DirMode); err != nil {
return fmt.Errorf("failed creating directory %s: %s", dir, err.Error())
}
if HasSudoAccess() {
err := Chown(dir, viper.GetString("service_username"), viper.GetString("service_username"),
true)
if err != nil {
return fmt.Errorf("failed to change ownership of " + dir + " to " +
viper.GetString("service_username") + ": " + err.Error())
}
}
}
return nil
}

Expand Down
1 change: 1 addition & 0 deletions managed/yba-installer/pkg/common/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Component interface {
Stop() error
Restart() error
Install() error
Initialize() error
MigrateFromReplicated() error
FinishReplicatedMigrate() error
SystemdFile() string
Expand Down

0 comments on commit 31e09f3

Please sign in to comment.