Fix duplicate saving on quit

Slight refactor to split server stop and close functions
	Quit function explicitly sends SIGTERM
	SIGTERM doesn't trigger an os.Exit

	Bonus: Properly save the world on spawning the rover
This commit is contained in:
Marc Di Luzio 2020-06-07 18:06:34 +01:00
parent 141827fa57
commit 8586bdabd7
6 changed files with 28 additions and 13 deletions

View file

@ -164,8 +164,8 @@ func (s *Server) Run() {
}
}
// Close closes up the server
func (s *Server) Close() error {
// Stop will stop the current server
func (s *Server) Stop() error {
// Stop the cron
s.schedule.Stop()
@ -176,6 +176,11 @@ func (s *Server) Close() error {
return err
}
return nil
}
// Close waits until the server is finished and closes up shop
func (s *Server) Close() error {
// Wait until the server has shut down
s.sync.Wait()
@ -183,6 +188,17 @@ func (s *Server) Close() error {
return s.SaveAll()
}
// Close waits until the server is finished and closes up shop
func (s *Server) StopAndClose() error {
// Stop the server
if err := s.Stop(); err != nil {
return err
}
// Close and return
return s.Close()
}
// SaveWorld will save out the world file
func (s *Server) SaveWorld() error {
if s.persistence == PersistentData {