From ffb6bd72ef10aba7a4dad5bd36aaa3b6a9951e17 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Tue, 10 Nov 2020 21:21:20 -0800 Subject: [PATCH] Don't accidentally reset a server's state when starting it after a system reboot; closes pterodactyl/panel#2695 --- cmd/root.go | 11 +++++------ environment/docker/stats.go | 9 ++++----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 34a79a5..ea5de8e 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -250,13 +250,12 @@ func rootCmdRun(*cobra.Command, []string) { if err := s.Environment.Attach(); err != nil { s.Log().WithField("error", errors.WithStackIf(err)).Warn("failed to attach to running server environment") } - - return + } else { + // At this point we've determined that the server should indeed be in an offline state, so we'll + // make a call to set that state just to ensure we don't ever accidentally end up with some invalid + // state being tracked. + s.Environment.SetState(environment.ProcessOfflineState) } - - // Addresses potentially invalid data in the stored file that can cause Wings to lose - // track of what the actual server state is. - s.Environment.SetState(environment.ProcessOfflineState) }) } diff --git a/environment/docker/stats.go b/environment/docker/stats.go index 7ff389f..b00a31e 100644 --- a/environment/docker/stats.go +++ b/environment/docker/stats.go @@ -15,15 +15,14 @@ import ( // Attach to the instance and then automatically emit an event whenever the resource usage for the // server process changes. func (e *Environment) pollResources(ctx context.Context) error { - l := log.WithField("container_id", e.Id) - - l.Debug("starting resource polling for container") - defer l.Debug("stopped resource polling for container") - if e.st.Load() == environment.ProcessOfflineState { return errors.New("cannot enable resource polling on a stopped server") } + l := log.WithField("container_id", e.Id) + l.Debug("starting resource polling for container") + defer l.Debug("stopped resource polling for container") + stats, err := e.client.ContainerStats(context.Background(), e.Id, true) if err != nil { return errors.WithStackIf(err)