Use environment namespace for power state, don't duplicate them across server

This commit is contained in:
Dane Everitt
2020-08-19 18:58:48 -07:00
parent b9fb922e91
commit 4d3a860604
13 changed files with 51 additions and 55 deletions

View File

@@ -8,7 +8,7 @@ import (
"github.com/docker/docker/client"
"github.com/pkg/errors"
"github.com/pterodactyl/wings/api"
"github.com/pterodactyl/wings/system"
"github.com/pterodactyl/wings/environment"
"os"
"strings"
"time"
@@ -57,8 +57,8 @@ func (e *Environment) Start() error {
// If we don't set it to stopping first, you'll trigger crash detection which
// we don't want to do at this point since it'll just immediately try to do the
// exact same action that lead to it crashing in the first place...
e.setState(system.ProcessStoppingState)
e.setState(system.ProcessOfflineState)
e.setState(environment.ProcessStoppingState)
e.setState(environment.ProcessOfflineState)
}
}()
@@ -74,7 +74,7 @@ func (e *Environment) Start() error {
} else {
// If the server is running update our internal state and continue on with the attach.
if c.State.Running {
e.setState(system.ProcessRunningState)
e.setState(environment.ProcessRunningState)
return e.Attach()
}
@@ -89,7 +89,7 @@ func (e *Environment) Start() error {
}
}
e.setState(system.ProcessStartingState)
e.setState(environment.ProcessStartingState)
// Set this to true for now, we will set it to false once we reach the
// end of this chain.
@@ -136,8 +136,8 @@ func (e *Environment) Stop() error {
// If the process is already offline don't switch it back to stopping. Just leave it how
// it is and continue through to the stop handling for the process.
if e.State() != system.ProcessOfflineState {
e.setState(system.ProcessStoppingState)
if e.State() != environment.ProcessOfflineState {
e.setState(environment.ProcessStoppingState)
}
// Only attempt to send the stop command to the instance if we are actually attached to
@@ -153,7 +153,7 @@ func (e *Environment) Stop() error {
// an error.
if client.IsErrNotFound(err) {
e.SetStream(nil)
e.setState(system.ProcessOfflineState)
e.setState(environment.ProcessOfflineState)
return nil
}
@@ -209,16 +209,16 @@ func (e *Environment) Terminate(signal os.Signal) error {
// If the container is not running but we're not already in a stopped state go ahead
// and update things to indicate we should be completely stopped now. Set to stopping
// first so crash detection is not triggered.
if e.State() != system.ProcessOfflineState {
e.setState(system.ProcessStoppingState)
e.setState(system.ProcessOfflineState)
if e.State() != environment.ProcessOfflineState {
e.setState(environment.ProcessStoppingState)
e.setState(environment.ProcessOfflineState)
}
return nil
}
// We set it to stopping than offline to prevent crash detection from being triggeree.
e.setState(system.ProcessStoppingState)
e.setState(environment.ProcessStoppingState)
sig := strings.TrimSuffix(strings.TrimPrefix(signal.String(), "signal "), "ed")
@@ -226,7 +226,7 @@ func (e *Environment) Terminate(signal os.Signal) error {
return err
}
e.setState(system.ProcessOfflineState)
e.setState(environment.ProcessOfflineState)
return nil
}