Don't actually try to start a server that is already running

This commit is contained in:
Dane Everitt 2020-08-19 19:20:46 -07:00
parent 9d2321f357
commit 43d8bd656a
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
2 changed files with 14 additions and 6 deletions

View File

@ -199,8 +199,10 @@ func rootCmdRun(*cobra.Command, []string) {
// is that it was running, but we see that the container process is not currently running.
if r || (!r && s.IsRunning()) {
s.Log().Info("detected server is running, re-attaching to process...")
if err := s.HandlePowerAction(server.PowerActionStart); err != nil {
s.Log().WithField("error", errors.WithStack(err)).Warn("failed to properly start server detected as already running")
s.SetState(environment.ProcessRunningState)
if err := s.Environment.Attach(); err != nil {
s.Log().WithField("error", errors.WithStack(err)).Warn("failed to attach to running server environment")
}
return

View File

@ -1,6 +1,7 @@
package server
import (
"fmt"
"github.com/apex/log"
"github.com/creasty/defaults"
"github.com/gammazero/workerpool"
@ -27,6 +28,7 @@ func LoadDirectory() error {
return errors.New("cannot call LoadDirectory with a non-nil collection")
}
log.Info("fetching list of servers from API")
configs, rerr, err := api.NewRequester().GetAllServerConfigurations()
if err != nil || rerr != nil {
if err != nil {
@ -39,10 +41,11 @@ func LoadDirectory() error {
log.Debug("retrieving cached server states from disk")
states, err := getServerStates()
if err != nil {
return errors.WithStack(err)
log.WithField("error", errors.WithStack(err)).Error("failed to retrieve locally cached server states from disk, assuming all servers in offline state")
}
log.WithField("total_configs", len(configs)).Debug("looping over received configurations from API")
start := time.Now()
log.WithField("total_configs", len(configs)).Info("processing servers returned by the API")
pool := workerpool.New(runtime.NumCPU())
for uuid, data := range configs {
@ -50,7 +53,7 @@ func LoadDirectory() error {
data := data
pool.Submit(func() {
log.WithField("uuid", uuid).Debug("creating server object from configuration")
log.WithField("server", uuid).Info("creating new server object from API response")
s, err := FromConfiguration(data)
if err != nil {
log.WithField("server", uuid).WithField("error", err).Error("failed to load server, skipping...")
@ -58,8 +61,8 @@ func LoadDirectory() error {
}
if state, exists := states[s.Id()]; exists {
s.Log().WithField("state", state).Debug("found existing server state in cache file; re-instantiating server state")
s.SetState(state)
s.Log().WithField("state", s.GetState()).Debug("loaded server state from cache file")
}
servers.Add(s)
@ -70,6 +73,9 @@ func LoadDirectory() error {
// before continuing.
pool.StopWait()
diff := time.Now().Sub(start)
log.WithField("duration", fmt.Sprintf("%s", diff)).Info("finished processing server configurations")
return nil
}