diff options
author | Paul Holzinger <paul.holzinger@web.de> | 2020-08-05 09:29:59 +0200 |
---|---|---|
committer | Paul Holzinger <paul.holzinger@web.de> | 2020-09-02 22:06:19 +0200 |
commit | ebfea2f4f89328ec3f74a8deedb3e727ce89ea59 (patch) | |
tree | efbc2519efc370db670948a6e3a709e4a7e5f2d0 /pkg/systemd/generate/containers.go | |
parent | 1184cdf03d8464451d36b24643e57b65a8b97980 (diff) | |
download | podman-ebfea2f4f89328ec3f74a8deedb3e727ce89ea59.tar.gz podman-ebfea2f4f89328ec3f74a8deedb3e727ce89ea59.tar.bz2 podman-ebfea2f4f89328ec3f74a8deedb3e727ce89ea59.zip |
APIv2 add generate systemd endpoint
Add support for generating systemd units
via the api and podman-remote.
Change the GenerateSystemdReport type to return the
units as map[string]string with the unit name as key.
Add `--format` flag to `podman generate systemd`
to allow the output to be formatted as json.
Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
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 } |