Add basic support for creating a server on wings

This commit is contained in:
Dane Everitt
2019-11-16 15:48:50 -08:00
parent 22e6ce2f7e
commit f0da1eeb48
4 changed files with 93 additions and 15 deletions

View File

@@ -3,6 +3,7 @@ package server
import (
"bufio"
"bytes"
"context"
"encoding/json"
"fmt"
"github.com/docker/docker/api/types"
@@ -14,7 +15,6 @@ import (
"github.com/pkg/errors"
"github.com/pterodactyl/wings/api"
"go.uber.org/zap"
"golang.org/x/net/context"
"io"
"os"
"strconv"
@@ -385,6 +385,8 @@ func (d *DockerEnvironment) DisableResourcePolling() error {
// Creates a new container for the server using all of the data that is currently
// available for it. If the container already exists it will be returned.
//
// @todo pull the image being requested if it doesn't exist currently.
func (d *DockerEnvironment) Create() error {
ctx := context.Background()
cli, err := client.NewClientWithOpts(client.FromEnv)
@@ -394,6 +396,11 @@ func (d *DockerEnvironment) Create() error {
var oomDisabled = true
// Ensure the data directory exists before getting too far through this process.
if err := d.Server.Filesystem.EnsureDataDirectory(); err != nil {
return err
}
// If the container already exists don't hit the user with an error, just return
// the current information about it which is what we would do when creating the
// container anyways.

View File

@@ -553,3 +553,18 @@ func (fs *Filesystem) ListDirectory(p string) ([]*Stat, error) {
return out, nil
}
// Ensures that the data directory for the server instance exists.
func (fs *Filesystem) EnsureDataDirectory() error {
if _, err := os.Stat(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(fs.Path(), 0600); err != nil {
return err
}
}
return nil
}