fix(services-restart): an LXC container's processes are left out, 4.46.0 (NetOrk/netork#2750) #134
No files matched your search
@@ -7,6 +7,16 @@ recorded here; their history is the git log.
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [4.46.0] - 2026-11-26
|
||||
|
||||
### Fixed
|
||||
- `get_services_need_restart()` leaves an LXC container's processes out of the `/proc` scan,
|
||||
as it does Docker's and Podman's (NetOrk/netork#2750). On a Proxmox VE node a container
|
||||
updates itself, and its own systemd's units (`/lxc/<vmid>/ns/system.slice/nginx.service`)
|
||||
read as host services that need a restart. Left out: `/lxc/<name>/` (Proxmox VE, cgroup v1)
|
||||
and `/lxc.payload.<name>/` (LXC 4 and later); `/lxc.monitor/<name>` still counts, since
|
||||
`lxc-start` runs the host's binary.
|
||||
|
||||
## [4.45.0] - 2026-11-26
|
||||
|
||||
### Added
|
||||
|
||||
@@ -214,7 +214,8 @@ finished until they restart. One fixed, read-only command, as root: `needs-resta
|
||||
where dnf-utils has it, else `needrestart -b -r l` (list only, whatever `needrestart.conf`
|
||||
says), else the processes whose `/proc/<pid>/maps` maps deleted code
|
||||
(`DELETED_CODE_PATTERN`), each named by the service its cgroup gives, as for the listening
|
||||
sockets. A driver supplies `_run_services_restart_command(command)`; the command arrives as
|
||||
sockets. A container's processes are left out, an LXC container's as well (a Proxmox node's
|
||||
containers update themselves). A driver supplies `_run_services_restart_command(command)`; the command arrives as
|
||||
one `sh -c` argument and reads no stdin. Without root there is no reading: one that saw only
|
||||
the login user's processes would read as clean.
|
||||
|
||||
|
||||
@@ -21,10 +21,11 @@ here once, and a driver only carries the command across.
|
||||
|
||||
**Units from cgroups.** For the ``/proc`` scan, ``/proc/<pid>/cgroup`` names the
|
||||
systemd service a process runs in, as for the listening sockets: a process of a
|
||||
user's own systemd is that user's manager (``user@1000``), one of a container is
|
||||
left out (the container runs its image's libraries, which no host update
|
||||
replaces), and one in no service -- a login session, systemd itself -- is listed
|
||||
as a process. The host's tools name services only, so ``processes`` stays empty
|
||||
user's own systemd is that user's manager (``user@1000``), one of a container --
|
||||
Docker, Podman, or LXC as on a Proxmox node -- is left out (the container runs its
|
||||
own libraries, which no host update replaces, and its own systemd's units are none
|
||||
of the host's services), and one in no service -- a login session, systemd itself --
|
||||
is listed as a process. The host's tools name services only, so ``processes`` stays empty
|
||||
for them.
|
||||
|
||||
**Root, or nothing.** Only root sees every process's memory. The script goes to
|
||||
@@ -105,6 +106,10 @@ _SERVICE_LINE = re.compile(r"^([\w:.@\\-]+)\.service$")
|
||||
_NEEDRESTART_SVC = re.compile(r"^NEEDRESTART-SVC:\s*(.+?)\s*$")
|
||||
#: A process of a user's own systemd: that user's manager is what restarts it.
|
||||
_USER_MANAGER = re.compile(r"/(user@\d+)\.service(?=/|$)")
|
||||
#: A process inside an LXC container: ``/lxc/<name>/`` (Proxmox VE, which nests the
|
||||
#: container's own cgroups under ``ns``; cgroup v1) or ``/lxc.payload.<name>/`` (LXC 4
|
||||
#: and later). Not ``/lxc.monitor/<name>``: ``lxc-start`` runs the host's binary.
|
||||
_LXC = re.compile(r"^/lxc(?:/|\.payload\.)[^/]+(?:/|$)")
|
||||
_SERVICE_SUFFIX = ".service"
|
||||
|
||||
|
||||
@@ -151,7 +156,7 @@ def _maps(sections: dict[str, list[str]]) -> tuple[list[str], list[RestartProces
|
||||
if not pid.isdigit():
|
||||
continue
|
||||
path = paths.get(int(pid))
|
||||
if _container(path):
|
||||
if _container(path) or _LXC.match(path or ""):
|
||||
continue
|
||||
unit = _process_unit(path)
|
||||
if unit:
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "napalm-device-types"
|
||||
version = "4.45.0"
|
||||
version = "4.46.0"
|
||||
description = "Abstract device-type base classes for NAPALM drivers"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.12"
|
||||
|
||||
@@ -115,6 +115,35 @@ class TestTheMapsScan:
|
||||
|
||||
assert reading == {"source": "maps", "units": [], "processes": []}
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"cgroup",
|
||||
[
|
||||
# Proxmox VE: the container's own systemd, under lxc/<vmid>/ns.
|
||||
"0::/lxc/101/ns/system.slice/nginx.service",
|
||||
"0::/lxc/101/ns/init.scope",
|
||||
# LXC 4 and later by default.
|
||||
"0::/lxc.payload.web/system.slice/nginx.service",
|
||||
# cgroup v1, systemd's hierarchy.
|
||||
"12:name=systemd:/lxc/web/system.slice/nginx.service",
|
||||
],
|
||||
)
|
||||
def test_an_lxc_container_is_left_out(self, cgroup):
|
||||
"""A Proxmox node's containers update themselves: the host sees their processes'
|
||||
mappings, and their own systemd's units, which are no services of the host's."""
|
||||
cgroups = f"2100 {cgroup}\n"
|
||||
|
||||
reading = parse_services_restart(_wire(("maps", "2100 nginx\n"), ("cgroups", cgroups)))
|
||||
|
||||
assert reading == {"source": "maps", "units": [], "processes": []}
|
||||
|
||||
def test_an_lxc_monitor_is_the_hosts(self):
|
||||
"""``lxc-start`` runs the host's own binary, outside the container."""
|
||||
reading = parse_services_restart(
|
||||
_wire(("maps", "2090 lxc-start\n"), ("cgroups", "2090 0::/lxc.monitor/101\n"))
|
||||
)
|
||||
|
||||
assert reading["processes"] == [{"pid": 2090, "name": "lxc-start"}]
|
||||
|
||||
def test_a_process_gone_before_its_cgroup_was_read_has_no_unit(self):
|
||||
reading = parse_services_restart(_wire(("maps", "4242 cron\n"), ("cgroups", "")))
|
||||
|
||||
|
||||
Reference in new issue
Block a user