From 16467fa7ffe17dcc502b5a35fb88c4a6a8bb2a78 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sun, 19 Jul 2020 17:09:38 -0700 Subject: [PATCH] Code cleanup --- installer/installer.go | 2 +- server/loader.go | 13 +++++++++---- server/state.go | 4 +++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/installer/installer.go b/installer/installer.go index 6ca95fd..ddebdf2 100644 --- a/installer/installer.go +++ b/installer/installer.go @@ -80,7 +80,7 @@ func New(data []byte) (*Installer, error) { // Create a new server instance using the configuration we wrote to the disk // so that everything gets instantiated correctly on the struct. - s, err := server.FromConfiguration(c) + s, err := server.FromConfiguration(c, true) return &Installer{ server: s, diff --git a/server/loader.go b/server/loader.go index 55b1a32..a98acba 100644 --- a/server/loader.go +++ b/server/loader.go @@ -43,18 +43,21 @@ func LoadDirectory() error { return errors.New(rerr.String()) } + log.Debug("retrieving cached server states from disk") states, err := getServerStates() if err != nil { return errors.WithStack(err) } + log.WithField("total_configs", len(configs)).Debug("looping over received configurations from API") for uuid, data := range configs { wg.Add() go func(uuid string, data *api.ServerConfigurationResponse) { defer wg.Done() - s, err := FromConfiguration(data) + log.WithField("uuid", uuid).Debug("creating server object from configuration") + s, err := FromConfiguration(data, false) if err != nil { log.WithField("server", uuid).WithField("error", err).Error("failed to load server, skipping...") return @@ -79,7 +82,7 @@ func LoadDirectory() error { // Initializes a server using a data byte array. This will be marshaled into the // given struct using a YAML marshaler. This will also configure the given environment // for a server. -func FromConfiguration(data *api.ServerConfigurationResponse) (*Server, error) { +func FromConfiguration(data *api.ServerConfigurationResponse, sync bool) (*Server, error) { cfg := Configuration{} if err := defaults.Set(&cfg); err != nil { return nil, err @@ -111,8 +114,10 @@ func FromConfiguration(data *api.ServerConfigurationResponse) (*Server, error) { } // Forces the configuration to be synced with the panel. - if err := s.SyncWithConfiguration(data); err != nil { - return nil, err + if sync { + if err := s.SyncWithConfiguration(data); err != nil { + return nil, err + } } return s, nil diff --git a/server/state.go b/server/state.go index aa24306..705d524 100644 --- a/server/state.go +++ b/server/state.go @@ -133,5 +133,7 @@ func (s *Server) GetState() string { // environment state, it is simply the tracked state from this daemon instance, and // not the response from Docker. func (s *Server) IsRunning() bool { - return s.GetState() == ProcessRunningState || s.GetState() == ProcessStartingState + st := s.GetState() + + return st == ProcessRunningState || st == ProcessStartingState }