Fix issues instantiating the server struct

This commit is contained in:
Dane Everitt
2019-11-30 16:37:11 -08:00
parent bdf546c47a
commit be14811eb4
5 changed files with 18 additions and 15 deletions

View File

@@ -2,6 +2,7 @@ package server
import (
"fmt"
"github.com/mcuadros/go-defaults"
"github.com/patrickmn/go-cache"
"github.com/pkg/errors"
"github.com/pterodactyl/wings/api"
@@ -38,8 +39,11 @@ type Server struct {
// server process.
EnvVars map[string]string `json:"environment" yaml:"environment"`
Build *BuildSettings `json:"build"`
Allocations *Allocations `json:"allocations"`
Build BuildSettings `json:"build"`
Allocations Allocations `json:"allocations"`
Environment Environment `json:"-" yaml:"-"`
Filesystem Filesystem `json:"-" yaml:"-"`
Resources ResourceUsage `json:"resources" yaml:"-"`
Container struct {
// Defines the Docker image that will be used for this server
@@ -51,12 +55,6 @@ type Server struct {
RebuildRequired bool `default:"false" json:"rebuild_required,omitempty" yaml:"rebuild_required"`
} `json:"container,omitempty"`
Environment Environment `json:"-" yaml:"-"`
Filesystem *Filesystem `json:"-" yaml:"-"`
Resources *ResourceUsage `json:"resources" yaml:"-"`
// Server cache used to store frequently requested information in memory and make
// certain long operations return faster. For example, FS disk space usage.
Cache *cache.Cache `json:"-" yaml:"-"`
@@ -199,7 +197,8 @@ func (s *Server) Init() {
// given struct using a YAML marshaler. This will also configure the given environment
// for a server.
func FromConfiguration(data []byte, cfg *config.SystemConfiguration) (*Server, error) {
s := &Server{}
s := new(Server)
defaults.SetDefaults(s)
s.Init()
if err := yaml.Unmarshal(data, s); err != nil {
@@ -226,11 +225,11 @@ func FromConfiguration(data []byte, cfg *config.SystemConfiguration) (*Server, e
s.Environment = env
s.Cache = cache.New(time.Minute*10, time.Minute*15)
s.Filesystem = &Filesystem{
s.Filesystem = Filesystem{
Configuration: cfg,
Server: s,
}
s.Resources = &ResourceUsage{}
s.Resources = ResourceUsage{}
// This is also done when the server is booted, however we need to account for instances
// where the server is already running and the Daemon reboots. In those cases this will
@@ -277,6 +276,7 @@ func (s *Server) SetState(state string) error {
return errors.New(fmt.Sprintf("invalid server state received: %s", state))
}
prevState := s.State
s.State = state
// Persist this change to the disk immediately so that should the Daemon be stopped or

View File

@@ -61,7 +61,7 @@ func (s *Server) UpdateDataStructure(data []byte) error {
s.EnvVars = src.EnvVars
}
if src.Allocations != nil && src.Allocations.Mappings != nil && len(src.Allocations.Mappings) > 0 {
if src.Allocations.Mappings != nil && len(src.Allocations.Mappings) > 0 {
s.Allocations.Mappings = src.Allocations.Mappings
}