Skip to content

Commit

Permalink
redefine restart and keep backward compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
CMGS committed Feb 19, 2021
1 parent 86cafe8 commit 9c67219
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 22 deletions.
16 changes: 7 additions & 9 deletions engine/docker/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ import (
)

const (
minMemory = units.MiB * 4
maxMemory = math.MaxInt64
restartAlways = "always"
root = "root"
minMemory = units.MiB * 4
maxMemory = math.MaxInt64
root = "root"
)

type rawArgs struct {
Expand All @@ -57,11 +56,10 @@ func (e *Engine) VirtualizationCreate(ctx context.Context, opts *enginetypes.Vir

restartPolicy := ""
restartRetry := 0
if opts.Restart == -1 || opts.Restart > 0 {
restartPolicy = restartAlways
}
if opts.Restart > 0 {
restartRetry = opts.Restart
restartStr := strings.Split(opts.Restart, ":")
restartPolicy = restartStr[0]
if r, err := strconv.Atoi(restartStr[len(restartStr)-1]); err != nil {
restartRetry = r
}
// no longer use opts.Network as networkmode
// always get network name from networks
Expand Down
13 changes: 8 additions & 5 deletions engine/systemd/unit.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,14 @@ func (b *unitBuilder) buffer() (*bytes.Buffer, error) {
return bytes.NewBufferString(unit), b.err
}

func (b *unitBuilder) convertToSystemdRestartPolicy(restart int) (policy string) {
if restart == 0 {
return "no"
}
return "always"
func (b *unitBuilder) convertToSystemdRestartPolicy(restart string) (policy string) {
switch {
case restart == "always":
return "always"
case strings.HasPrefix(restart, "on-failure"):
return "on-failure"
}
return "no"
}

func (b *unitBuilder) convertToSystemdStdio(logType string) (stdioType string, err error) {
Expand Down
2 changes: 1 addition & 1 deletion engine/types/virtualization.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type VirtualizationCreateOptions struct {
Labels map[string]string

Debug bool
Restart int
Restart string

Networks map[string]string

Expand Down
8 changes: 4 additions & 4 deletions rpc/gen/core.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rpc/gen/core.proto
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ message EntrypointOptions {
repeated string publish = 6;
HealthCheckOptions healthcheck = 7;
HookOptions hook = 8;
int32 restart = 9;
string restart = 9;
map<string, string> sysctls = 10;
}

Expand Down
2 changes: 1 addition & 1 deletion rpc/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func toCoreDeployOptions(d *pb.DeployOptions) (*types.DeployOptions, error) {
Privileged: entrypoint.Privileged,
Dir: entrypoint.Dir,
Publish: entrypoint.Publish,
Restart: int(entrypoint.Restart),
Restart: entrypoint.Restart,
Sysctls: entrypoint.Sysctls,
}

Expand Down
2 changes: 1 addition & 1 deletion types/specs.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Entrypoint struct {
Publish []string `yaml:"publish,omitempty,flow"`
HealthCheck *HealthCheck `yaml:"healthcheck,omitempty,flow"`
Hook *Hook `yaml:"hook,omitempty,flow"`
Restart int `yaml:"restart,omitempty"`
Restart string `yaml:"restart,omitempty"`
Sysctls map[string]string `yaml:"sysctls,omitempty,flow"`
}

Expand Down

0 comments on commit 9c67219

Please sign in to comment.