Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/keeper/cmd/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,7 @@ func (p *PostgresKeeper) postgresKeeperSM(pctx context.Context) {
}
}

if err = pgm.StopIfStarted(true); err != nil {
if err = pgm.StopIfStarted(true, 900); err != nil {
log.Errorw("failed to stop pg instance", zap.Error(err))
return
}
Expand Down
15 changes: 10 additions & 5 deletions internal/postgresql/postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,14 +379,19 @@ func (p *Manager) start(args ...string) error {
}

// Stop tries to stop an instance. An error will be returned if the instance isn't started, stop fails or
// times out (60 second).
func (p *Manager) Stop(fast bool) error {
// times out (60 second). Optional timeout parameter can be provided.
func (p *Manager) Stop(fast bool, timeout ...int) error {
log.Infow("stopping database")
name := filepath.Join(p.pgBinPath, "pg_ctl")
cmd := exec.Command(name, "stop", "-w", "-D", p.dataDir, "-o", "-c unix_socket_directories="+common.PgUnixSocketDirectories)
if fast {
cmd.Args = append(cmd.Args, "-m", "fast")
}

if len(timeout) > 0 && timeout[0] > 0 {
timeoutSeconds := timeout[0]
cmd.Args = append(cmd.Args, "-t", strconv.Itoa(timeoutSeconds))
}
log.Debugw("execing cmd", "cmd", cmd)

// Pipe command's std[err|out] to parent.
Expand Down Expand Up @@ -443,8 +448,8 @@ func (p *Manager) Reload() error {
}

// StopIfStarted checks if the instance is started, then calls stop and
// then check if the instance is really stopped
func (p *Manager) StopIfStarted(fast bool) error {
// then check if the instance is really stopped. Optional timeout parameter can be provided.
func (p *Manager) StopIfStarted(fast bool, timeout ...int) error {
// Stop will return an error if the instance isn't started, so first check
// if it's started
started, err := p.IsStarted()
Expand All @@ -459,7 +464,7 @@ func (p *Manager) StopIfStarted(fast bool) error {
if !started {
return nil
}
if err = p.Stop(fast); err != nil {
if err = p.Stop(fast, timeout...); err != nil {
return err
}
started, err = p.IsStarted()
Expand Down