From 7f4c29580a58c61f5e7410b48f835b11ed9a1b18 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sun, 24 Nov 2019 13:04:24 -0800 Subject: [PATCH] Create the container if the server is booted and it is missing --- server/environment_docker.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/server/environment_docker.go b/server/environment_docker.go index 7ba10f3..43eaf44 100644 --- a/server/environment_docker.go +++ b/server/environment_docker.go @@ -128,8 +128,12 @@ func (d *DockerEnvironment) OnBeforeStart() error { return nil } -// Checks if there is a container that already exists for the server. If so that -// container is started. If there is no container, one is created and then started. +// Starts the server environment and begins piping output to the event listeners for the +// console. +// +// This process will also confirm that the server environment exists and is in a bootable +// state. This ensures that unexpected container deletion while Wings is running does +// not result in the server becoming unbootable. func (d *DockerEnvironment) Start() error { sawError := false // If sawError is set to true there was an error somewhere in the pipeline that @@ -141,6 +145,17 @@ func (d *DockerEnvironment) Start() error { } }() + // The Create() function will check if the container exists in the first place, and if + // so just silently return without an error. Otherwise, it will try to create the necessary + // container and data storage directory. + // + // This won't actually run an installation process however, it is just here to ensure the + // environment gets created properly if it is missing and the server is started. We're making + // an assumption that all of the files will still exist at this point. + if err := d.Create(); err != nil { + return errors.WithStack(err) + } + c, err := d.Client.ContainerInspect(context.Background(), d.Server.Uuid) if err != nil { return errors.WithStack(err)