func provisionImplInit(dbConn *sql.DB, params *swarmapi.DockerRunRequest, standby bool) error { //go get the domain name from the settings var domainname types.Setting var pgport types.Setting var sleepSetting types.Setting var err error domainname, err = admindb.GetSetting(dbConn, "DOMAIN-NAME") if err != nil { logit.Error.Println(err.Error()) return err } pgport, err = admindb.GetSetting(dbConn, "PG-PORT") if err != nil { logit.Error.Println(err.Error()) return err } sleepSetting, err = admindb.GetSetting(dbConn, "SLEEP-PROV") if err != nil { logit.Error.Println("Provision:SLEEP-PROV setting error " + err.Error()) return err } var sleepTime time.Duration sleepTime, err = time.ParseDuration(sleepSetting.Value) fqdn := params.ContainerName + "." + domainname.Value //we are depending on a DNS entry being created shortly after //creating the node in Docker //you might need to wait here until you can reach the new node's agent logit.Info.Println("PROFILE waiting till DNS ready") err = waitTillReady(fqdn, sleepTime) if err != nil { logit.Error.Println(err.Error()) return err } logit.Info.Println("checkpt 1") if standby { logit.Info.Println("standby node being created, will not initdb") } else { if params.RestoreJob != "" { logit.Info.Println("RestoreJob found, not doing initdb...") } else { //initdb on the new node logit.Info.Println("PROFILE running initdb on the node") var resp cpmcontainerapi.InitdbResponse logit.Info.Println("checkpt 2") resp, err = cpmcontainerapi.InitdbClient(fqdn) if err != nil { logit.Error.Println(err.Error()) return err } logit.Info.Println("checkpt 3") logit.Info.Println("initdb output was" + resp.Output) //create postgresql.conf var data string var mode = "standalone" info := new(template.PostgresqlParameters) info.PG_PORT = pgport.Value info.CLUSTER_TYPE = "" err = template.GetTuningParms(dbConn, params.Profile, info) if err != nil { logit.Error.Println(err.Error()) return err } logit.Info.Println("after GetTuning call with MWM = " + info.TUNE_MWM) data, err = template.Postgresql(mode, info) if err != nil { logit.Error.Println(err.Error()) return err } logit.Info.Println("provision chkpt 4") //place postgresql.conf on new node logit.Info.Println("fqdn is " + fqdn) logit.Info.Println("postgresql.conf file is " + data) _, err = cpmcontainerapi.RemoteWritefileClient("/pgdata/postgresql.conf", data, fqdn) if err != nil { logit.Error.Println(err.Error()) return err } logit.Info.Println("provision chkpt 5") //create pg_hba.conf rules := make([]template.Rule, 0) data, err = template.Hba(dbConn, mode, params.ContainerName, pgport.Value, "", domainname.Value, rules) if err != nil { logit.Error.Println(err.Error()) return err } logit.Info.Println("provision chkpt 6") //place pg_hba.conf on new node _, err = cpmcontainerapi.RemoteWritefileClient("/pgdata/pg_hba.conf", data, fqdn) if err != nil { logit.Error.Println(err.Error()) return err } logit.Info.Println("PROFILE templates all built and copied to node") } //start pg on new node var startResp cpmcontainerapi.StartPGResponse startResp, err = cpmcontainerapi.StartPGClient(fqdn) if err != nil { logit.Error.Println(err.Error()) return err } logit.Info.Println("startpg output was" + startResp.Output) //seed database with initial objects var seedResp cpmcontainerapi.SeedResponse seedResp, err = cpmcontainerapi.SeedClient(fqdn) if err != nil { logit.Error.Println(err.Error()) return err } logit.Info.Println("seed output was" + seedResp.Output) } logit.Info.Println("PROFILE node provisioning completed") return nil }
func main() { startTime = time.Now() startTimeString = startTime.String() logit.Info.Println("backrestrestore running....") err := getEnvVars() if err != nil { logit.Error.Println(err.Error()) return } s := task.TaskStatus{} eDuration := time.Since(startTime) s.StartTime = startTimeString s.ElapsedTime = eDuration.String() s.Status = "initializing" s.TaskSize = "n/a" sendStats(&s) logit.Info.Println("giving DNS time to register the backup job....sleeping for 7 secs") sleepTime, _ := time.ParseDuration("7s") time.Sleep(sleepTime) stats("restore job starting") stats("stopping postgres...") var stopResponse cpmcontainerapi.StopPGResponse stopResponse, err = cpmcontainerapi.StopPGClient(restoreContainerName) if err != nil { logit.Error.Println(err.Error()) s.Status = "error in stopPG" sendStats(&s) os.Exit(1) } logit.Info.Println("StopPG....") logit.Info.Println(stopResponse.Output) logit.Info.Println(stopResponse.Status) logit.Info.Println("End of StopPG....") //wait for postgres to quit time.Sleep(sleepTime) stats("performing the restore...") //perform the restore restoreRequest := cpmcontainerapi.RestoreRequest{} restoreRequest.RestoreRemotePath = restoreRemotePath restoreRequest.RestoreRemoteHost = restoreRemoteHost restoreRequest.RestoreRemoteUser = restoreRemoteUser restoreRequest.RestoreDbUser = restoreDbUser restoreRequest.RestoreDbPass = restoreDbPass restoreRequest.RestoreSet = restoreSet var restoreResponse cpmcontainerapi.RestoreResponse restoreResponse, err = cpmcontainerapi.RestoreClient(restoreContainerName, &restoreRequest) if err != nil { logit.Error.Println(err.Error()) s.Status = "error in restore" sendStats(&s) os.Exit(1) } logit.Info.Println("Restore....") logit.Info.Println(restoreResponse.Output) logit.Info.Println(restoreResponse.Status) logit.Info.Println("End of Restore....") stats("starting postgres after the restore...") var startResponse cpmcontainerapi.StartPGResponse startResponse, err = cpmcontainerapi.StartPGClient(restoreContainerName) if err != nil { logit.Error.Println(err.Error()) s.Status = "error in startPG" sendStats(&s) os.Exit(1) } logit.Info.Println("StartPG....") logit.Info.Println(startResponse.Output) logit.Info.Println(startResponse.Status) logit.Info.Println("End of StartPG....") stats("seeding the database...") var seedResponse cpmcontainerapi.SeedResponse seedResponse, err = cpmcontainerapi.SeedClient(restoreContainerName) if err != nil { logit.Error.Println(err.Error()) s.Status = "error in Seed" sendStats(&s) os.Exit(1) } logit.Info.Println("Seed....") logit.Info.Println(seedResponse.Output) logit.Info.Println(seedResponse.Status) logit.Info.Println("End of Seed....") //send final stats to backup finalstats("restore completed") }