summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2020-06-05 10:44:16 -0400
committerDaniel J Walsh <dwalsh@redhat.com>2020-06-05 13:01:57 -0400
commitc8f57b71a4255938efa23fec37c59181c1c657e4 (patch)
tree0195dcfa6421bbb079e2b75918250eb5e7d4a2ae /pkg
parentc448c03269139dabf6f6fa7ff0fedb2291018b2a (diff)
downloadpodman-c8f57b71a4255938efa23fec37c59181c1c657e4.tar.gz
podman-c8f57b71a4255938efa23fec37c59181c1c657e4.tar.bz2
podman-c8f57b71a4255938efa23fec37c59181c1c657e4.zip
Fix handling of systemd.
Systemd enablement has to happen on the server side, since we need check if the image is running systemd. Also need to make sure user setting the StopSignal is not overriden on the server side. But if not set and using systemd, we set it correctly. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'pkg')
-rw-r--r--pkg/specgen/container_validate.go2
-rw-r--r--pkg/specgen/generate/container_create.go38
2 files changed, 38 insertions, 2 deletions
diff --git a/pkg/specgen/container_validate.go b/pkg/specgen/container_validate.go
index 75da38c0e..2c5891f9a 100644
--- a/pkg/specgen/container_validate.go
+++ b/pkg/specgen/container_validate.go
@@ -38,7 +38,7 @@ func (s *SpecGenerator) Validate() error {
}
// systemd values must be true, false, or always
if len(s.ContainerBasicConfig.Systemd) > 0 && !util.StringInSlice(strings.ToLower(s.ContainerBasicConfig.Systemd), SystemDValues) {
- return errors.Wrapf(ErrInvalidSpecConfig, "SystemD values must be one of %s", strings.Join(SystemDValues, ","))
+ return errors.Wrapf(ErrInvalidSpecConfig, "--systemd values must be one of %q", strings.Join(SystemDValues, ", "))
}
//
diff --git a/pkg/specgen/generate/container_create.go b/pkg/specgen/generate/container_create.go
index de398d1e3..74ae848af 100644
--- a/pkg/specgen/generate/container_create.go
+++ b/pkg/specgen/generate/container_create.go
@@ -3,12 +3,14 @@ package generate
import (
"context"
"os"
+ "path/filepath"
"github.com/containers/common/pkg/config"
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/libpod/define"
"github.com/containers/libpod/libpod/image"
"github.com/containers/libpod/pkg/specgen"
+ "github.com/containers/libpod/pkg/util"
"github.com/containers/storage"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
@@ -128,7 +130,41 @@ func createContainerOptions(ctx context.Context, rt *libpod.Runtime, s *specgen.
if s.Stdin {
options = append(options, libpod.WithStdin())
}
- if len(s.Systemd) > 0 {
+
+ useSystemd := false
+ switch s.Systemd {
+ case "always":
+ useSystemd = true
+ case "false":
+ break
+ case "", "true":
+ command := s.Command
+ if len(command) == 0 {
+ command, err = img.Cmd(ctx)
+ if err != nil {
+ return nil, err
+ }
+ }
+
+ if len(command) > 0 {
+ if command[0] == "/usr/sbin/init" || command[0] == "/sbin/init" || (filepath.Base(command[0]) == "systemd") {
+ useSystemd = true
+ }
+ }
+ default:
+ return nil, errors.Wrapf(err, "invalid value %q systemd option requires 'true, false, always'", s.Systemd)
+ }
+ if useSystemd {
+ // is StopSignal was not set by the user then set it to systemd
+ // expected StopSigal
+ if s.StopSignal == nil {
+ stopSignal, err := util.ParseSignal("RTMIN+3")
+ if err != nil {
+ return nil, errors.Wrapf(err, "error parsing systemd signal")
+ }
+ s.StopSignal = &stopSignal
+ }
+
options = append(options, libpod.WithSystemd())
}
if len(s.Name) > 0 {