diff options
Diffstat (limited to 'pkg/systemd/generate')
-rw-r--r-- | pkg/systemd/generate/common.go | 11 | ||||
-rw-r--r-- | pkg/systemd/generate/containers.go | 3 | ||||
-rw-r--r-- | pkg/systemd/generate/containers_test.go | 41 | ||||
-rw-r--r-- | pkg/systemd/generate/pods.go | 3 |
4 files changed, 27 insertions, 31 deletions
diff --git a/pkg/systemd/generate/common.go b/pkg/systemd/generate/common.go index bbd1a5f92..94a6f4cb5 100644 --- a/pkg/systemd/generate/common.go +++ b/pkg/systemd/generate/common.go @@ -4,25 +4,18 @@ import ( "strconv" "strings" + "github.com/containers/podman/v3/pkg/systemd/define" "github.com/pkg/errors" ) -// EnvVariable "PODMAN_SYSTEMD_UNIT" is set in all generated systemd units and -// is set to the unit's (unique) name. -const EnvVariable = "PODMAN_SYSTEMD_UNIT" - // minTimeoutStopSec is the minimal stop timeout for generated systemd units. // Once exceeded, processes of the services are killed and the cgroup(s) are // cleaned up. const minTimeoutStopSec = 60 -// RestartPolicies includes all valid restart policies to be used in a unit -// file. -var RestartPolicies = []string{"no", "on-success", "on-failure", "on-abnormal", "on-watchdog", "on-abort", "always"} - // validateRestartPolicy checks that the user-provided policy is valid. func validateRestartPolicy(restart string) error { - for _, i := range RestartPolicies { + for _, i := range define.RestartPolicies { if i == restart { return nil } diff --git a/pkg/systemd/generate/containers.go b/pkg/systemd/generate/containers.go index 92c6d8865..9343a5067 100644 --- a/pkg/systemd/generate/containers.go +++ b/pkg/systemd/generate/containers.go @@ -11,6 +11,7 @@ import ( "github.com/containers/podman/v3/libpod" "github.com/containers/podman/v3/pkg/domain/entities" + "github.com/containers/podman/v3/pkg/systemd/define" "github.com/containers/podman/v3/version" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -173,7 +174,7 @@ func executeContainerTemplate(info *containerInfo, options entities.GenerateSyst info.Executable = executable } - info.EnvVariable = EnvVariable + info.EnvVariable = define.EnvVariable info.ExecStart = "{{{{.Executable}}}} start {{{{.ContainerNameOrID}}}}" info.ExecStop = "{{{{.Executable}}}} stop {{{{if (ge .StopTimeout 0)}}}}-t {{{{.StopTimeout}}}}{{{{end}}}} {{{{.ContainerNameOrID}}}}" info.ExecStopPost = "{{{{.Executable}}}} stop {{{{if (ge .StopTimeout 0)}}}}-t {{{{.StopTimeout}}}}{{{{end}}}} {{{{.ContainerNameOrID}}}}" diff --git a/pkg/systemd/generate/containers_test.go b/pkg/systemd/generate/containers_test.go index 747c54699..ebbbdb786 100644 --- a/pkg/systemd/generate/containers_test.go +++ b/pkg/systemd/generate/containers_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/containers/podman/v3/pkg/domain/entities" + "github.com/containers/podman/v3/pkg/systemd/define" "github.com/stretchr/testify/assert" ) @@ -398,7 +399,7 @@ WantedBy=multi-user.target default.target PIDFile: "/run/containers/storage/overlay-containers/639c53578af4d84b8800b4635fa4e680ee80fd67e0e6a2d4eea48d1e3230f401/userdata/conmon.pid", StopTimeout: 22, PodmanVersion: "CI", - EnvVariable: EnvVariable, + EnvVariable: define.EnvVariable, }, goodID, false, @@ -414,7 +415,7 @@ WantedBy=multi-user.target default.target PIDFile: "/run/containers/storage/overlay-containers/639c53578af4d84b8800b4635fa4e680ee80fd67e0e6a2d4eea48d1e3230f401/userdata/conmon.pid", StopTimeout: 22, PodmanVersion: "CI", - EnvVariable: EnvVariable, + EnvVariable: define.EnvVariable, }, goodIDNoHeaderInfo, false, @@ -430,7 +431,7 @@ WantedBy=multi-user.target default.target PIDFile: "/run/containers/storage/overlay-containers/639c53578af4d84b8800b4635fa4e680ee80fd67e0e6a2d4eea48d1e3230f401/userdata/conmon.pid", StopTimeout: 10, PodmanVersion: "CI", - EnvVariable: EnvVariable, + EnvVariable: define.EnvVariable, }, goodName, false, @@ -447,7 +448,7 @@ WantedBy=multi-user.target default.target StopTimeout: 10, PodmanVersion: "CI", BoundToServices: []string{"pod", "a", "b", "c"}, - EnvVariable: EnvVariable, + EnvVariable: define.EnvVariable, }, goodNameBoundTo, false, @@ -462,7 +463,7 @@ WantedBy=multi-user.target default.target PIDFile: "/run/containers/storage/overlay-containers/639c53578af4d84b8800b4635fa4e680ee80fd67e0e6a2d4eea48d1e3230f401/userdata/conmon.pid", StopTimeout: 10, PodmanVersion: "CI", - EnvVariable: EnvVariable, + EnvVariable: define.EnvVariable, }, "", false, @@ -479,7 +480,7 @@ WantedBy=multi-user.target default.target StopTimeout: 10, PodmanVersion: "CI", CreateCommand: []string{"I'll get stripped", "container", "run", "--name", "jadda-jadda", "--hostname", "hello-world", "awesome-image:latest", "command", "arg1", "...", "argN", "foo=arg \"with \" space"}, - EnvVariable: EnvVariable, + EnvVariable: define.EnvVariable, }, goodWithNameAndGeneric, true, @@ -496,7 +497,7 @@ WantedBy=multi-user.target default.target StopTimeout: 10, PodmanVersion: "CI", CreateCommand: []string{"I'll get stripped", "run", "-d", "--name", "jadda-jadda", "--hostname", "hello-world", "awesome-image:latest", "command", "arg1", "...", "argN"}, - EnvVariable: EnvVariable, + EnvVariable: define.EnvVariable, }, goodWithExplicitShortDetachParam, true, @@ -513,7 +514,7 @@ WantedBy=multi-user.target default.target StopTimeout: 10, PodmanVersion: "CI", CreateCommand: []string{"I'll get stripped", "run", "-d", "--name", "jadda-jadda", "--hostname", "hello-world", "awesome-image:latest", "command", "arg1", "...", "argN"}, - EnvVariable: EnvVariable, + EnvVariable: define.EnvVariable, Pod: &podInfo{ PodIDFile: "%t/pod-foobar.pod-id-file", }, @@ -533,7 +534,7 @@ WantedBy=multi-user.target default.target StopTimeout: 10, PodmanVersion: "CI", CreateCommand: []string{"I'll get stripped", "run", "--detach", "--name", "jadda-jadda", "--hostname", "hello-world", "awesome-image:latest", "command", "arg1", "...", "argN"}, - EnvVariable: EnvVariable, + EnvVariable: define.EnvVariable, }, goodNameNewDetach, true, @@ -550,7 +551,7 @@ WantedBy=multi-user.target default.target StopTimeout: 10, PodmanVersion: "CI", CreateCommand: []string{"I'll get stripped", "run", "awesome-image:latest"}, - EnvVariable: EnvVariable, + EnvVariable: define.EnvVariable, }, goodIDNew, true, @@ -567,7 +568,7 @@ WantedBy=multi-user.target default.target StopTimeout: 42, PodmanVersion: "CI", CreateCommand: []string{"I'll get stripped", "run", "--detach=true", "awesome-image:latest"}, - EnvVariable: EnvVariable, + EnvVariable: define.EnvVariable, }, genGoodNewDetach("--detach=true"), true, @@ -584,7 +585,7 @@ WantedBy=multi-user.target default.target StopTimeout: 42, PodmanVersion: "CI", CreateCommand: []string{"I'll get stripped", "run", "--detach=false", "awesome-image:latest"}, - EnvVariable: EnvVariable, + EnvVariable: define.EnvVariable, }, genGoodNewDetach("-d"), true, @@ -601,7 +602,7 @@ WantedBy=multi-user.target default.target StopTimeout: 42, PodmanVersion: "CI", CreateCommand: []string{"I'll get stripped", "run", "--name", "test", "-p", "80:80", "--detach=false", "awesome-image:latest", "somecmd", "--detach=false"}, - EnvVariable: EnvVariable, + EnvVariable: define.EnvVariable, }, goodNameNewDetachFalseWithCmd, true, @@ -618,7 +619,7 @@ WantedBy=multi-user.target default.target StopTimeout: 42, PodmanVersion: "CI", CreateCommand: []string{"I'll get stripped", "run", "--name", "test", "-p", "80:80", "--detach=false", "--detach=false", "awesome-image:latest", "somecmd", "--detach=false"}, - EnvVariable: EnvVariable, + EnvVariable: define.EnvVariable, }, goodNameNewDetachFalseWithCmd, true, @@ -635,7 +636,7 @@ WantedBy=multi-user.target default.target StopTimeout: 42, PodmanVersion: "CI", CreateCommand: []string{"I'll get stripped", "run", "-dti", "awesome-image:latest"}, - EnvVariable: EnvVariable, + EnvVariable: define.EnvVariable, }, genGoodNewDetach("-dti"), true, @@ -652,7 +653,7 @@ WantedBy=multi-user.target default.target StopTimeout: 42, PodmanVersion: "CI", CreateCommand: []string{"I'll get stripped", "run", "-tid", "awesome-image:latest"}, - EnvVariable: EnvVariable, + EnvVariable: define.EnvVariable, }, genGoodNewDetach("-tid"), true, @@ -669,7 +670,7 @@ WantedBy=multi-user.target default.target StopTimeout: 42, PodmanVersion: "CI", CreateCommand: []string{"I'll get stripped", "--events-backend", "none", "--runroot", "/root", "run", "awesome-image:latest"}, - EnvVariable: EnvVariable, + EnvVariable: define.EnvVariable, }, goodNewRootFlags, true, @@ -686,7 +687,7 @@ WantedBy=multi-user.target default.target StopTimeout: 10, PodmanVersion: "CI", CreateCommand: []string{"I'll get stripped", "container", "create", "awesome-image:latest"}, - EnvVariable: EnvVariable, + EnvVariable: define.EnvVariable, }, goodContainerCreate, true, @@ -703,7 +704,7 @@ WantedBy=multi-user.target default.target StopTimeout: 10, PodmanVersion: "CI", CreateCommand: []string{"I'll get stripped", "create", "--name", "test", "--log-driver=journald", "--log-opt=tag={{.Name}}", "awesome-image:latest"}, - EnvVariable: EnvVariable, + EnvVariable: define.EnvVariable, }, goodNewWithJournaldTag, true, @@ -720,7 +721,7 @@ WantedBy=multi-user.target default.target StopTimeout: 10, PodmanVersion: "CI", CreateCommand: []string{"I'll get stripped", "create", "--name", "test", "awesome-image:latest", "sh", "-c", "kill $$ && echo %\\"}, - EnvVariable: EnvVariable, + EnvVariable: define.EnvVariable, }, goodNewWithSpecialChars, true, diff --git a/pkg/systemd/generate/pods.go b/pkg/systemd/generate/pods.go index 8c0401278..f96058d36 100644 --- a/pkg/systemd/generate/pods.go +++ b/pkg/systemd/generate/pods.go @@ -11,6 +11,7 @@ import ( "github.com/containers/podman/v3/libpod" "github.com/containers/podman/v3/pkg/domain/entities" + "github.com/containers/podman/v3/pkg/systemd/define" "github.com/containers/podman/v3/version" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -237,7 +238,7 @@ func executePodTemplate(info *podInfo, options entities.GenerateSystemdOptions) info.Executable = executable } - info.EnvVariable = EnvVariable + info.EnvVariable = define.EnvVariable info.ExecStart = "{{{{.Executable}}}} start {{{{.InfraNameOrID}}}}" info.ExecStop = "{{{{.Executable}}}} stop {{{{if (ge .StopTimeout 0)}}}}-t {{{{.StopTimeout}}}}{{{{end}}}} {{{{.InfraNameOrID}}}}" info.ExecStopPost = "{{{{.Executable}}}} stop {{{{if (ge .StopTimeout 0)}}}}-t {{{{.StopTimeout}}}}{{{{end}}}} {{{{.InfraNameOrID}}}}" |