diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-09-05 06:42:36 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-05 06:42:36 -0400 |
commit | f1323a941c7b5709197def5d10ad79ed24bbbc35 (patch) | |
tree | 3d0e1b98c20b4d5191f86b57d8197bf6daadf4f5 /pkg/systemd/generate/containers.go | |
parent | 6862cc667761fe3cb8dd45a3491cdca977d493cf (diff) | |
parent | ebfea2f4f89328ec3f74a8deedb3e727ce89ea59 (diff) | |
download | podman-f1323a941c7b5709197def5d10ad79ed24bbbc35.tar.gz podman-f1323a941c7b5709197def5d10ad79ed24bbbc35.tar.bz2 podman-f1323a941c7b5709197def5d10ad79ed24bbbc35.zip |
Merge pull request #7329 from Luap99/generate-systemd-remote
APIv2 add generate systemd endpoint
Diffstat (limited to 'pkg/systemd/generate/containers.go')
-rw-r--r-- | pkg/systemd/generate/containers.go | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/pkg/systemd/generate/containers.go b/pkg/systemd/generate/containers.go index 5f6376977..caf5de357 100644 --- a/pkg/systemd/generate/containers.go +++ b/pkg/systemd/generate/containers.go @@ -3,9 +3,7 @@ package generate import ( "bytes" "fmt" - "io/ioutil" "os" - "path/filepath" "sort" "strings" "text/template" @@ -87,17 +85,22 @@ KillMode=none Type=forking [Install] -WantedBy=multi-user.target default.target` +WantedBy=multi-user.target default.target +` // ContainerUnit generates a systemd unit for the specified container. Based // on the options, the return value might be the entire unit or a file it has // been written to. -func ContainerUnit(ctr *libpod.Container, options entities.GenerateSystemdOptions) (string, error) { +func ContainerUnit(ctr *libpod.Container, options entities.GenerateSystemdOptions) (string, string, error) { info, err := generateContainerInfo(ctr, options) if err != nil { - return "", err + return "", "", err + } + content, err := executeContainerTemplate(info, options) + if err != nil { + return "", "", err } - return executeContainerTemplate(info, options) + return info.ServiceName, content, nil } func generateContainerInfo(ctr *libpod.Container, options entities.GenerateSystemdOptions) (*containerInfo, error) { @@ -288,18 +291,5 @@ func executeContainerTemplate(info *containerInfo, options entities.GenerateSyst return "", err } - if !options.Files { - return buf.String(), nil - } - - buf.WriteByte('\n') - cwd, err := os.Getwd() - if err != nil { - return "", errors.Wrap(err, "error getting current working directory") - } - path := filepath.Join(cwd, fmt.Sprintf("%s.service", info.ServiceName)) - if err := ioutil.WriteFile(path, buf.Bytes(), 0644); err != nil { - return "", errors.Wrap(err, "error generating systemd unit") - } - return path, nil + return buf.String(), nil } |