Sync all server details when booting daemon or server process
This commit is contained in:
@@ -151,15 +151,11 @@ func (d *DockerEnvironment) InSituUpdate() error {
|
||||
// state. This ensures that unexpected container deletion while Wings is running does
|
||||
// not result in the server becoming unbootable.
|
||||
func (d *DockerEnvironment) OnBeforeStart() error {
|
||||
c, rerr, err := d.Server.GetProcessConfiguration()
|
||||
if err != nil {
|
||||
zap.S().Infow("syncing server configuration with Panel", zap.String("server", d.Server.Uuid))
|
||||
if err := d.Server.Sync(); err != nil {
|
||||
return err
|
||||
} else if rerr != nil {
|
||||
return errors.New(rerr.String())
|
||||
}
|
||||
|
||||
d.Server.processConfiguration = c
|
||||
|
||||
// If the server requires a rebuild, go ahead and delete the container from the system which
|
||||
// will allow the subsequent Create() call to create a new container instance for the server
|
||||
// to run in.
|
||||
|
||||
@@ -72,7 +72,7 @@ type Server struct {
|
||||
// Defines the process configuration for the server instance. This is dynamically
|
||||
// fetched from the Pterodactyl Server instance each time the server process is
|
||||
// started, and then cached here.
|
||||
processConfiguration *api.ServerConfiguration
|
||||
processConfiguration *api.ProcessConfiguration
|
||||
|
||||
// Internal mutex used to block actions that need to occur sequentially, such as
|
||||
// writing the configuration to the disk.
|
||||
@@ -250,23 +250,45 @@ func FromConfiguration(data []byte, cfg *config.SystemConfiguration) (*Server, e
|
||||
// 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
|
||||
// allow us to you know, stop servers.
|
||||
if cfg, rerr, err := s.GetProcessConfiguration(); err != nil {
|
||||
return nil, err
|
||||
} else if rerr != nil {
|
||||
// If the response error is because a server does not exist on the Panel return
|
||||
// that so that we can handle that in the future.
|
||||
if rerr.Status == "404" {
|
||||
return nil, &serverDoesNotExist{}
|
||||
if cfg.SyncServersOnBoot {
|
||||
if err := s.Sync(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return nil, errors.New(rerr.String())
|
||||
} else {
|
||||
s.processConfiguration = cfg
|
||||
}
|
||||
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// Syncs the state of the server on the Panel with Wings. This ensures that we're always
|
||||
// using the state of the server from the Panel and allows us to not require successful
|
||||
// API calls to Wings to do things.
|
||||
//
|
||||
// This also means mass actions can be performed against servers on the Panel and they
|
||||
// will automatically sync with Wings when the server is started.
|
||||
func (s *Server) Sync() error {
|
||||
cfg, rerr, err := s.GetProcessConfiguration()
|
||||
if err != nil || rerr != nil {
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
if rerr.Status == "404" {
|
||||
return &serverDoesNotExist{}
|
||||
}
|
||||
|
||||
return errors.New(rerr.String())
|
||||
}
|
||||
|
||||
// Update the data structure and persist it to the disk.
|
||||
if err:= s.UpdateDataStructure(cfg.Settings, false); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
s.processConfiguration = cfg.ProcessConfiguration
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reads the log file for a server up to a specified number of bytes.
|
||||
func (s *Server) ReadLogfile(len int64) ([]string, error) {
|
||||
return s.Environment.Readlog(len)
|
||||
@@ -348,6 +370,6 @@ func (s *Server) SetState(state string) error {
|
||||
}
|
||||
|
||||
// Gets the process configuration data for the server.
|
||||
func (s *Server) GetProcessConfiguration() (*api.ServerConfiguration, *api.RequestError, error) {
|
||||
func (s *Server) GetProcessConfiguration() (*api.ServerConfigurationResponse, *api.RequestError, error) {
|
||||
return api.NewRequester().GetServerConfiguration(s.Uuid)
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@ import (
|
||||
// The server will be marked as requiring a rebuild on the next boot sequence,
|
||||
// it is up to the specific environment to determine what needs to happen when
|
||||
// that is the case.
|
||||
func (s *Server) UpdateDataStructure(data []byte) error {
|
||||
src := Server{}
|
||||
if err := json.Unmarshal(data, &src); err != nil {
|
||||
func (s *Server) UpdateDataStructure(data []byte, background bool) error {
|
||||
src := new(Server)
|
||||
if err := json.Unmarshal(data, src); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ func (s *Server) UpdateDataStructure(data []byte) error {
|
||||
}
|
||||
|
||||
// Set the default values in the interface that we unmarshaled into.
|
||||
if err := defaults.Set(&src); err != nil {
|
||||
return err
|
||||
if err := defaults.Set(src); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
// Merge the new data object that we have received with the existing server data object
|
||||
@@ -76,7 +76,9 @@ func (s *Server) UpdateDataStructure(data []byte) error {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
s.runBackgroundActions()
|
||||
if background {
|
||||
s.runBackgroundActions()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user