Skip to content

Commit

Permalink
Kill database after upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 committed Aug 24, 2023
1 parent a335f66 commit 925f6a5
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions cmd/internal/database/meilisearch/meilisearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path"
"path/filepath"
"strings"
"syscall"
"time"

"github.com/Masterminds/semver/v3"
Expand Down Expand Up @@ -168,17 +169,29 @@ func (db *Meilisearch) Upgrade() error {
return fmt.Errorf("unable to rename dbdir: %w", err)
}

args := []string{"--ignore-dump-if-db-exists", "--import-dump", path.Join(db.dumpdir, latestStableDump), "--master-key", db.apikey}
db.log.Infow("execute meilisearch", "args", args)
var cmd *exec.Cmd
go func() {
args := []string{"--import-dump", path.Join(db.dumpdir, latestStableDump), "--master-key", db.apikey}
db.log.Infow("execute meilisearch", "args", args)

cmd = exec.Command(meilisearchCmd, args...) // nolint:gosec
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
if err != nil {
db.log.Errorw("unable import latest dump, skipping upgrade", "error", err)
}
}()

retry.Do(func() error {
v, err := db.client.Version()
if err != nil {
return err
}
db.log.Infow("meilisearch started after upgrade, killing it", "version", v)
return cmd.Process.Signal(syscall.SIGTERM)
})

cmd := exec.Command(meilisearchCmd, args...) // nolint:gosec
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
if err != nil {
db.log.Errorw("unable import latest dump, skipping upgrade", "error", err)
return nil
}
db.log.Infow("upgrade done and new data in place", "took", time.Since(start))
return nil
}
Expand Down

0 comments on commit 925f6a5

Please sign in to comment.