X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/54849feb0cf30bd3d78f14f1a41e6bc464fb80d6..ab832f5a22db3debbd13cacbee9cf69d68d7075c:/lib/boot/postgresql.go diff --git a/lib/boot/postgresql.go b/lib/boot/postgresql.go index fc23eb9132..d105b0b623 100644 --- a/lib/boot/postgresql.go +++ b/lib/boot/postgresql.go @@ -48,7 +48,7 @@ func (runPostgreSQL) Run(ctx context.Context, fail func(error), super *Superviso } buf := bytes.NewBuffer(nil) - err = super.RunProgram(ctx, super.tempdir, buf, nil, "pg_config", "--bindir") + err = super.RunProgram(ctx, super.tempdir, runOptions{output: buf}, "pg_config", "--bindir") if err != nil { return err } @@ -60,12 +60,13 @@ func (runPostgreSQL) Run(ctx context.Context, fail func(error), super *Superviso return err } prog, args := filepath.Join(bindir, "initdb"), []string{"-D", datadir, "-E", "utf8"} + opts := runOptions{} if iamroot { postgresUser, err := user.Lookup("postgres") if err != nil { return fmt.Errorf("user.Lookup(\"postgres\"): %s", err) } - postgresUid, err := strconv.Atoi(postgresUser.Uid) + postgresUID, err := strconv.Atoi(postgresUser.Uid) if err != nil { return fmt.Errorf("user.Lookup(\"postgres\"): non-numeric uid?: %q", postgresUser.Uid) } @@ -81,29 +82,23 @@ func (runPostgreSQL) Run(ctx context.Context, fail func(error), super *Superviso if err != nil { return err } - err = os.Chown(datadir, postgresUid, 0) + err = os.Chown(datadir, postgresUID, 0) if err != nil { return err } - // We can't use "sudo -u" here because it creates an - // intermediate process that interferes with our - // ability to reliably kill postgres. The setuidgid - // program just calls exec without forking, so it - // doesn't have this problem. - args = append([]string{"postgres", prog}, args...) - prog = "setuidgid" - } - err = super.RunProgram(ctx, super.tempdir, nil, nil, prog, args...) + opts.user = "postgres" + } + err = super.RunProgram(ctx, super.tempdir, opts, prog, args...) if err != nil { return err } - err = super.RunProgram(ctx, super.tempdir, nil, nil, "cp", "server.crt", "server.key", datadir) + err = super.RunProgram(ctx, super.tempdir, runOptions{}, "cp", "server.crt", "server.key", datadir) if err != nil { return err } if iamroot { - err = super.RunProgram(ctx, super.tempdir, nil, nil, "chown", "postgres", datadir+"/server.crt", datadir+"/server.key") + err = super.RunProgram(ctx, super.tempdir, runOptions{}, "chown", "postgres", datadir+"/server.crt", datadir+"/server.key") if err != nil { return err } @@ -118,13 +113,14 @@ func (runPostgreSQL) Run(ctx context.Context, fail func(error), super *Superviso "-l", // enable ssl "-D", datadir, // data dir "-k", datadir, // socket dir + "-h", super.cluster.PostgreSQL.Connection["host"], "-p", super.cluster.PostgreSQL.Connection["port"], } + opts := runOptions{} if iamroot { - args = append([]string{"postgres", prog}, args...) - prog = "setuidgid" + opts.user = "postgres" } - fail(super.RunProgram(ctx, super.tempdir, nil, nil, prog, args...)) + fail(super.RunProgram(ctx, super.tempdir, opts, prog, args...)) }() for {