Update stop for servers to use configuration

This commit is contained in:
Dane Everitt 2019-09-22 21:22:16 -07:00
parent d7753d9c7f
commit 00bc71afd1
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
3 changed files with 29 additions and 6 deletions

View File

@ -8,6 +8,12 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
) )
const (
ProcessStopCommand = "command"
ProcessStopSignal = "signal"
ProcessStopNativeStop = "stop"
)
// Defines a single find/replace instance for a given server configuration file. // Defines a single find/replace instance for a given server configuration file.
type ConfigurationFileReplacement struct { type ConfigurationFileReplacement struct {
Match string `json:"match"` Match string `json:"match"`

View File

@ -12,6 +12,7 @@ import (
"github.com/docker/docker/daemon/logger/jsonfilelog" "github.com/docker/docker/daemon/logger/jsonfilelog"
"github.com/docker/go-connections/nat" "github.com/docker/go-connections/nat"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/pterodactyl/wings/api"
"go.uber.org/zap" "go.uber.org/zap"
"golang.org/x/net/context" "golang.org/x/net/context"
"io" "io"
@ -191,9 +192,18 @@ func (d *DockerEnvironment) Start() error {
// Stops the container that the server is running in. This will allow up to 10 // Stops the container that the server is running in. This will allow up to 10
// seconds to pass before a failure occurs. // seconds to pass before a failure occurs.
func (d *DockerEnvironment) Stop() error { func (d *DockerEnvironment) Stop() error {
t := time.Second * 10 stop := d.Server.processConfiguration.Stop
if stop.Type == api.ProcessStopSignal {
return d.Terminate(os.Kill)
}
d.Server.SetState(ProcessStoppingState) d.Server.SetState(ProcessStoppingState)
if stop.Type == api.ProcessStopCommand {
return d.SendCommand(stop.Value)
}
t := time.Second * 10
return d.Client.ContainerStop(context.Background(), d.Server.Uuid, &t) return d.Client.ContainerStop(context.Background(), d.Server.Uuid, &t)
} }
@ -211,7 +221,10 @@ func (d *DockerEnvironment) Terminate(signal os.Signal) error {
} }
d.Server.SetState(ProcessStoppingState) d.Server.SetState(ProcessStoppingState)
return d.Client.ContainerKill(ctx, d.Server.Uuid, "SIGKILL")
return d.Client.ContainerKill(
ctx, d.Server.Uuid, strings.TrimPrefix("signal ", signal.String()),
)
} }
// Attaches to the docker container itself and ensures that we can pipe data in and out // Attaches to the docker container itself and ensures that we can pipe data in and out

View File

@ -218,7 +218,11 @@ func FromConfiguration(data []byte, cfg *config.SystemConfiguration) (*Server, e
// This is also done when the server is booted, however we need to account for instances // This is also done when the server is booted, however we need to account for instances
// where the server is already running and the Daemon reboots. In those cases this will // where the server is already running and the Daemon reboots. In those cases this will
// allow us to you know, stop servers. // allow us to you know, stop servers.
s.GetProcessConfiguration() if cfg, err := s.GetProcessConfiguration(); err != nil {
return nil, err
} else {
s.processConfiguration = cfg
}
return s, nil return s, nil
} }