diff options
author | esendjer <esendjer@gmail.com> | 2022-01-19 14:56:37 +0500 |
---|---|---|
committer | esendjer <esendjer@gmail.com> | 2022-01-19 21:46:16 +0500 |
commit | b9a2d8698a22c4b267e252caad56d8b31fcadd38 (patch) | |
tree | f5506687b939bdc29e2324b1335d3f9c4632f340 /pkg/systemd/generate/containers.go | |
parent | 094b11cbcb528a7d120c31402a1bcd9c82d84938 (diff) | |
download | podman-b9a2d8698a22c4b267e252caad56d8b31fcadd38.tar.gz podman-b9a2d8698a22c4b267e252caad56d8b31fcadd38.tar.bz2 podman-b9a2d8698a22c4b267e252caad56d8b31fcadd38.zip |
Handlers for `generate systemd` with custom dependencies
This commit includes:
* Handlers for generate systemd unit
with manually defined dependencies such as:
Wants=, After= and Requires=
* The new unit and e2e tests for checking generated systemd units
for container and pod with custom dependencies
* Documented descriptions for custom dependencies options
Signed-off-by: Eugene (Evgenii) Shubin <esendjer@gmail.com>
Diffstat (limited to 'pkg/systemd/generate/containers.go')
-rw-r--r-- | pkg/systemd/generate/containers.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/pkg/systemd/generate/containers.go b/pkg/systemd/generate/containers.go index fd5c247f3..ea829c810 100644 --- a/pkg/systemd/generate/containers.go +++ b/pkg/systemd/generate/containers.go @@ -94,6 +94,13 @@ type containerInfo struct { RunRoot string // Add %i and %I to description and execute parts IdentifySpecifier bool + // Wants are the list of services that this service is (weak) dependent on. This + // option does not influence the order in which services are started or stopped. + Wants []string + // After ordering dependencies between the list of services and this service. + After []string + // Similar to Wants, but declares a stronger requirement dependency. + Requires []string } const containerTemplate = headerTemplate + ` @@ -101,6 +108,19 @@ const containerTemplate = headerTemplate + ` BindsTo={{{{- range $index, $value := .BoundToServices -}}}}{{{{if $index}}}} {{{{end}}}}{{{{ $value }}}}.service{{{{end}}}} After={{{{- range $index, $value := .BoundToServices -}}}}{{{{if $index}}}} {{{{end}}}}{{{{ $value }}}}.service{{{{end}}}} {{{{- end}}}} +{{{{- if or .Wants .After .Requires }}}} + +# User-defined dependencies +{{{{- end}}}} +{{{{- if .Wants}}}} +Wants={{{{- range $index, $value := .Wants }}}}{{{{ if $index}}}} {{{{end}}}}{{{{ $value }}}}{{{{end}}}} +{{{{- end}}}} +{{{{- if .After}}}} +After={{{{- range $index, $value := .After }}}}{{{{ if $index}}}} {{{{end}}}}{{{{ $value }}}}{{{{end}}}} +{{{{- end}}}} +{{{{- if .Requires}}}} +Requires={{{{- range $index, $value := .Requires }}}}{{{{ if $index}}}} {{{{end}}}}{{{{ $value }}}}{{{{end}}}} +{{{{- end}}}} [Service] Environment={{{{.EnvVariable}}}}=%n{{{{- if (eq .IdentifySpecifier true) }}}}-%i{{{{- end}}}} @@ -201,6 +221,9 @@ func generateContainerInfo(ctr *libpod.Container, options entities.GenerateSyste CreateCommand: createCommand, RunRoot: runRoot, containerEnv: envs, + Wants: options.Wants, + After: options.After, + Requires: options.Requires, } return &info, nil |