generate systemd: drop support for remote clients

Drop the support for remote clients to generate systemd-service files.
The generated files are machine-dependent and hence relate only to the
a local machine.  Furthermore, a proper service management when using
a remote-client is not possible as systemd has no access to a process.

Dropping the support will also reduce the risk of making users believe
that the generated services are usable in a remote scenario.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
This commit is contained in:
Valentin Rothberg 2019-08-21 09:24:20 +02:00
parent 1ad8fe5241
commit a33e4a89ca
7 changed files with 12 additions and 37 deletions

7
API.md
View File

@ -49,8 +49,6 @@ in the [API.md](https://github.com/containers/libpod/blob/master/API.md) file in
[func GenerateKube(name: string, service: bool) KubePodService](#GenerateKube) [func GenerateKube(name: string, service: bool) KubePodService](#GenerateKube)
[func GenerateSystemd(name: string, restart: string, timeout: int, useName: bool) string](#GenerateSystemd)
[func GetAttachSockets(name: string) Sockets](#GetAttachSockets) [func GetAttachSockets(name: string) Sockets](#GetAttachSockets)
[func GetContainer(id: string) Container](#GetContainer) [func GetContainer(id: string) Container](#GetContainer)
@ -482,11 +480,6 @@ error will be returned. See also [ImportImage](ImportImage).
method GenerateKube(name: [string](https://godoc.org/builtin#string), service: [bool](https://godoc.org/builtin#bool)) [KubePodService](#KubePodService)</div> method GenerateKube(name: [string](https://godoc.org/builtin#string), service: [bool](https://godoc.org/builtin#bool)) [KubePodService](#KubePodService)</div>
GenerateKube generates a Kubernetes v1 Pod description of a Podman container or pod GenerateKube generates a Kubernetes v1 Pod description of a Podman container or pod
and its containers. The description is in YAML. See also [ReplayKube](ReplayKube). and its containers. The description is in YAML. See also [ReplayKube](ReplayKube).
### <a name="GenerateSystemd"></a>func GenerateSystemd
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">
method GenerateSystemd(name: [string](https://godoc.org/builtin#string), restart: [string](https://godoc.org/builtin#string), timeout: [int](https://godoc.org/builtin#int), useName: [bool](https://godoc.org/builtin#bool)) [string](https://godoc.org/builtin#string)</div>
### <a name="GetAttachSockets"></a>func GetAttachSockets ### <a name="GetAttachSockets"></a>func GetAttachSockets
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;"> <div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">

View File

@ -18,11 +18,14 @@ var (
// Commands that are universally implemented // Commands that are universally implemented
generateCommands = []*cobra.Command{ generateCommands = []*cobra.Command{
_containerKubeCommand, _containerKubeCommand,
_containerSystemdCommand,
} }
) )
func init() { func init() {
// Systemd-service generation is not supported for remote-clients.
if !remoteclient {
generateCommands = append(generateCommands, _containerSystemdCommand)
}
generateCommand.Command = _generateCommand generateCommand.Command = _generateCommand
generateCommand.AddCommand(generateCommands...) generateCommand.AddCommand(generateCommands...)
generateCommand.SetUsageTemplate(UsageTemplate()) generateCommand.SetUsageTemplate(UsageTemplate())

View File

@ -1241,8 +1241,6 @@ method GetLayersMapWithImageInfo() -> (layerMap: string)
# BuildImageHierarchyMap is for the development of Podman and should not be used. # BuildImageHierarchyMap is for the development of Podman and should not be used.
method BuildImageHierarchyMap(name: string) -> (imageInfo: string) method BuildImageHierarchyMap(name: string) -> (imageInfo: string)
method GenerateSystemd(name: string, restart: string, timeout: int, useName: bool) -> (unit: string)
# ImageNotFound means the image could not be found by the provided name or ID in local storage. # ImageNotFound means the image could not be found by the provided name or ID in local storage.
error ImageNotFound (id: string, reason: string) error ImageNotFound (id: string, reason: string)

View File

@ -11,6 +11,7 @@ podman-generate-systemd- Generate Systemd Unit file
command will dynamically create the unit file and output it to stdout where it can be piped by the user command will dynamically create the unit file and output it to stdout where it can be piped by the user
to a file. The options can be used to influence the results of the output as well. to a file. The options can be used to influence the results of the output as well.
Note that this command is not supported for the remote client.
## OPTIONS: ## OPTIONS:

View File

@ -11,10 +11,11 @@ The generate command will create structured output (like YAML) based on a contai
## COMMANDS ## COMMANDS
| Command | Man Page | Description | | Command | Man Page | Description |
| ------- | --------------------------------------------------- | ---------------------------------------------------------------------------- | |---------|------------------------------------------------------------|------------------------------------------------------------------------------------|
| kube | [podman-generate-kube(1)](podman-generate-kube.1.md)| Generate Kubernetes YAML based on a pod or container. | | kube | [podman-generate-kube(1)](podman-generate-kube.1.md) | Generate Kubernetes YAML based on a pod or container. |
| systemd | [podman-generate-systemd(1)](podman-generate-systemd.1.md)| Generate a systemd unit file for a container. | | systemd | [podman-generate-systemd(1)](podman-generate-systemd.1.md) | Generate a systemd unit file for a container. Not supported for the remote client. |
## SEE ALSO ## SEE ALSO
podman, podman-pod, podman-container podman, podman-pod, podman-container

View File

@ -951,7 +951,7 @@ func (r *LocalRuntime) Port(c *cliconfig.PortValues) ([]*Container, error) {
// GenerateSystemd creates a systemd until for a container // GenerateSystemd creates a systemd until for a container
func (r *LocalRuntime) GenerateSystemd(c *cliconfig.GenerateSystemdValues) (string, error) { func (r *LocalRuntime) GenerateSystemd(c *cliconfig.GenerateSystemdValues) (string, error) {
return iopodman.GenerateSystemd().Call(r.Conn, c.InputArgs[0], c.RestartPolicy, int64(c.StopTimeout), c.Name) return "", errors.New("systemd generation not supported for remote clients")
} }
// GetNamespaces returns namespace information about a container for PS // GetNamespaces returns namespace information about a container for PS

View File

@ -4,9 +4,9 @@ package varlinkapi
import ( import (
"encoding/json" "encoding/json"
"github.com/containers/libpod/cmd/podman/shared" "github.com/containers/libpod/cmd/podman/shared"
iopodman "github.com/containers/libpod/cmd/podman/varlink" iopodman "github.com/containers/libpod/cmd/podman/varlink"
"github.com/containers/libpod/pkg/systemdgen"
) )
// GenerateKube ... // GenerateKube ...
@ -29,24 +29,3 @@ func (i *LibpodAPI) GenerateKube(call iopodman.VarlinkCall, name string, service
Service: string(servB), Service: string(servB),
}) })
} }
// GenerateSystemd ...
func (i *LibpodAPI) GenerateSystemd(call iopodman.VarlinkCall, nameOrID, restart string, stopTimeout int64, useName bool) error {
ctr, err := i.Runtime.LookupContainer(nameOrID)
if err != nil {
return call.ReplyErrorOccurred(err.Error())
}
timeout := int(ctr.StopTimeout())
if stopTimeout >= 0 {
timeout = int(stopTimeout)
}
name := ctr.ID()
if useName {
name = ctr.Name()
}
unit, err := systemdgen.CreateSystemdUnitAsString(name, ctr.ID(), restart, ctr.Config().StaticDir, timeout)
if err != nil {
return call.ReplyErrorOccurred(err.Error())
}
return call.ReplyGenerateSystemd(unit)
}