Very basic state management for servers

This commit is contained in:
Dane Everitt 2019-04-07 15:20:21 -07:00
parent 729a84b4bf
commit 7c0acf3f60
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53

View File

@ -2,6 +2,7 @@ package server
import (
"github.com/patrickmn/go-cache"
"github.com/pkg/errors"
"github.com/pterodactyl/wings/config"
"github.com/remeh/sizedwaitgroup"
"go.uber.org/zap"
@ -13,6 +14,16 @@ import (
"time"
)
// Defines states that identify if the server is running or not.
const (
StateOffline = "off"
StateStarting = "starting"
StateRunning = "running"
StateStopping = "stopping"
)
type ProcessState string
// High level definition for a server instance being controlled by Wings.
type Server struct {
// The unique identifier for the server that should be used when referencing
@ -25,7 +36,7 @@ type Server struct {
Suspended bool `json:"suspended"`
// The power state of the server.
State int `json:"state"`
State ProcessState `json:"state"`
// The command that should be used when booting up the server instance.
Invocation string `json:"invocation"`
@ -219,6 +230,22 @@ func (s *Server) Cache() *cache.Cache {
return s.cache
}
// Sets the state of the server process.
func (s *Server) SetState(state ProcessState) error {
switch state {
case StateOffline:
case StateRunning:
case StateStarting:
case StateStopping:
s.State = state
break
default:
return errors.New("invalid state provided")
}
return nil
}
// Determine if the server is bootable in it's current state or not. This will not
// indicate why a server is not bootable, only if it is.
func (s *Server) IsBootable() bool {