mirror of
https://github.com/podman-container-tools/podman.git
synced 2026-08-05 00:15:44 +00:00
libpod: forward NOTIFY_SOCKET for sd-notify container mode
Backportsbe5d1261b4* mountNotifySocket consulted c.notifySocket, which was never populated. Use persisted c.config.SdNotifySocket instead so the path matches conmon's --sdnotify-socket and survives container restarts. * Add WithSdNotifySocket and have MakeContainer read NOTIFY_SOCKET from the environment when sdnotify mode is container. * Related to upstreambe5d1261b4(libpod: Move mountNotifySocket to container_internal_common.go), which introduced the shared mountNotifySocket path this wiring completes. Created/Modified with the assistance of AI: Cursor <Auto> Signed-off-by: Chris Evich <cevich@redhat.com>
This commit is contained in:
parent
0fdacefba6
commit
45aff3bd29
4 changed files with 22 additions and 8 deletions
|
|
@ -128,10 +128,6 @@ type Container struct {
|
|||
// This is true if a container is restored from a checkpoint.
|
||||
restoreFromCheckpoint bool
|
||||
|
||||
// Used to query the NOTIFY_SOCKET once along with setting up
|
||||
// mounts etc.
|
||||
notifySocket string
|
||||
|
||||
slirp4netnsSubnet *net.IPNet
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -751,11 +751,10 @@ func lookupHostUser(name string) (*runcuser.ExecUser, error) {
|
|||
return &execUser, nil
|
||||
}
|
||||
|
||||
// mountNotifySocket mounts the NOTIFY_SOCKET into the container if it's set
|
||||
// and if the sdnotify mode is set to container. It also sets c.notifySocket
|
||||
// to avoid redundantly looking up the env variable.
|
||||
// mountNotifySocket mounts the NOTIFY_SOCKET into the container if the host
|
||||
// notify socket path is stored in config and sdnotify mode is container.
|
||||
func (c *Container) mountNotifySocket(g generate.Generator) error {
|
||||
if c.notifySocket == "" {
|
||||
if c.config.SdNotifySocket == "" {
|
||||
return nil
|
||||
}
|
||||
if c.config.SdNotifyMode != define.SdNotifyModeContainer {
|
||||
|
|
|
|||
|
|
@ -626,6 +626,19 @@ func WithSdNotifyMode(mode string) CtrCreateOption {
|
|||
}
|
||||
}
|
||||
|
||||
// WithSdNotifySocket sets the host path to the systemd notify socket (e.g. from
|
||||
// NOTIFY_SOCKET) when using sd-notify container mode.
|
||||
func WithSdNotifySocket(socket string) CtrCreateOption {
|
||||
return func(ctr *Container) error {
|
||||
if ctr.valid {
|
||||
return define.ErrCtrFinalized
|
||||
}
|
||||
|
||||
ctr.config.SdNotifySocket = socket
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// WithShmSize sets the size of /dev/shm tmpfs mount.
|
||||
func WithShmSize(size int64) CtrCreateOption {
|
||||
return func(ctr *Container) error {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
|
|
@ -361,6 +362,11 @@ func createContainerOptions(rt *libpod.Runtime, s *specgen.SpecGenerator, pod *l
|
|||
if len(s.SdNotifyMode) > 0 {
|
||||
options = append(options, libpod.WithSdNotifyMode(s.SdNotifyMode))
|
||||
}
|
||||
if notifySocket, ok := os.LookupEnv("NOTIFY_SOCKET"); ok && notifySocket != "" {
|
||||
if strings.EqualFold(s.SdNotifyMode, define.SdNotifyModeContainer) {
|
||||
options = append(options, libpod.WithSdNotifySocket(notifySocket))
|
||||
}
|
||||
}
|
||||
if pod != nil {
|
||||
logrus.Debugf("adding container to pod %s", pod.Name())
|
||||
options = append(options, rt.WithPod(pod))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue