When stopping, close the database (#1686)

* When stopping, close the database

This patch is likely to cause errornous behavior in the application.
This is due to the fact that the application doesn't gracefully shut
down, but is forcefully terminated.

However, the purpose is to uncover what needs to be done, to make
it a more graceful shutdown.
This commit is contained in:
SmallCoccinelle 2021-09-07 06:28:40 +02:00 committed by GitHub
parent 651d2e6373
commit a3f38d8edf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 0 deletions

View file

@ -8,6 +8,7 @@ import (
"syscall"
"github.com/stashapp/stash/pkg/api"
"github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/manager"
_ "github.com/golang-migrate/migrate/v4/database/sqlite3"
@ -21,6 +22,11 @@ func main() {
// stop any profiling at exit
defer pprof.StopCPUProfile()
blockForever()
err := manager.GetInstance().Shutdown()
if err != nil {
logger.Errorf("Error when closing: %s", err)
}
}
func blockForever() {

View file

@ -89,6 +89,13 @@ func Initialize(databasePath string) error {
return nil
}
func Close() error {
WriteMu.Lock()
defer WriteMu.Unlock()
return DB.Close()
}
func open(databasePath string, disableForeignKeys bool) *sqlx.DB {
// https://github.com/mattn/go-sqlite3
url := "file:" + databasePath + "?_journal=WAL"

View file

@ -378,3 +378,10 @@ func (s *singleton) GetSystemStatus() *models.SystemStatus {
ConfigPath: &configFile,
}
}
// Shutdown gracefully stops the manager
func (s *singleton) Shutdown() error {
// TODO: Each part of the manager needs to gracefully stop at some point
// for now, we just close the database.
return database.Close()
}