Very basic state management for servers
This commit is contained in:
parent
729a84b4bf
commit
7c0acf3f60
|
@ -2,6 +2,7 @@ package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/patrickmn/go-cache"
|
"github.com/patrickmn/go-cache"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/pterodactyl/wings/config"
|
"github.com/pterodactyl/wings/config"
|
||||||
"github.com/remeh/sizedwaitgroup"
|
"github.com/remeh/sizedwaitgroup"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
@ -13,6 +14,16 @@ import (
|
||||||
"time"
|
"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.
|
// High level definition for a server instance being controlled by Wings.
|
||||||
type Server struct {
|
type Server struct {
|
||||||
// The unique identifier for the server that should be used when referencing
|
// The unique identifier for the server that should be used when referencing
|
||||||
|
@ -25,7 +36,7 @@ type Server struct {
|
||||||
Suspended bool `json:"suspended"`
|
Suspended bool `json:"suspended"`
|
||||||
|
|
||||||
// The power state of the server.
|
// 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.
|
// The command that should be used when booting up the server instance.
|
||||||
Invocation string `json:"invocation"`
|
Invocation string `json:"invocation"`
|
||||||
|
@ -219,6 +230,22 @@ func (s *Server) Cache() *cache.Cache {
|
||||||
return s.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
|
// 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.
|
// indicate why a server is not bootable, only if it is.
|
||||||
func (s *Server) IsBootable() bool {
|
func (s *Server) IsBootable() bool {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user