summaryrefslogtreecommitdiff
path: root/pkg/systemd/generate/common.go
diff options
context:
space:
mode:
authorNirmal Patel <npate012@gmail.com>2022-02-19 17:55:23 -0500
committerNirmal Patel <npate012@gmail.com>2022-03-16 20:26:59 -0400
commit714e5a13d9586ac6a3a6a1ee1b2ec15a43058350 (patch)
treecf09301df89228e663fa68ef3947c1962fd92d51 /pkg/systemd/generate/common.go
parentb1d37a7e21bfb3e12af2e7cee25dc88ac4f148dd (diff)
downloadpodman-714e5a13d9586ac6a3a6a1ee1b2ec15a43058350.tar.gz
podman-714e5a13d9586ac6a3a6a1ee1b2ec15a43058350.tar.bz2
podman-714e5a13d9586ac6a3a6a1ee1b2ec15a43058350.zip
Separator is no longer prepended when prefix is empty on podman generate systemd
When podman generate systemd is invoked, it previously did not check if container-prefix or pod-prefix are empty. When these are empty, the file name starts with the separator, which is hyphen by default. This results in files like '-containername.service'. The code now checks if these prefixes are empty. If they are, the filename no longer adds a separator. Instead, it uses name or ID of the container or pod. Closes #13272 Signed-off-by: Nirmal Patel <npate012@gmail.com>
Diffstat (limited to 'pkg/systemd/generate/common.go')
-rw-r--r--pkg/systemd/generate/common.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/pkg/systemd/generate/common.go b/pkg/systemd/generate/common.go
index a6f8f7cd4..e53d37897 100644
--- a/pkg/systemd/generate/common.go
+++ b/pkg/systemd/generate/common.go
@@ -137,3 +137,17 @@ func removeArg(arg string, args []string) []string {
}
return newArgs
}
+
+// This function is used to get name of systemd service from prefix, separator, and
+// container/pod name. If prefix is empty, the service name does not include the
+// separator. This is to avoid a situation where service name starts with the separator
+// which is usually hyphen.
+func getServiceName(prefix string, separator string, name string) string {
+ serviceName := name
+
+ if len(prefix) > 0 {
+ serviceName = prefix + separator + name
+ }
+
+ return serviceName
+}