diff --git a/docs/source/markdown/podman-systemd.unit.5.md b/docs/source/markdown/podman-systemd.unit.5.md index 7fa1301248..6490554acd 100644 --- a/docs/source/markdown/podman-systemd.unit.5.md +++ b/docs/source/markdown/podman-systemd.unit.5.md @@ -863,6 +863,7 @@ Valid options for `[Pod]` are listed below: | PodmanArgs=\-\-cpus=2 | --cpus=2 | | PodName=name | --name=name | | PublishPort=50-59 | --publish 50-59 | +| ServiceName=name | Name the systemd unit `name.service` | | Volume=/source:/dest | --volume /source:/dest | Supported keys in the `[Pod]` section are: @@ -947,6 +948,14 @@ When using `host` networking via `Network=host`, the `PublishPort=` option canno This key can be listed multiple times. + +### `ServiceName=` + +By default, Quadlet will name the systemd service unit by appending `-pod` to the name of the Quadlet. +Setting this key overrides this behavior by instructing Quadlet to use the provided name. + +Note, the name should not include the `.service` file extension + ### `Volume=` Mount a volume in the pod. This is equivalent to the Podman `--volume` option, and diff --git a/pkg/systemd/quadlet/quadlet.go b/pkg/systemd/quadlet/quadlet.go index 329f3883bc..f02ca54c8e 100644 --- a/pkg/systemd/quadlet/quadlet.go +++ b/pkg/systemd/quadlet/quadlet.go @@ -143,6 +143,7 @@ const ( KeySecurityLabelLevel = "SecurityLabelLevel" KeySecurityLabelNested = "SecurityLabelNested" KeySecurityLabelType = "SecurityLabelType" + KeyServiceName = "ServiceName" KeySetWorkingDirectory = "SetWorkingDirectory" KeyShmSize = "ShmSize" KeyStopSignal = "StopSignal" @@ -373,6 +374,7 @@ var ( KeyPodName: true, KeyPodmanArgs: true, KeyPublishPort: true, + KeyServiceName: true, KeyVolume: true, } ) @@ -1474,6 +1476,9 @@ func GetBuiltImageName(buildUnit *parser.UnitFile) string { } func GetPodServiceName(podUnit *parser.UnitFile) string { + if serviceName, ok := podUnit.Lookup(PodGroup, KeyServiceName); ok { + return serviceName + } return replaceExtension(podUnit.Filename, "", "", "-pod") } diff --git a/test/e2e/quadlet/service-name.pod b/test/e2e/quadlet/service-name.pod new file mode 100644 index 0000000000..6f2842e083 --- /dev/null +++ b/test/e2e/quadlet/service-name.pod @@ -0,0 +1,5 @@ +## assert-podman-pre-args "--name=test-pod" + +[Pod] +PodName=test-pod +ServiceName=test-pod