mirror of
https://github.com/stashapp/stash.git
synced 2025-12-15 21:03:22 +01:00
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:
parent
651d2e6373
commit
a3f38d8edf
3 changed files with 20 additions and 0 deletions
6
main.go
6
main.go
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue