From 5fd138e188da6ef5a0296a7aad0a926ae3940174 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Fri, 3 Apr 2020 14:52:24 -0700 Subject: [PATCH] Add support for restarting a server instance --- http.go | 19 ++++++++++++++++++- websocket.go | 8 +++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/http.go b/http.go index f6e7c09..02f282d 100644 --- a/http.go +++ b/http.go @@ -190,7 +190,24 @@ func (rt *Router) routeServerPower(w http.ResponseWriter, r *http.Request, ps ht } break 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": if err := s.Environment.Terminate(os.Kill); err != nil { zap.S().Errorw( diff --git a/websocket.go b/websocket.go index 062d23a..3bfc144 100644 --- a/websocket.go +++ b/websocket.go @@ -375,7 +375,13 @@ func (wsh *WebsocketHandler) HandleInbound(m WebsocketMessage) error { case "stop": return wsh.Server.Environment.Stop() case "restart": - return nil + { + if err := wsh.Server.Environment.WaitForStop(60, false); err != nil { + return err + } + + return wsh.Server.Environment.Start() + } case "kill": return wsh.Server.Environment.Terminate(os.Kill) }