Update stop for servers to use configuration
This commit is contained in:
parent
d7753d9c7f
commit
00bc71afd1
|
@ -8,6 +8,12 @@ import (
|
|||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
const (
|
||||
ProcessStopCommand = "command"
|
||||
ProcessStopSignal = "signal"
|
||||
ProcessStopNativeStop = "stop"
|
||||
)
|
||||
|
||||
// Defines a single find/replace instance for a given server configuration file.
|
||||
type ConfigurationFileReplacement struct {
|
||||
Match string `json:"match"`
|
||||
|
|
|
@ -12,6 +12,7 @@ import (
|
|||
"github.com/docker/docker/daemon/logger/jsonfilelog"
|
||||
"github.com/docker/go-connections/nat"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/pterodactyl/wings/api"
|
||||
"go.uber.org/zap"
|
||||
"golang.org/x/net/context"
|
||||
"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
|
||||
// seconds to pass before a failure occurs.
|
||||
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)
|
||||
if stop.Type == api.ProcessStopCommand {
|
||||
return d.SendCommand(stop.Value)
|
||||
}
|
||||
|
||||
t := time.Second * 10
|
||||
|
||||
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)
|
||||
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
|
||||
|
|
|
@ -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
|
||||
// where the server is already running and the Daemon reboots. In those cases this will
|
||||
// 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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user