diff --git a/environment/docker/environment.go b/environment/docker/environment.go index 296fe6d..c8b6448 100644 --- a/environment/docker/environment.go +++ b/environment/docker/environment.go @@ -2,6 +2,11 @@ package docker import ( "context" + "fmt" + "io" + "sync" + + "emperror.dev/errors" "github.com/apex/log" "github.com/docker/docker/api/types" "github.com/docker/docker/client" @@ -9,8 +14,6 @@ import ( "github.com/pterodactyl/wings/environment" "github.com/pterodactyl/wings/events" "github.com/pterodactyl/wings/system" - "io" - "sync" ) type Metadata struct { @@ -187,3 +190,26 @@ func (e *Environment) SetImage(i string) { e.meta.Image = i } + +func (e *Environment) State() string { + return e.st.Load() +} + +// SetState sets the state of the environment. This emits an event that server's +// can hook into to take their own actions and track their own state based on +// the environment. +func (e *Environment) SetState(state string) { + if state != environment.ProcessOfflineState && + state != environment.ProcessStartingState && + state != environment.ProcessRunningState && + state != environment.ProcessStoppingState { + panic(errors.New(fmt.Sprintf("invalid server state received: %s", state))) + } + + // Emit the event to any listeners that are currently registered. + if e.State() != state { + // If the state changed make sure we update the internal tracking to note that. + e.st.Store(state) + e.Events().Publish(environment.StateChangeEvent, state) + } +} diff --git a/environment/docker/power.go b/environment/docker/power.go index 0663bab..d818756 100644 --- a/environment/docker/power.go +++ b/environment/docker/power.go @@ -164,9 +164,10 @@ func (e *Environment) Stop() error { return nil } -// Attempts to gracefully stop a server using the defined stop command. If the server -// does not stop after seconds have passed, an error will be returned, or the instance -// will be terminated forcefully depending on the value of the second argument. +// WaitForStop attempts to gracefully stop a server using the defined stop +// command. If the server does not stop after seconds have passed, an error will +// be returned, or the instance will be terminated forcefully depending on the +// value of the second argument. func (e *Environment) WaitForStop(seconds uint, terminate bool) error { if err := e.Stop(); err != nil { return err diff --git a/environment/docker/state.go b/environment/docker/state.go deleted file mode 100644 index ee03443..0000000 --- a/environment/docker/state.go +++ /dev/null @@ -1,29 +0,0 @@ -package docker - -import ( - "emperror.dev/errors" - "fmt" - "github.com/pterodactyl/wings/environment" -) - -func (e *Environment) State() string { - return e.st.Load() -} - -// Sets the state of the environment. This emits an event that server's can hook into to -// take their own actions and track their own state based on the environment. -func (e *Environment) SetState(state string) { - if state != environment.ProcessOfflineState && - state != environment.ProcessStartingState && - state != environment.ProcessRunningState && - state != environment.ProcessStoppingState { - panic(errors.New(fmt.Sprintf("invalid server state received: %s", state))) - } - - // Emit the event to any listeners that are currently registered. - if e.State() != state { - // If the state changed make sure we update the internal tracking to note that. - e.st.Store(state) - e.Events().Publish(environment.StateChangeEvent, state) - } -}