Replace even more zap occurences

This commit is contained in:
Dane Everitt 2020-06-13 10:26:35 -07:00
parent 0ae286d617
commit 198a22f446
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
12 changed files with 80 additions and 125 deletions

View File

@ -2,13 +2,13 @@ package installer
import ( import (
"encoding/json" "encoding/json"
"github.com/apex/log"
"github.com/asaskevich/govalidator" "github.com/asaskevich/govalidator"
"github.com/buger/jsonparser" "github.com/buger/jsonparser"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/pterodactyl/wings/api" "github.com/pterodactyl/wings/api"
"github.com/pterodactyl/wings/config" "github.com/pterodactyl/wings/config"
"github.com/pterodactyl/wings/server" "github.com/pterodactyl/wings/server"
"go.uber.org/zap"
"os" "os"
"path" "path"
) )
@ -108,24 +108,27 @@ func (i *Installer) Server() *server.Server {
// associated installation process based on the parameters passed through for // associated installation process based on the parameters passed through for
// the server instance. // the server instance.
func (i *Installer) Execute() { func (i *Installer) Execute() {
zap.S().Debugw("creating required server data directory", zap.String("server", i.Uuid())) p := path.Join(config.Get().System.Data, i.Uuid())
if err := os.MkdirAll(path.Join(config.Get().System.Data, i.Uuid()), 0755); err != nil { l := log.WithFields(log.Fields{"server": i.Uuid(), "process": "installer"})
zap.S().Errorw("failed to create server data directory", zap.String("server", i.Uuid()), zap.Error(errors.WithStack(err)))
l.WithField("path", p).Debug("creating required server data directory")
if err := os.MkdirAll(p, 0755); err != nil {
l.WithFields(log.Fields{"path": p, "error": errors.WithStack(err)}).Error("failed to create server data directory")
return return
} }
if err := os.Chown(path.Join(config.Get().System.Data, i.Uuid()), config.Get().System.User.Uid, config.Get().System.User.Gid); err != nil { if err := os.Chown(p, config.Get().System.User.Uid, config.Get().System.User.Gid); err != nil {
zap.S().Errorw("failed to chown server data directory", zap.String("server", i.Uuid()), zap.Error(errors.WithStack(err))) l.WithField("error", errors.WithStack(err)).Error("failed to chown server data directory")
return return
} }
zap.S().Debugw("creating required environment for server instance", zap.String("server", i.Uuid())) l.Debug("creating required environment for server instance")
if err := i.server.Environment.Create(); err != nil { if err := i.server.Environment.Create(); err != nil {
zap.S().Errorw("failed to create environment for server", zap.String("server", i.Uuid()), zap.Error(err)) l.WithField("error", err).Error("failed to create environment for server")
return return
} }
zap.S().Debugw("created environment for server during install process", zap.String("server", i.Uuid())) l.Info("successfully created environment for server during install process")
} }
// Returns a string value from the JSON data provided. // Returns a string value from the JSON data provided.

View File

@ -3,10 +3,10 @@ package parser
import ( import (
"bytes" "bytes"
"github.com/Jeffail/gabs/v2" "github.com/Jeffail/gabs/v2"
"github.com/apex/log"
"github.com/buger/jsonparser" "github.com/buger/jsonparser"
"github.com/iancoleman/strcase" "github.com/iancoleman/strcase"
"github.com/pkg/errors" "github.com/pkg/errors"
"go.uber.org/zap"
"io/ioutil" "io/ioutil"
"os" "os"
"regexp" "regexp"
@ -120,11 +120,9 @@ func (cfr *ConfigurationFileReplacement) SetAtPathway(c *gabs.Container, path st
// We're doing some regex here. // We're doing some regex here.
r, err := regexp.Compile(strings.TrimPrefix(cfr.IfValue, "regex:")) r, err := regexp.Compile(strings.TrimPrefix(cfr.IfValue, "regex:"))
if err != nil { if err != nil {
zap.S().Warnw( log.WithFields(log.Fields{"if_value": strings.TrimPrefix(cfr.IfValue, "regex:"), "error": err}).
"configuration if_value using invalid regexp, cannot do replacement", Warn("configuration if_value using invalid regexp, cannot perform replacement")
zap.String("if_value", strings.TrimPrefix(cfr.IfValue, "regex:")),
zap.Error(err),
)
return nil return nil
} }
@ -179,11 +177,7 @@ func (f *ConfigurationFile) LookupConfigurationValue(cfr ConfigurationFileReplac
return match, errors.WithStack(err) return match, errors.WithStack(err)
} }
zap.S().Debugw( log.WithFields(log.Fields{"path": path, "filename": f.FileName}).Debug("attempted to load a configuration value that does not exist")
"attempted to load a configuration value that does not exist",
zap.Strings("path", path),
zap.String("filename", f.FileName),
)
// If there is no key, keep the original value intact, that way it is obvious there // If there is no key, keep the original value intact, that way it is obvious there
// is a replace issue at play. // is a replace issue at play.

View File

@ -3,13 +3,13 @@ package parser
import ( import (
"bufio" "bufio"
"encoding/json" "encoding/json"
"github.com/apex/log"
"github.com/beevik/etree" "github.com/beevik/etree"
"github.com/buger/jsonparser" "github.com/buger/jsonparser"
"github.com/icza/dyno" "github.com/icza/dyno"
"github.com/magiconair/properties" "github.com/magiconair/properties"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/pterodactyl/wings/config" "github.com/pterodactyl/wings/config"
"go.uber.org/zap"
"gopkg.in/ini.v1" "gopkg.in/ini.v1"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
"io/ioutil" "io/ioutil"
@ -30,6 +30,10 @@ const (
type ConfigurationParser string type ConfigurationParser string
func (cp ConfigurationParser) String() string {
return string(cp)
}
// Defines a configuration file for the server startup. These will be looped over // Defines a configuration file for the server startup. These will be looped over
// and modified before the server finishes booting. // and modified before the server finishes booting.
type ConfigurationFile struct { type ConfigurationFile struct {
@ -63,11 +67,7 @@ func (f *ConfigurationFile) UnmarshalJSON(data []byte) error {
} }
if err := json.Unmarshal(*m["replace"], &f.Replace); err != nil { if err := json.Unmarshal(*m["replace"], &f.Replace); err != nil {
zap.S().Warnw( log.WithField("file", f.FileName).WithField("error", err).Warn("failed to unmarshal configuration file replacement")
"failed to unmarshal configuration file replacement",
zap.String("file", f.FileName),
zap.Error(err),
)
f.Replace = []ConfigurationFileReplacement{} f.Replace = []ConfigurationFileReplacement{}
} }
@ -131,7 +131,7 @@ func (cfr *ConfigurationFileReplacement) UnmarshalJSON(data []byte) error {
// Parses a given configuration file and updates all of the values within as defined // Parses a given configuration file and updates all of the values within as defined
// in the API response from the Panel. // in the API response from the Panel.
func (f *ConfigurationFile) Parse(path string, internal bool) error { func (f *ConfigurationFile) Parse(path string, internal bool) error {
zap.S().Debugw("parsing configuration file", zap.String("path", path), zap.String("parser", string(f.Parser))) log.WithField("path", path).WithField("parser", f.Parser.String()).Debug("parsing server configuration file")
if mb, err := json.Marshal(config.Get()); err != nil { if mb, err := json.Marshal(config.Get()); err != nil {
return err return err

View File

@ -2,11 +2,11 @@ package router
import ( import (
"fmt" "fmt"
"github.com/apex/log"
"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/server" "github.com/pterodactyl/wings/server"
"go.uber.org/zap"
"net/http" "net/http"
"os" "os"
) )
@ -40,6 +40,14 @@ func TrackedServerError(err error, s *server.Server) *RequestError {
} }
} }
func (e *RequestError) logger() *log.Entry {
if e.server != nil {
return e.server.Log().WithField("error_id", e.Uuid)
}
return log.WithField("error_id", e.Uuid)
}
// Sets the output message to display to the user in the error. // Sets the output message to display to the user in the error.
func (e *RequestError) SetMessage(msg string) *RequestError { func (e *RequestError) SetMessage(msg string) *RequestError {
e.Message = msg e.Message = msg
@ -61,19 +69,11 @@ func (e *RequestError) AbortWithStatus(status int, c *gin.Context) {
// Otherwise, log the error to zap, and then report the error back to the user. // Otherwise, log the error to zap, and then report the error back to the user.
if status >= 500 { if status >= 500 {
if e.server != nil { e.logger().WithField("error", e.Err).Error("encountered HTTP/500 error while handling request")
zap.S().Errorw("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().Errorw("encountered error while handling HTTP request", zap.String("error_id", e.Uuid), zap.Error(e.Err))
}
c.Error(errors.WithStack(e)) c.Error(errors.WithStack(e))
} else { } else {
if e.server != nil { e.logger().WithField("error", e.Err).Debug("encountered non-HTTP/500 error while handling request")
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

@ -2,6 +2,7 @@ package router
import ( import (
"bytes" "bytes"
"github.com/apex/log"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/pterodactyl/wings/server" "github.com/pterodactyl/wings/server"
@ -74,15 +75,12 @@ func postServerPower(c *gin.Context) {
// Pass the actual heavy processing off to a seperate thread to handle so that // Pass the actual heavy processing off to a seperate thread to handle so that
// we can immediately return a response from the server. Some of these actions // we can immediately return a response from the server. Some of these actions
// can take quite some time, especially stopping or restarting. // can take quite some time, especially stopping or restarting.
go func() { go func(server *server.Server) {
if err := s.HandlePowerAction(data); err != nil { if err := server.HandlePowerAction(data); err != nil {
zap.S().Errorw( server.Log().WithFields(log.Fields{"action": data, "error": err}).
"encountered an error processing a server power action", Error("encountered error processing a server power action in the background")
zap.String("server", s.Uuid),
zap.Error(err),
)
} }
}() }(s)
c.Status(http.StatusAccepted) c.Status(http.StatusAccepted)
} }
@ -111,12 +109,7 @@ func postServerCommands(c *gin.Context) {
for _, command := range data.Commands { for _, command := range data.Commands {
if err := s.Environment.SendCommand(command); err != nil { if err := s.Environment.SendCommand(command); err != nil {
zap.S().Warnw( s.Log().WithFields(log.Fields{"command": command, "error": err}).Warn("failed to send command to server instance")
"failed to send command to server",
zap.String("server", s.Uuid),
zap.String("command", command),
zap.Error(err),
)
} }
} }

View File

@ -6,7 +6,6 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
ws "github.com/gorilla/websocket" ws "github.com/gorilla/websocket"
"github.com/pterodactyl/wings/router/websocket" "github.com/pterodactyl/wings/router/websocket"
"go.uber.org/zap"
) )
// Upgrades a connection to a websocket and passes events along between. // Upgrades a connection to a websocket and passes events along between.
@ -40,7 +39,7 @@ func getServerWebsocket(c *gin.Context) {
ws.CloseServiceRestart, ws.CloseServiceRestart,
ws.CloseAbnormalClosure, ws.CloseAbnormalClosure,
) { ) {
zap.S().Warnw("error handling websocket message", zap.Error(err)) s.Log().WithField("error", err).Warn("error handling websocket message for server")
} }
break break
} }
@ -57,4 +56,3 @@ func getServerWebsocket(c *gin.Context) {
} }
} }
} }

View File

@ -2,12 +2,12 @@ package router
import ( import (
"bytes" "bytes"
"github.com/apex/log"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/pterodactyl/wings/config" "github.com/pterodactyl/wings/config"
"github.com/pterodactyl/wings/installer" "github.com/pterodactyl/wings/installer"
"github.com/pterodactyl/wings/server" "github.com/pterodactyl/wings/server"
"github.com/pterodactyl/wings/system" "github.com/pterodactyl/wings/system"
"go.uber.org/zap"
"net/http" "net/http"
) )
@ -59,11 +59,7 @@ func postCreateServer(c *gin.Context) {
i.Execute() i.Execute()
if err := i.Server().Install(); err != nil { if err := i.Server().Install(); err != nil {
zap.S().Errorw( log.WithFields(log.Fields{"server": i.Uuid(), "error": err}).Error("failed to run install process for server")
"failed to run install process for server",
zap.String("server", i.Uuid()),
zap.Error(err),
)
} }
}(install) }(install)

View File

@ -3,6 +3,7 @@ package websocket
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/apex/log"
"github.com/gbrlsnchs/jwt/v3" "github.com/gbrlsnchs/jwt/v3"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
@ -10,7 +11,6 @@ import (
"github.com/pterodactyl/wings/config" "github.com/pterodactyl/wings/config"
"github.com/pterodactyl/wings/router/tokens" "github.com/pterodactyl/wings/router/tokens"
"github.com/pterodactyl/wings/server" "github.com/pterodactyl/wings/server"
"go.uber.org/zap"
"net/http" "net/http"
"os" "os"
"strings" "strings"
@ -85,7 +85,6 @@ func (h *Handler) SendJson(v *Message) error {
// If we're sending installation output but the user does not have the required // If we're sending installation output but the user does not have the required
// permissions to see the output, don't send it down the line. // permissions to see the output, don't send it down the line.
if v.Event == server.InstallOutputEvent { if v.Event == server.InstallOutputEvent {
zap.S().Debugf("%+v", v.Args)
if !j.HasPermission(PermissionReceiveInstall) { if !j.HasPermission(PermissionReceiveInstall) {
return nil return nil
} }
@ -152,13 +151,8 @@ func (h *Handler) SendErrorJson(msg Message, err error) error {
wsm.Args = []string{m} wsm.Args = []string{m}
if !server.IsSuspendedError(err) { if !server.IsSuspendedError(err) {
zap.S().Errorw( h.server.Log().WithFields(log.Fields{"event": msg.Event, "error_identifier": u.String(), "error": err}).
"an error was encountered in the websocket process", Error("failed to handle websocket process; an error was encountered processing an event")
zap.String("event", msg.Event),
zap.String("server", h.server.Uuid),
zap.String("error_identifier", u.String()),
zap.Error(err),
)
} }
return h.unsafeSendJson(wsm) return h.unsafeSendJson(wsm)
@ -192,7 +186,7 @@ func (h *Handler) GetJwt() *tokens.WebsocketPayload {
func (h *Handler) HandleInbound(m Message) error { func (h *Handler) HandleInbound(m Message) error {
if m.Event != AuthenticationEvent { if m.Event != AuthenticationEvent {
if err := h.TokenValid(); err != nil { if err := h.TokenValid(); err != nil {
zap.S().Debugw("jwt token is no longer valid", zap.String("message", err.Error())) log.WithField("message", err.Error()).Debug("jwt for server websocket is no longer valid")
h.unsafeSendJson(Message{ h.unsafeSendJson(Message{
Event: ErrorEvent, Event: ErrorEvent,

View File

@ -2,7 +2,6 @@ package server
import ( import (
"github.com/pterodactyl/wings/parser" "github.com/pterodactyl/wings/parser"
"go.uber.org/zap"
"sync" "sync"
) )
@ -17,15 +16,15 @@ func (s *Server) UpdateConfigurationFiles() {
go func(f parser.ConfigurationFile, server *Server) { go func(f parser.ConfigurationFile, server *Server) {
defer wg.Done() defer wg.Done()
p, err := s.Filesystem.SafePath(f.FileName) p, err := server.Filesystem.SafePath(f.FileName)
if err != nil { if err != nil {
zap.S().Errorw("failed to generate safe path for configuration file", zap.String("server", server.Uuid), zap.Error(err)) server.Log().WithField("error", err).Error("failed to generate safe path for configuration file")
return return
} }
if err := f.Parse(p, false); err != nil { if err := f.Parse(p, false); err != nil {
zap.S().Errorw("failed to parse and update server configuration file", zap.String("server", server.Uuid), zap.Error(err)) server.Log().WithField("error", err).Error("failed to parse and update server configuration file")
} }
}(v, s) }(v, s)
} }

View File

@ -4,7 +4,6 @@ import (
"fmt" "fmt"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/pterodactyl/wings/config" "github.com/pterodactyl/wings/config"
"go.uber.org/zap"
"time" "time"
) )
@ -27,15 +26,13 @@ type CrashDetection struct {
// //
// If the server is determined to have crashed, the process will be restarted and the // If the server is determined to have crashed, the process will be restarted and the
// counter for the server will be incremented. // counter for the server will be incremented.
//
// @todo output event to server console
func (s *Server) handleServerCrash() error { func (s *Server) handleServerCrash() error {
// No point in doing anything here if the server isn't currently offline, there // No point in doing anything here if the server isn't currently offline, there
// is no reason to do a crash detection event. If the server crash detection is // is no reason to do a crash detection event. If the server crash detection is
// disabled we want to skip anything after this as well. // disabled we want to skip anything after this as well.
if s.GetState() != ProcessOfflineState || !s.CrashDetection.Enabled { if s.GetState() != ProcessOfflineState || !s.CrashDetection.Enabled {
if !s.CrashDetection.Enabled { if !s.CrashDetection.Enabled {
zap.S().Debugw("server triggered crash detection but handler is disabled for server process", zap.String("server", s.Uuid)) s.Log().Debug("server triggered crash detection but handler is disabled for server process")
s.PublishConsoleOutputFromDaemon("Server detected as crashed; crash detection is disabled for this instance.") s.PublishConsoleOutputFromDaemon("Server detected as crashed; crash detection is disabled for this instance.")
} }
@ -51,7 +48,7 @@ func (s *Server) handleServerCrash() error {
// If the system is not configured to detect a clean exit code as a crash, and the // If the system is not configured to detect a clean exit code as a crash, and the
// crash is not the result of the program running out of memory, do nothing. // crash is not the result of the program running out of memory, do nothing.
if exitCode == 0 && !oomKilled && !config.Get().System.DetectCleanExitAsCrash { if exitCode == 0 && !oomKilled && !config.Get().System.DetectCleanExitAsCrash {
zap.S().Debugw("server exited with successful code; system configured to not detect as crash", zap.String("server", s.Uuid)) s.Log().Debug("server exited with successful exit code; system is configured to not detect this as a crash")
return nil return nil
} }

View File

@ -4,6 +4,7 @@ import (
"bufio" "bufio"
"bytes" "bytes"
"context" "context"
"github.com/apex/log"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/mount" "github.com/docker/docker/api/types/mount"
@ -11,7 +12,6 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/pterodactyl/wings/api" "github.com/pterodactyl/wings/api"
"github.com/pterodactyl/wings/config" "github.com/pterodactyl/wings/config"
"go.uber.org/zap"
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
@ -25,14 +25,12 @@ import (
func (s *Server) Install() error { func (s *Server) Install() error {
err := s.internalInstall() err := s.internalInstall()
zap.S().Debugw("notifying panel of server install state", zap.String("server", s.Uuid)) s.Log().Debug("notifying panel of server install state")
if serr := s.SyncInstallState(err == nil); serr != nil { if serr := s.SyncInstallState(err == nil); serr != nil {
zap.S().Warnw( s.Log().WithFields(log.Fields{
"failed to notify panel of server install state", "was_successful": err == nil,
zap.String("server", s.Uuid), "error": serr,
zap.Bool("was_successful", err == nil), }).Warn("failed to notify panel of server install state")
zap.Error(serr),
)
} }
return err return err
@ -42,7 +40,7 @@ func (s *Server) Install() error {
// does not touch any existing files for the server, other than what the script modifies. // does not touch any existing files for the server, other than what the script modifies.
func (s *Server) Reinstall() error { func (s *Server) Reinstall() error {
if s.GetState() != ProcessOfflineState { if s.GetState() != ProcessOfflineState {
zap.S().Debugw("waiting for server instance to enter a stopped state", zap.String("server", s.Uuid)) s.Log().Debug("waiting for server instance to enter a stopped state")
if err := s.Environment.WaitForStop(10, true); err != nil { if err := s.Environment.WaitForStop(10, true); err != nil {
return err return err
} }
@ -67,14 +65,12 @@ func (s *Server) internalInstall() error {
return errors.WithStack(err) return errors.WithStack(err)
} }
zap.S().Infow("beginning installation process for server", zap.String("server", s.Uuid)) s.Log().Info("beginning installation process for server")
if err := p.Run(); err != nil { if err := p.Run(); err != nil {
return err return err
} }
zap.S().Infow("completed installation process for server", zap.String("server", s.Uuid)) s.Log().Info("completed installation process for server")
return nil return nil
} }
@ -106,13 +102,13 @@ func NewInstallationProcess(s *Server, script *api.InstallationScript) (*Install
// Removes the installer container for the server. // Removes the installer container for the server.
func (ip *InstallationProcess) RemoveContainer() { func (ip *InstallationProcess) RemoveContainer() {
err := ip.client.ContainerRemove(context.Background(), ip.Server.Uuid + "_installer", types.ContainerRemoveOptions{ err := ip.client.ContainerRemove(context.Background(), ip.Server.Uuid+"_installer", types.ContainerRemoveOptions{
RemoveVolumes: true, RemoveVolumes: true,
Force: true, Force: true,
}) })
if err != nil && !client.IsErrNotFound(err) { if err != nil && !client.IsErrNotFound(err) {
zap.S().Warnw("failed to delete server installer container", zap.String("server", ip.Server.Uuid), zap.Error(errors.WithStack(err))) ip.Server.Log().WithField("error", errors.WithStack(err)).Warn("failed to delete server install container")
} }
} }
@ -137,7 +133,7 @@ func (ip *InstallationProcess) Run() error {
// If this step fails, log a warning but don't exit out of the process. This is completely // If this step fails, log a warning but don't exit out of the process. This is completely
// internal to the daemon's functionality, and does not affect the status of the server itself. // internal to the daemon's functionality, and does not affect the status of the server itself.
if err := ip.AfterExecute(cid); err != nil { if err := ip.AfterExecute(cid); err != nil {
zap.S().Warnw("failed to complete after-execute step of installation process", zap.String("server", ip.Server.Uuid), zap.Error(err)) ip.Server.Log().WithField("error", err).Warn("failed to complete after-execute step of installation process")
} }
return nil return nil
@ -189,7 +185,7 @@ func (ip *InstallationProcess) pullInstallationImage() error {
// Block continuation until the image has been pulled successfully. // Block continuation until the image has been pulled successfully.
scanner := bufio.NewScanner(r) scanner := bufio.NewScanner(r)
for scanner.Scan() { for scanner.Scan() {
zap.S().Debugw(scanner.Text()) log.Debug(scanner.Text())
} }
if err := scanner.Err(); err != nil { if err := scanner.Err(); err != nil {
@ -265,7 +261,7 @@ func (ip *InstallationProcess) AfterExecute(containerId string) error {
ctx := context.Background() ctx := context.Background()
defer ip.RemoveContainer() defer ip.RemoveContainer()
zap.S().Debugw("pulling installation logs for server", zap.String("server", ip.Server.Uuid), zap.String("container_id", containerId)) ip.Server.Log().WithField("container_id", containerId).Debug("pulling installation logs for server")
reader, err := ip.client.ContainerLogs(ctx, containerId, types.ContainerLogsOptions{ reader, err := ip.client.ContainerLogs(ctx, containerId, types.ContainerLogsOptions{
ShowStdout: true, ShowStdout: true,
ShowStderr: true, ShowStderr: true,
@ -295,12 +291,6 @@ func (ip *InstallationProcess) AfterExecute(containerId string) error {
func (ip *InstallationProcess) Execute(installPath string) (string, error) { func (ip *InstallationProcess) Execute(installPath string) (string, error) {
ctx := context.Background() ctx := context.Background()
zap.S().Debugw(
"creating server installer container",
zap.String("server", ip.Server.Uuid),
zap.String("script_path", installPath+"/install.sh"),
)
conf := &container.Config{ conf := &container.Config{
Hostname: "installer", Hostname: "installer",
AttachStdout: true, AttachStdout: true,
@ -348,17 +338,13 @@ func (ip *InstallationProcess) Execute(installPath string) (string, error) {
NetworkMode: container.NetworkMode(config.Get().Docker.Network.Mode), NetworkMode: container.NetworkMode(config.Get().Docker.Network.Mode),
} }
zap.S().Infow("creating installer container for server process", zap.String("server", ip.Server.Uuid)) ip.Server.Log().WithField("install_script", installPath+"/install.sh").Info("creating install container for server process")
r, err := ip.client.ContainerCreate(ctx, conf, hostConf, nil, ip.Server.Uuid+"_installer") r, err := ip.client.ContainerCreate(ctx, conf, hostConf, nil, ip.Server.Uuid+"_installer")
if err != nil { if err != nil {
return "", errors.WithStack(err) return "", errors.WithStack(err)
} }
zap.S().Infow( ip.Server.Log().WithField("container_id", r.ID).Info("running installation script for server in container")
"running installation script for server in container",
zap.String("server", ip.Server.Uuid),
zap.String("container_id", r.ID),
)
if err := ip.client.ContainerStart(ctx, r.ID, types.ContainerStartOptions{}); err != nil { if err := ip.client.ContainerStart(ctx, r.ID, types.ContainerStartOptions{}); err != nil {
return "", err return "", err
} }
@ -366,11 +352,7 @@ func (ip *InstallationProcess) Execute(installPath string) (string, error) {
go func(id string) { go func(id string) {
ip.Server.Events().Publish(DaemonMessageEvent, "Starting installation process, this could take a few minutes...") ip.Server.Events().Publish(DaemonMessageEvent, "Starting installation process, this could take a few minutes...")
if err := ip.StreamOutput(id); err != nil { if err := ip.StreamOutput(id); err != nil {
zap.S().Errorw( ip.Server.Log().WithField("error", err).Error("error while handling output stream for server install process")
"error handling streaming output for server install process",
zap.String("container_id", id),
zap.Error(err),
)
} }
ip.Server.Events().Publish(DaemonMessageEvent, "Installation process completed.") ip.Server.Events().Publish(DaemonMessageEvent, "Installation process completed.")
}(r.ID) }(r.ID)
@ -409,12 +391,10 @@ func (ip *InstallationProcess) StreamOutput(id string) error {
} }
if err := s.Err(); err != nil { if err := s.Err(); err != nil {
zap.S().Warnw( ip.Server.Log().WithFields(log.Fields{
"error processing scanner line in installation output for server", "container_id": id,
zap.String("server", ip.Server.Uuid), "error": errors.WithStack(err),
zap.String("container_id", id), }).Warn("error processing scanner line in installation output for server")
zap.Error(errors.WithStack(err)),
)
} }
return nil return nil

View File

@ -1,8 +1,8 @@
package server package server
import ( import (
"github.com/apex/log"
"github.com/pterodactyl/wings/api" "github.com/pterodactyl/wings/api"
"go.uber.org/zap"
"strings" "strings"
) )
@ -28,9 +28,10 @@ func (s *Server) onConsoleOutput(data string) {
// set the server to that state. Only do this if the server is not currently stopped // set the server to that state. Only do this if the server is not currently stopped
// or stopping. // or stopping.
if s.GetState() == ProcessStartingState && strings.Contains(data, s.processConfiguration.Startup.Done) { if s.GetState() == ProcessStartingState && strings.Contains(data, s.processConfiguration.Startup.Done) {
zap.S().Debugw( s.Log().WithFields(log.Fields{
"detected server in running state based on line output", zap.String("match", s.processConfiguration.Startup.Done), zap.String("against", data), "match": s.processConfiguration.Startup.Done,
) "against": data,
}).Debug("detected server in running state based on console line output")
s.SetState(ProcessRunningState) s.SetState(ProcessRunningState)
} }