From 8920f919b1766fb3bf7ae9115832ff628ff0b365 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Thu, 21 Jan 2021 20:08:54 -0800 Subject: [PATCH 1/6] Add makefile entry for remote debugging support with dev environment --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Makefile b/Makefile index 594cc64..e419df5 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,12 @@ debug: go build -race sudo ./wings --debug --ignore-certificate-errors --config config.yml +# Runs a remotly debuggable session for Wings allowing an IDE to connect and target +# different breakpoints. +rmdebug: + go build -gcflags "all=-N -l" -race + sudo dlv --listen=:2345 --headless=true --api-version=2 --accept-multiclient exec ./wings -- --debug --ignore-certificate-errors --config config.yml + compress: upx --brute build/wings_* From 56af6fc1f82b26246e16c56d4d781435be23b0e4 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Thu, 21 Jan 2021 20:58:40 -0800 Subject: [PATCH 2/6] Correctly abort on file missing without panic --- router/router_server_files.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/router/router_server_files.go b/router/router_server_files.go index 9679e17..44e315b 100644 --- a/router/router_server_files.go +++ b/router/router_server_files.go @@ -30,6 +30,7 @@ func getServerFileContents(c *gin.Context) { f, st, err := s.Filesystem().File(p) if err != nil { middleware.CaptureAndAbort(c, err) + return } defer f.Close() @@ -48,6 +49,7 @@ func getServerFileContents(c *gin.Context) { // take since a panic will at least be recovered and this should be incredibly // rare? middleware.CaptureAndAbort(c, err) + return } } From 5d070cbdc5f5460cbca700c30e2b22b191388651 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Thu, 21 Jan 2021 20:58:52 -0800 Subject: [PATCH 3/6] Handle edge case where a user triggers an install when the server has no data directory --- server/install.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/server/install.go b/server/install.go index e72555e..fe0fcea 100644 --- a/server/install.go +++ b/server/install.go @@ -447,6 +447,14 @@ func (ip *InstallationProcess) Execute() (string, error) { NetworkMode: container.NetworkMode(config.Get().Docker.Network.Mode), } + // Ensure the root directory for the server exists properly before attempting + // to trigger the reinstall of the server. It is possible the directory would + // not exist when this runs if Wings boots with a missing directory and a user + // triggers a reinstall before trying to start the server. + if err := ip.Server.EnsureDataDirectoryExists(); err != nil { + return "", err + } + ip.Server.Log().WithField("install_script", ip.tempDir()+"/install.sh").Info("creating install container for server process") // Remove the temporary directory when the installation process finishes for this server container. defer func() { From 93506994a5bb122a49c10612749a2c1c6d4d6806 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 23 Jan 2021 10:45:29 -0800 Subject: [PATCH 4/6] Ensure the root directory for a server is always create when booting wings --- cmd/root.go | 6 ++++++ server/filesystem.go | 30 ------------------------------ server/server.go | 25 +++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 30 deletions(-) delete mode 100644 server/filesystem.go diff --git a/cmd/root.go b/cmd/root.go index efc5b6a..a90eab2 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -164,6 +164,12 @@ func rootCmdRun(cmd *cobra.Command, _ []string) { for _, serv := range server.GetServers().All() { s := serv + // For each server we encounter make sure the root data directory exists. + if err := s.EnsureDataDirectoryExists(); err != nil { + s.Log().Error("could not create root data directory for server: not loading server...") + continue + } + pool.Submit(func() { s.Log().Info("configuring server environment and restoring to previous state") diff --git a/server/filesystem.go b/server/filesystem.go deleted file mode 100644 index d86b526..0000000 --- a/server/filesystem.go +++ /dev/null @@ -1,30 +0,0 @@ -package server - -import ( - "os" - - "github.com/pterodactyl/wings/server/filesystem" -) - -func (s *Server) Filesystem() *filesystem.Filesystem { - return s.fs -} - -// Ensures that the data directory for the server instance exists. -func (s *Server) EnsureDataDirectoryExists() error { - if _, err := os.Stat(s.fs.Path()); err != nil && !os.IsNotExist(err) { - return err - } else if err != nil { - // Create the server data directory because it does not currently exist - // on the system. - if err := os.MkdirAll(s.fs.Path(), 0700); err != nil { - return err - } - - if err := s.fs.Chown("/"); err != nil { - s.Log().WithField("error", err).Warn("failed to chown server data directory") - } - } - - return nil -} diff --git a/server/server.go b/server/server.go index f7acc9a..0e1fb05 100644 --- a/server/server.go +++ b/server/server.go @@ -3,6 +3,7 @@ package server import ( "context" "fmt" + "os" "strings" "sync" @@ -221,3 +222,27 @@ func (s *Server) ProcessConfiguration() *api.ProcessConfiguration { return s.procConfig } + +// Filesystem returns an instance of the filesystem for this server. +func (s *Server) Filesystem() *filesystem.Filesystem { + return s.fs +} + +// EnsureDataDirectoryExists ensures that the data directory for the server +// instance exists. +func (s *Server) EnsureDataDirectoryExists() error { + if _, err := os.Lstat(s.fs.Path()); err != nil { + if os.IsNotExist(err) { + s.Log().Debug("server: creating root directory and setting permissions") + if err := os.MkdirAll(s.fs.Path(), 0700); err != nil { + return errors.WithStack(err) + } + if err := s.fs.Chown("/"); err != nil { + s.Log().WithField("error", err).Warn("server: failed to chown server data directory") + } + } else { + return errors.WrapIf(err, "server: failed to stat server root directory") + } + } + return nil +} \ No newline at end of file From 60416360767487fe60d2b67b7c4cb373931cd0ea Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 23 Jan 2021 11:47:53 -0800 Subject: [PATCH 5/6] Fix SSL issues --- Dockerfile | 47 +++++++++++++++----------------------- docker-compose.example.yml | 1 + 2 files changed, 19 insertions(+), 29 deletions(-) diff --git a/Dockerfile b/Dockerfile index dcb75d8..574bfda 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,33 +1,22 @@ # Stage 1 (Build) -FROM golang:1.15-alpine3.12 AS builder +FROM golang:1.15-alpine3.12 AS builder -ARG VERSION - -RUN apk add --update --no-cache git=2.26.2-r0 make=4.3-r0 upx=3.96-r0 - -WORKDIR /app/ - -COPY go.mod go.sum /app/ -RUN go mod download - -COPY . /app/ - -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \ - -ldflags="-s -w -X github.com/pterodactyl/wings/system.Version=$VERSION" \ - -v \ - -trimpath \ - -o wings \ - wings.go - -RUN upx wings - -# --------------------------------------- # +ARG VERSION +RUN apk add --update --no-cache git=2.26.2-r0 make=4.3-r0 upx=3.96-r0 +WORKDIR /app/ +COPY go.mod go.sum /app/ +RUN go mod download +COPY . /app/ +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \ + -ldflags="-s -w -X github.com/pterodactyl/wings/system.Version=$VERSION" \ + -v \ + -trimpath \ + -o wings \ + wings.go +RUN upx wings # Stage 2 (Final) -FROM busybox:1.33.0 - -RUN echo "ID=\"busybox\"" > /etc/os-release - -COPY --from=builder /app/wings /usr/bin/ - -CMD [ "wings", "--config", "/etc/pterodactyl/config.yml" ] +FROM busybox:1.33.0 +RUN echo "ID=\"busybox\"" > /etc/os-release +COPY --from=builder /app/wings /usr/bin/ +CMD [ "wings", "--config", "/etc/pterodactyl/config.yml" ] diff --git a/docker-compose.example.yml b/docker-compose.example.yml index d2aeb6c..583a0d1 100644 --- a/docker-compose.example.yml +++ b/docker-compose.example.yml @@ -22,6 +22,7 @@ services: - "/var/lib/pterodactyl/:/var/lib/pterodactyl/" - "/var/log/pterodactyl/:/var/log/pterodactyl/" - "/tmp/pterodactyl/:/tmp/pterodactyl/" + - "/etc/ssl/certs:/etc/ssl/certs" # you may need /srv/daemon-data if you are upgrading from an old daemon #- "/srv/daemon-data/:/srv/daemon-data/" # Required for ssl if you use let's encrypt. uncomment to use. From fecacc1339fc41698bd90b2aedb925f9c5e625a9 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 23 Jan 2021 13:46:57 -0800 Subject: [PATCH 6/6] USe readonly flag on compose --- docker-compose.example.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.example.yml b/docker-compose.example.yml index 583a0d1..8a6f57c 100644 --- a/docker-compose.example.yml +++ b/docker-compose.example.yml @@ -22,7 +22,7 @@ services: - "/var/lib/pterodactyl/:/var/lib/pterodactyl/" - "/var/log/pterodactyl/:/var/log/pterodactyl/" - "/tmp/pterodactyl/:/tmp/pterodactyl/" - - "/etc/ssl/certs:/etc/ssl/certs" + - "/etc/ssl/certs:/etc/ssl/certs:ro" # you may need /srv/daemon-data if you are upgrading from an old daemon #- "/srv/daemon-data/:/srv/daemon-data/" # Required for ssl if you use let's encrypt. uncomment to use.