mirror of
https://github.com/idanoo/autobrr
synced 2025-07-22 16:29:12 +00:00
refactor: streamline shutdown signal handling (#1248)
This commit is contained in:
parent
fc63d46e71
commit
558bc045ab
1 changed files with 8 additions and 14 deletions
|
@ -141,7 +141,7 @@ func main() {
|
|||
}()
|
||||
|
||||
sigCh := make(chan os.Signal, 1)
|
||||
signal.Notify(sigCh, syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGKILL, syscall.SIGTERM)
|
||||
signal.Notify(sigCh, syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM)
|
||||
|
||||
srv := server.NewServer(log, cfg.Config, ircService, indexerService, feedService, schedulingService, updateService)
|
||||
if err := srv.Start(); err != nil {
|
||||
|
@ -150,20 +150,14 @@ func main() {
|
|||
}
|
||||
|
||||
for sig := range sigCh {
|
||||
switch sig {
|
||||
case syscall.SIGHUP:
|
||||
log.Log().Msg("shutting down server sighup")
|
||||
srv.Shutdown()
|
||||
db.Close()
|
||||
os.Exit(1)
|
||||
case syscall.SIGINT, syscall.SIGQUIT:
|
||||
srv.Shutdown()
|
||||
db.Close()
|
||||
os.Exit(1)
|
||||
case syscall.SIGKILL, syscall.SIGTERM:
|
||||
srv.Shutdown()
|
||||
db.Close()
|
||||
log.Info().Msgf("received signal: %v, shutting down server.", sig)
|
||||
|
||||
srv.Shutdown()
|
||||
|
||||
if err := db.Close(); err != nil {
|
||||
log.Error().Err(err).Msg("failed to close the database connection properly")
|
||||
os.Exit(1)
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue