diff --git a/commands/cmd_create_db.go b/commands/cmd_create_db.go index f2972cd..a505ff3 100644 --- a/commands/cmd_create_db.go +++ b/commands/cmd_create_db.go @@ -284,8 +284,17 @@ func (c *CmdCreateDB) Run(vcc vclusterops.ClusterCommands) error { // write db info to vcluster config file err := writeConfig(&vdb, c.createDBOptions.ForceOverwriteFile) if err != nil { - vcc.DisplayWarning("Failed to write the configuration file: %s\n", err) + vcc.DisplayWarning("Failed to write the configuration file: %s", err) + if dbOptions.ConfigPath != defaultConfigFilePath { + vcc.DisplayWarning("Attempting writing to default config file path: %s", defaultConfigFilePath) + dbOptions.ConfigPath = defaultConfigFilePath + err = writeConfig(&vdb, c.createDBOptions.ForceOverwriteFile) + if err != nil { + vcc.DisplayWarning("Failed to write the configuration file to default path: %s", err) + } + } } + // write config parameters to vcluster config param file err = c.writeConfigParam(c.createDBOptions.ConfigurationParameters, c.createDBOptions.ForceOverwriteFile) if err != nil { diff --git a/commands/vcluster_config.go b/commands/vcluster_config.go index 00004b9..4547b36 100644 --- a/commands/vcluster_config.go +++ b/commands/vcluster_config.go @@ -37,6 +37,7 @@ const ( currentConfigFileVersion = "1.0" configFilePerm = 0644 rpmConfDir = "/opt/vertica/config" + defaultConfigFilePath = rpmConfDir + "/" + defConfigFileName ) // Config is the struct of vertica_cluster.yaml @@ -124,7 +125,7 @@ func initConfigImpl(vclusterExePath string, ensureOptVerticaConfigExists, ensure } cobra.CheckErr(err) } else { - dbOptions.ConfigPath = fmt.Sprintf("%s/%s", rpmConfDir, defConfigFileName) + dbOptions.ConfigPath = defaultConfigFilePath return } } @@ -360,6 +361,7 @@ func (c *DatabaseConfig) write(configFilePath string, forceOverwrite bool) error if err != nil { return fmt.Errorf("fail to marshal configuration data, details: %w", err) } + err = os.WriteFile(configFilePath, configBytes, configFilePerm) if err != nil { return fmt.Errorf("fail to write configuration file, details: %w", err)