Worker refuses to start without pg_hba.conf
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
61
main.go
61
main.go
@@ -196,7 +196,8 @@ func main() {
|
||||
initDonePath := filepath.Join(targetDir, PostgresInitDoneFileName)
|
||||
if _, err := os.Stat(initDonePath); err != nil && !os.IsNotExist(err) {
|
||||
log.Fatal("Failed to access Postgres data directory")
|
||||
} else if err != nil {
|
||||
} else {
|
||||
// Note: pg_auto_failure refuses to start without pg_hba.conf
|
||||
log.WithFields(log.Fields{"path": targetDir}).Info("Postgres data dir is not initialized")
|
||||
if state.hbaConfPath != "" {
|
||||
go func() {
|
||||
@@ -212,37 +213,39 @@ func main() {
|
||||
}()
|
||||
}
|
||||
|
||||
// Propagate the replication password
|
||||
// Note: There is no option to pass the replication password and even pg_autoctl create without --run already
|
||||
// assumes it is present. Neither pg_autoctl config set works at this stage
|
||||
replEnvPassword := "PGPASSWORD=" + state.replicationPassword
|
||||
replSet := false
|
||||
initEnv := innerEnv
|
||||
for i, j := range initEnv {
|
||||
if strings.HasPrefix(j, "PGPASSWORD=") {
|
||||
initEnv[i] = replEnvPassword
|
||||
replSet = true
|
||||
break
|
||||
if err != nil {
|
||||
// Database initialization as the storage is empty so propagate the replication password (in case this is a secondary)
|
||||
// Note: There is no option to pass the replication password and even pg_autoctl create without --run already
|
||||
// assumes it is present. Neither pg_autoctl config set works at this stage. So use PGPASSWORD
|
||||
replEnvPassword := "PGPASSWORD=" + state.replicationPassword
|
||||
replSet := false
|
||||
initEnv := innerEnv
|
||||
for i, j := range initEnv {
|
||||
if strings.HasPrefix(j, "PGPASSWORD=") {
|
||||
initEnv[i] = replEnvPassword
|
||||
replSet = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !replSet {
|
||||
initEnv = append(initEnv, replEnvPassword)
|
||||
}
|
||||
}
|
||||
if !replSet {
|
||||
initEnv = append(initEnv, replEnvPassword)
|
||||
}
|
||||
|
||||
log.WithFields(log.Fields{"name": innerExec, "args": innerArgs}).Info("Initializing pg_auto_failure on disk")
|
||||
cmdInit := exec.Command(innerExec, innerArgs...)
|
||||
cmdInit.Env = initEnv
|
||||
cmdInit.Stdout = os.Stdout
|
||||
cmdInit.Stderr = os.Stderr
|
||||
if err := cmdInit.Run(); err != nil {
|
||||
log.WithError(err).Warn("Initialization of pg_auto_failure encountered problems")
|
||||
}
|
||||
log.WithFields(log.Fields{"name": innerExec, "args": innerArgs}).Info("Initializing pg_auto_failure on disk")
|
||||
cmdInit := exec.Command(innerExec, innerArgs...)
|
||||
cmdInit.Env = initEnv
|
||||
cmdInit.Stdout = os.Stdout
|
||||
cmdInit.Stderr = os.Stderr
|
||||
if err := cmdInit.Run(); err != nil {
|
||||
log.WithError(err).Warn("Initialization of pg_auto_failure encountered problems")
|
||||
}
|
||||
|
||||
log.Info("Setting replication password in the configuration")
|
||||
setPassCmd := exec.Command(AutoFailoverExecutable, "config", "set", "replication.password", state.replicationPassword)
|
||||
setPassCmd.Env = state.env
|
||||
if err := setPassCmd.Run(); err != nil {
|
||||
log.WithError(err).Fatal("Failed to set password of user pgautofailover_replicator in the configuration")
|
||||
log.Info("Setting replication password in the configuration")
|
||||
setPassCmd := exec.Command(AutoFailoverExecutable, "config", "set", "replication.password", state.replicationPassword)
|
||||
setPassCmd.Env = state.env
|
||||
if err := setPassCmd.Run(); err != nil {
|
||||
log.WithError(err).Fatal("Failed to set password of user pgautofailover_replicator in the configuration")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user