Add debug logs when a non-500 error occurs, force sync the configuration during installation of a new server

This commit is contained in:
Matthew Penner 2020-04-10 12:00:04 -06:00
parent 62ed90e621
commit 9e30d63818
4 changed files with 13 additions and 6 deletions

View File

@ -82,7 +82,7 @@ type SystemConfiguration struct {
Gid int
}
// Determines wether or not server data should be synced when the Daemon is started.
// Determines whether or not server data should be synced when the Daemon is started.
// If set to false, data will only be synced when a server process is started, or
// detected as started when booting.
SyncServersOnBoot bool `default:"true" yaml:"sync_servers_on_boot"`

View File

@ -84,7 +84,7 @@ func New(data []byte) (*Installer, error) {
// Create a new server instance using the configuration we wrote to the disk
// so that everything gets instantiated correctly on the struct.
s2, err := server.FromConfiguration(b, &config.Get().System)
s2, err := server.FromConfiguration(b, &config.Get().System, true)
return &Installer{
server: s2,

View File

@ -5,6 +5,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"github.com/pkg/errors"
"github.com/pterodactyl/wings/config"
"github.com/pterodactyl/wings/server"
"go.uber.org/zap"
"net/http"
@ -68,6 +69,12 @@ func (e *RequestError) AbortWithStatus(status int, c *gin.Context) {
}
c.Error(errors.WithStack(e))
} else if config.Get().Debug {
if e.server != nil {
zap.S().Debugw("encountered error while handling HTTP request", zap.String("server", e.server.Uuid), zap.String("error_id", e.Uuid), zap.Error(e.Err))
} else {
zap.S().Debugw("encountered error while handling HTTP request", zap.String("error_id", e.Uuid), zap.Error(e.Err))
}
}
msg := "An unexpected error was encountered while processing this request."

View File

@ -179,7 +179,7 @@ func LoadDirectory(dir string, cfg *config.SystemConfiguration) error {
return
}
s, err := FromConfiguration(b, cfg)
s, err := FromConfiguration(b, cfg, false)
if err != nil {
if IsServerDoesNotExistError(err) {
zap.S().Infow("server does not exist on remote system", zap.String("server", file.Name()))
@ -209,7 +209,7 @@ func (s *Server) Init() {
// Initializes a server using a data byte array. This will be marshaled into the
// 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) {
func FromConfiguration(data []byte, cfg *config.SystemConfiguration, forceSync bool) (*Server, error) {
s := new(Server)
if err := defaults.Set(s); err != nil {
@ -244,7 +244,7 @@ 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.SyncServersOnBoot {
if forceSync || cfg.SyncServersOnBoot {
if err := s.Sync(); err != nil {
return nil, err
}
@ -414,4 +414,4 @@ func (s *Server) HandlePowerAction(action PowerAction) error {
default:
return errors.New("an invalid power action was provided")
}
}
}