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 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 // If set to false, data will only be synced when a server process is started, or
// detected as started when booting. // detected as started when booting.
SyncServersOnBoot bool `default:"true" yaml:"sync_servers_on_boot"` 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 // Create a new server instance using the configuration we wrote to the disk
// so that everything gets instantiated correctly on the struct. // 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{ return &Installer{
server: s2, server: s2,

View File

@ -5,6 +5,7 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/pterodactyl/wings/config"
"github.com/pterodactyl/wings/server" "github.com/pterodactyl/wings/server"
"go.uber.org/zap" "go.uber.org/zap"
"net/http" "net/http"
@ -68,6 +69,12 @@ func (e *RequestError) AbortWithStatus(status int, c *gin.Context) {
} }
c.Error(errors.WithStack(e)) 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." 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 return
} }
s, err := FromConfiguration(b, cfg) s, err := FromConfiguration(b, cfg, false)
if err != nil { if err != nil {
if IsServerDoesNotExistError(err) { if IsServerDoesNotExistError(err) {
zap.S().Infow("server does not exist on remote system", zap.String("server", file.Name())) 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 // 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 // given struct using a YAML marshaler. This will also configure the given environment
// for a server. // 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) s := new(Server)
if err := defaults.Set(s); err != nil { 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 // 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 // where the server is already running and the Daemon reboots. In those cases this will
// allow us to you know, stop servers. // allow us to you know, stop servers.
if cfg.SyncServersOnBoot { if forceSync || cfg.SyncServersOnBoot {
if err := s.Sync(); err != nil { if err := s.Sync(); err != nil {
return nil, err return nil, err
} }