Simplify environment creation for server

This commit is contained in:
Dane Everitt 2020-09-12 21:48:04 -07:00
parent be49e08f4f
commit ce2659fdd7
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
4 changed files with 13 additions and 33 deletions

View File

@ -2,16 +2,12 @@ package installer
import (
"encoding/json"
"github.com/apex/log"
"github.com/asaskevich/govalidator"
"github.com/buger/jsonparser"
"github.com/pkg/errors"
"github.com/pterodactyl/wings/api"
"github.com/pterodactyl/wings/config"
"github.com/pterodactyl/wings/environment"
"github.com/pterodactyl/wings/server"
"os"
"path"
)
type Installer struct {
@ -95,33 +91,6 @@ func (i *Installer) Server() *server.Server {
return i.server
}
// Executes the installer process, creating the server and running through the
// associated installation process based on the parameters passed through for
// the server instance.
func (i *Installer) Execute() {
p := path.Join(config.Get().System.Data, i.Uuid())
l := log.WithFields(log.Fields{"server": i.Uuid(), "process": "installer"})
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
}
if err := os.Chown(p, config.Get().System.User.Uid, config.Get().System.User.Gid); err != nil {
l.WithField("error", errors.WithStack(err)).Error("failed to chown server data directory")
return
}
l.Debug("creating required environment for server instance")
if err := i.server.Environment.Create(); err != nil {
l.WithField("error", err).Error("failed to create environment for server")
return
}
l.Info("successfully created environment for server during install process")
}
// Returns a string value from the JSON data provided.
func getString(data []byte, key ...string) string {
value, _ := jsonparser.GetString(data, key...)

View File

@ -57,7 +57,11 @@ func postCreateServer(c *gin.Context) {
// cycle. If there are any errors they will be logged and communicated back
// to the Panel where a reinstall may take place.
go func(i *installer.Installer) {
i.Execute()
err := i.Server().CreateEnvironment()
if err != nil {
i.Server().Log().WithField("error", err).Error("failed to create server environment during install process")
return
}
if err := i.Server().Install(false); err != nil {
log.WithFields(log.Fields{"server": i.Uuid(), "error": err}).Error("failed to run install process for server")

View File

@ -277,7 +277,10 @@ func postTransfer(c *gin.Context) {
server.GetServers().Add(i.Server())
// Create the server's environment (note this does not execute the install script)
i.Execute()
if err := i.Server().CreateEnvironment(); err != nil {
l.WithField("error", err).Error("failed to create server environment")
return
}
// Un-archive the archive. That sounds weird..
if err := archiver.NewTarGz().Unarchive(archivePath, i.Server().Filesystem.Path()); err != nil {

View File

@ -782,6 +782,10 @@ func (fs *Filesystem) EnsureDataDirectory() error {
if err := os.MkdirAll(fs.Path(), 0700); err != nil {
return errors.WithStack(err)
}
if err := fs.Chown("/"); err != nil {
fs.Server.Log().WithField("error", err).Warn("failed to chown server data directory")
}
}
return nil