mirror of
https://github.com/containers/podman.git
synced 2025-06-23 02:18:13 +08:00
@ -424,7 +424,7 @@ func GetCreateFlags(cf *ContainerCLIOpts) *pflag.FlagSet {
|
||||
"Sysctl options",
|
||||
)
|
||||
createFlags.StringVar(
|
||||
&cf.SystemdD,
|
||||
&cf.Systemd,
|
||||
"systemd", "true",
|
||||
`Run container in systemd mode ("true"|"false"|"always")`,
|
||||
)
|
||||
|
@ -85,7 +85,7 @@ type ContainerCLIOpts struct {
|
||||
SubUIDName string
|
||||
SubGIDName string
|
||||
Sysctl []string
|
||||
SystemdD string
|
||||
Systemd string
|
||||
TmpFS []string
|
||||
TTY bool
|
||||
UIDMap []string
|
||||
|
@ -3,7 +3,6 @@ package common
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@ -285,16 +284,13 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string
|
||||
s.NetNS = c.Net.Network
|
||||
}
|
||||
|
||||
// STOP SIGNAL
|
||||
signalString := "TERM"
|
||||
if sig := c.StopSignal; len(sig) > 0 {
|
||||
signalString = sig
|
||||
stopSignal, err := util.ParseSignal(sig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.StopSignal = &stopSignal
|
||||
}
|
||||
stopSignal, err := util.ParseSignal(signalString)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
s.StopSignal = &stopSignal
|
||||
|
||||
// ENVIRONMENT VARIABLES
|
||||
//
|
||||
@ -439,25 +435,7 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string
|
||||
s.ImageVolumeMode = "anonymous"
|
||||
}
|
||||
|
||||
systemd := c.SystemdD == "always"
|
||||
if !systemd && command != nil {
|
||||
x, err := strconv.ParseBool(c.SystemdD)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "cannot parse bool %s", c.SystemdD)
|
||||
}
|
||||
if x && (command[0] == "/usr/sbin/init" || command[0] == "/sbin/init" || (filepath.Base(command[0]) == "systemd")) {
|
||||
systemd = true
|
||||
}
|
||||
}
|
||||
if systemd {
|
||||
if s.StopSignal == nil {
|
||||
stopSignal, err = util.ParseSignal("RTMIN+3")
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "error parsing systemd signal")
|
||||
}
|
||||
s.StopSignal = &stopSignal
|
||||
}
|
||||
}
|
||||
s.Systemd = c.Systemd
|
||||
if s.ResourceLimits == nil {
|
||||
s.ResourceLimits = &specs.LinuxResources{}
|
||||
}
|
||||
|
@ -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, ", "))
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -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 {
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/containers/libpod/pkg/cgroups"
|
||||
. "github.com/containers/libpod/test/utils"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
@ -82,13 +81,6 @@ WantedBy=multi-user.target
|
||||
})
|
||||
|
||||
It("podman run container with systemd PID1", func() {
|
||||
cgroupsv2, err := cgroups.IsCgroup2UnifiedMode()
|
||||
Expect(err).To(BeNil())
|
||||
if cgroupsv2 {
|
||||
// TODO: Find a way to enable this for v2
|
||||
Skip("systemd test does not work in cgroups V2 mode yet")
|
||||
}
|
||||
|
||||
systemdImage := "fedora"
|
||||
pull := podmanTest.Podman([]string{"pull", systemdImage})
|
||||
pull.WaitWithDefaultTimeout()
|
||||
|
Reference in New Issue
Block a user