Merge branch 'develop' into dane/backup-restore

This commit is contained in:
Dane Everitt 2021-01-25 19:17:14 -08:00
commit 981071cda8
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
7 changed files with 60 additions and 59 deletions

View File

@ -1,33 +1,22 @@
# Stage 1 (Build) # Stage 1 (Build)
FROM golang:1.15-alpine3.12 AS builder FROM golang:1.15-alpine3.12 AS builder
ARG VERSION ARG VERSION
RUN apk add --update --no-cache git=2.26.2-r0 make=4.3-r0 upx=3.96-r0
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/
WORKDIR /app/ RUN go mod download
COPY . /app/
COPY go.mod go.sum /app/ RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
RUN go mod download -ldflags="-s -w -X github.com/pterodactyl/wings/system.Version=$VERSION" \
-v \
COPY . /app/ -trimpath \
-o wings \
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \ wings.go
-ldflags="-s -w -X github.com/pterodactyl/wings/system.Version=$VERSION" \ RUN upx wings
-v \
-trimpath \
-o wings \
wings.go
RUN upx wings
# --------------------------------------- #
# Stage 2 (Final) # Stage 2 (Final)
FROM busybox:1.33.0 FROM busybox:1.33.0
RUN echo "ID=\"busybox\"" > /etc/os-release
RUN echo "ID=\"busybox\"" > /etc/os-release COPY --from=builder /app/wings /usr/bin/
CMD [ "wings", "--config", "/etc/pterodactyl/config.yml" ]
COPY --from=builder /app/wings /usr/bin/
CMD [ "wings", "--config", "/etc/pterodactyl/config.yml" ]

View File

@ -164,6 +164,12 @@ func rootCmdRun(cmd *cobra.Command, _ []string) {
for _, serv := range server.GetServers().All() { for _, serv := range server.GetServers().All() {
s := serv 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() { pool.Submit(func() {
s.Log().Info("configuring server environment and restoring to previous state") s.Log().Info("configuring server environment and restoring to previous state")

View File

@ -22,6 +22,7 @@ services:
- "/var/lib/pterodactyl/:/var/lib/pterodactyl/" - "/var/lib/pterodactyl/:/var/lib/pterodactyl/"
- "/var/log/pterodactyl/:/var/log/pterodactyl/" - "/var/log/pterodactyl/:/var/log/pterodactyl/"
- "/tmp/pterodactyl/:/tmp/pterodactyl/" - "/tmp/pterodactyl/:/tmp/pterodactyl/"
- "/etc/ssl/certs:/etc/ssl/certs:ro"
# you may need /srv/daemon-data if you are upgrading from an old daemon # you may need /srv/daemon-data if you are upgrading from an old daemon
#- "/srv/daemon-data/:/srv/daemon-data/" #- "/srv/daemon-data/:/srv/daemon-data/"
# Required for ssl if you use let's encrypt. uncomment to use. # Required for ssl if you use let's encrypt. uncomment to use.

View File

@ -30,6 +30,7 @@ func getServerFileContents(c *gin.Context) {
f, st, err := s.Filesystem().File(p) f, st, err := s.Filesystem().File(p)
if err != nil { if err != nil {
middleware.CaptureAndAbort(c, err) middleware.CaptureAndAbort(c, err)
return
} }
defer f.Close() 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 // take since a panic will at least be recovered and this should be incredibly
// rare? // rare?
middleware.CaptureAndAbort(c, err) middleware.CaptureAndAbort(c, err)
return
} }
} }

View File

@ -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
}

View File

@ -447,6 +447,14 @@ func (ip *InstallationProcess) Execute() (string, error) {
NetworkMode: container.NetworkMode(config.Get().Docker.Network.Mode), 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") 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. // Remove the temporary directory when the installation process finishes for this server container.
defer func() { defer func() {

View File

@ -3,6 +3,7 @@ package server
import ( import (
"context" "context"
"fmt" "fmt"
"os"
"strings" "strings"
"sync" "sync"
@ -221,3 +222,27 @@ func (s *Server) ProcessConfiguration() *api.ProcessConfiguration {
return s.procConfig 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
}