Use environment namespace for power state, don't duplicate them across server
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/pterodactyl/wings/config"
|
||||
"github.com/pterodactyl/wings/environment"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
@@ -44,7 +45,7 @@ func (s *Server) handleServerCrash() error {
|
||||
// No point in doing anything here if the server isn't currently offline, there
|
||||
// is no reason to do a crash detection event. If the server crash detection is
|
||||
// disabled we want to skip anything after this as well.
|
||||
if s.GetState() != ProcessOfflineState || !s.Config().CrashDetectionEnabled {
|
||||
if s.GetState() != environment.ProcessOfflineState || !s.Config().CrashDetectionEnabled {
|
||||
if !s.Config().CrashDetectionEnabled {
|
||||
s.Log().Debug("server triggered crash detection but handler is disabled for server process")
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/pterodactyl/wings/api"
|
||||
"github.com/pterodactyl/wings/config"
|
||||
"github.com/pterodactyl/wings/environment"
|
||||
"golang.org/x/sync/semaphore"
|
||||
"html/template"
|
||||
"io"
|
||||
@@ -58,9 +59,8 @@ func (s *Server) Install(sync bool) error {
|
||||
|
||||
// Some how these publish events are sent to clients in reverse order,
|
||||
// this is probably due to channels having the most recently sent item first.
|
||||
|
||||
// Ensure that the server is marked as offline.
|
||||
s.Events().Publish(StatusEvent, ProcessOfflineState)
|
||||
s.Events().Publish(StatusEvent, environment.ProcessOfflineState)
|
||||
|
||||
// Push an event to the websocket so we can auto-refresh the information in the panel once
|
||||
// the install is completed.
|
||||
@@ -72,7 +72,7 @@ func (s *Server) Install(sync bool) error {
|
||||
// Reinstalls a server's software by utilizing the install script for the server egg. This
|
||||
// does not touch any existing files for the server, other than what the script modifies.
|
||||
func (s *Server) Reinstall() error {
|
||||
if s.GetState() != ProcessOfflineState {
|
||||
if s.GetState() != environment.ProcessOfflineState {
|
||||
s.Log().Debug("waiting for server instance to enter a stopped state")
|
||||
if err := s.Environment.WaitForStop(10, true); err != nil {
|
||||
return err
|
||||
|
||||
@@ -66,7 +66,7 @@ func (s *Server) onConsoleOutput(data string) {
|
||||
processConfiguration := s.ProcessConfiguration()
|
||||
|
||||
// Check if the server is currently starting.
|
||||
if s.GetState() == ProcessStartingState {
|
||||
if s.GetState() == environment.ProcessStartingState {
|
||||
// Check if we should strip ansi color codes.
|
||||
if processConfiguration.Startup.StripAnsi {
|
||||
// Strip ansi color codes from the data string.
|
||||
@@ -87,7 +87,7 @@ func (s *Server) onConsoleOutput(data string) {
|
||||
// If the specific line of output is one that would mark the server as started,
|
||||
// set the server to that state. Only do this if the server is not currently stopped
|
||||
// or stopping.
|
||||
_ = s.SetState(ProcessRunningState)
|
||||
_ = s.SetState(environment.ProcessRunningState)
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -99,7 +99,7 @@ func (s *Server) onConsoleOutput(data string) {
|
||||
stop := processConfiguration.Stop
|
||||
|
||||
if stop.Type == api.ProcessStopCommand && data == stop.Value {
|
||||
_ = s.SetState(ProcessStoppingState)
|
||||
_ = s.SetState(environment.ProcessOfflineState)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/pterodactyl/wings/config"
|
||||
"github.com/pterodactyl/wings/system"
|
||||
"github.com/pterodactyl/wings/environment"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
@@ -14,13 +14,6 @@ import (
|
||||
|
||||
var stateMutex sync.Mutex
|
||||
|
||||
const (
|
||||
ProcessOfflineState = "offline"
|
||||
ProcessStartingState = "starting"
|
||||
ProcessRunningState = "running"
|
||||
ProcessStoppingState = "stopping"
|
||||
)
|
||||
|
||||
// Returns the state of the servers.
|
||||
func getServerStates() (map[string]string, error) {
|
||||
// Request a lock after we check if the file exists.
|
||||
@@ -71,7 +64,10 @@ func saveServerStates() error {
|
||||
// Sets the state of the server internally. This function handles crash detection as
|
||||
// well as reporting to event listeners for the server.
|
||||
func (s *Server) SetState(state string) error {
|
||||
if state != ProcessOfflineState && state != ProcessStartingState && state != ProcessRunningState && state != ProcessStoppingState {
|
||||
if state != environment.ProcessOfflineState &&
|
||||
state != environment.ProcessStartingState &&
|
||||
state != environment.ProcessRunningState &&
|
||||
state != environment.ProcessStoppingState {
|
||||
return errors.New(fmt.Sprintf("invalid server state received: %s", state))
|
||||
}
|
||||
|
||||
@@ -102,7 +98,7 @@ func (s *Server) SetState(state string) error {
|
||||
|
||||
// Reset the resource usage to 0 when the process fully stops so that all of the UI
|
||||
// views in the Panel correctly display 0.
|
||||
if state == system.ProcessOfflineState {
|
||||
if state == environment.ProcessOfflineState {
|
||||
s.resources.mu.Lock()
|
||||
s.resources.Empty()
|
||||
s.resources.mu.Unlock()
|
||||
@@ -118,7 +114,7 @@ func (s *Server) SetState(state string) error {
|
||||
// automatically attempt to start the process back up for the user. This is done in a
|
||||
// separate thread as to not block any actions currently taking place in the flow
|
||||
// that called this function.
|
||||
if (prevState == ProcessStartingState || prevState == ProcessRunningState) && s.GetState() == ProcessOfflineState {
|
||||
if (prevState == environment.ProcessStartingState || prevState == environment.ProcessRunningState) && s.GetState() == environment.ProcessOfflineState {
|
||||
s.Log().Info("detected server as entering a crashed state; running crash handler")
|
||||
|
||||
go func(server *Server) {
|
||||
@@ -146,5 +142,5 @@ func (s *Server) GetState() string {
|
||||
func (s *Server) IsRunning() bool {
|
||||
st := s.GetState()
|
||||
|
||||
return st == ProcessRunningState || st == ProcessStartingState
|
||||
return st == environment.ProcessRunningState || st == environment.ProcessStartingState
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"github.com/buger/jsonparser"
|
||||
"github.com/imdario/mergo"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/pterodactyl/wings/environment"
|
||||
)
|
||||
|
||||
// Merges data passed through in JSON form into the existing server object.
|
||||
@@ -112,7 +113,7 @@ func (s *Server) UpdateDataStructure(data []byte, background bool) error {
|
||||
func (s *Server) runBackgroundActions() {
|
||||
// Check if the s is now suspended, and if so and the process is not terminated
|
||||
// yet, do it immediately.
|
||||
if s.IsSuspended() && s.GetState() != ProcessOfflineState {
|
||||
if s.IsSuspended() && s.GetState() != environment.ProcessOfflineState {
|
||||
s.Log().Info("server suspended with running process state, terminating now")
|
||||
|
||||
if err := s.Environment.WaitForStop(10, true); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user