Add support for restarting a server instance

This commit is contained in:
Dane Everitt 2020-04-03 14:52:24 -07:00
parent 019d028011
commit 5fd138e188
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
2 changed files with 25 additions and 2 deletions

19
http.go
View File

@ -190,7 +190,24 @@ func (rt *Router) routeServerPower(w http.ResponseWriter, r *http.Request, ps ht
} }
break break
case "restart": case "restart":
break if err := s.Environment.WaitForStop(60, false); err != nil {
zap.S().Errorw(
"encountered unexpected error waiting for server process to stop",
zap.Error(err),
zap.String("server", s.Uuid),
zap.String("action", "restart"),
)
}
if err := s.Environment.Start(); err != nil {
zap.S().Errorw(
"encountered unexpected error starting server process",
zap.Error(err),
zap.String("server", s.Uuid),
zap.String("action", "restart"),
)
}
break;
case "kill": case "kill":
if err := s.Environment.Terminate(os.Kill); err != nil { if err := s.Environment.Terminate(os.Kill); err != nil {
zap.S().Errorw( zap.S().Errorw(

View File

@ -375,7 +375,13 @@ func (wsh *WebsocketHandler) HandleInbound(m WebsocketMessage) error {
case "stop": case "stop":
return wsh.Server.Environment.Stop() return wsh.Server.Environment.Stop()
case "restart": case "restart":
return nil {
if err := wsh.Server.Environment.WaitForStop(60, false); err != nil {
return err
}
return wsh.Server.Environment.Start()
}
case "kill": case "kill":
return wsh.Server.Environment.Terminate(os.Kill) return wsh.Server.Environment.Terminate(os.Kill)
} }