Skip to content

Commit 7ad2911

Browse files
Add nvidia-cdi-refresh service
Automatic regeneration of /var/run/cdi/nvidia.yaml New units: • nvidia-cdi-refresh.service – one-shot wrapper for nvidia-ctk cdi generate (adds sleep + required caps). • nvidia-cdi-refresh.path – fires on driver install/upgrade via modules.dep.bin changes. Packaging • RPM %post reloads systemd and enables the path unit on fresh installs. • DEB postinst does the same (configure, skip on upgrade). Result: CDI spec is always up to date Signed-off-by: Carlos Eduardo Arango Gutierrez <[email protected]>
1 parent 890db82 commit 7ad2911

10 files changed

+98
-1
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
[Unit]
16+
Description=Trigger CDI refresh on NVIDIA driver install / uninstall events
17+
18+
[Path]
19+
PathChanged=/lib/modules/%v/modules.dep
20+
PathChanged=/lib/modules/%v/modules.dep.bin
21+
22+
[Install]
23+
WantedBy=multi-user.target
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
[Unit]
16+
Description=Refresh NVIDIA CDI specification file
17+
ConditionPathExists=/usr/bin/nvidia-smi
18+
ConditionPathExists=/usr/bin/nvidia-ctk
19+
20+
[Service]
21+
Type=oneshot
22+
EnvironmentFile=-/etc/nvidia-container-runtime/cdi-refresh.env
23+
ExecCondition=/usr/bin/grep -qE '/nvidia.ko' /lib/modules/%v/modules.dep
24+
ExecStart=/usr/bin/nvidia-ctk cdi generate --output=/var/run/cdi/nvidia.yaml
25+
CapabilityBoundingSet=CAP_SYS_MODULE CAP_SYS_ADMIN CAP_MKNOD
26+
27+
[Install]
28+
WantedBy=multi-user.target

docker/Dockerfile.debian

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ RUN make PREFIX=${DIST_DIR} cmds
5555

5656
WORKDIR $DIST_DIR
5757
COPY packaging/debian ./debian
58+
COPY deployments/systemd/ .
5859

5960
ARG LIBNVIDIA_CONTAINER_TOOLS_VERSION
6061
ENV LIBNVIDIA_CONTAINER_TOOLS_VERSION ${LIBNVIDIA_CONTAINER_TOOLS_VERSION}

docker/Dockerfile.opensuse-leap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ RUN make PREFIX=${DIST_DIR} cmds
4646

4747
WORKDIR $DIST_DIR/..
4848
COPY packaging/rpm .
49+
COPY deployments/systemd/ .
4950

5051
ARG LIBNVIDIA_CONTAINER_TOOLS_VERSION
5152
ENV LIBNVIDIA_CONTAINER_TOOLS_VERSION ${LIBNVIDIA_CONTAINER_TOOLS_VERSION}

docker/Dockerfile.rpm-yum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ RUN make PREFIX=${DIST_DIR} cmds
7171

7272
WORKDIR $DIST_DIR/..
7373
COPY packaging/rpm .
74+
COPY deployments/systemd/ ${DIST_DIR}/
7475

7576
ARG LIBNVIDIA_CONTAINER_TOOLS_VERSION
7677
ENV LIBNVIDIA_CONTAINER_TOOLS_VERSION ${LIBNVIDIA_CONTAINER_TOOLS_VERSION}

docker/Dockerfile.ubuntu

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ RUN make PREFIX=${DIST_DIR} cmds
5353

5454
WORKDIR $DIST_DIR
5555
COPY packaging/debian ./debian
56+
COPY deployments/systemd/ .
5657

5758
ARG LIBNVIDIA_CONTAINER_TOOLS_VERSION
5859
ENV LIBNVIDIA_CONTAINER_TOOLS_VERSION ${LIBNVIDIA_CONTAINER_TOOLS_VERSION}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
nvidia-container-runtime /usr/bin
22
nvidia-ctk /usr/bin
33
nvidia-cdi-hook /usr/bin
4+
nvidia-cdi-refresh.service /etc/systemd/system/
5+
nvidia-cdi-refresh.path /etc/systemd/system/

packaging/debian/nvidia-container-toolkit-base.postinst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ set -e
55
case "$1" in
66
configure)
77
/usr/bin/nvidia-ctk --quiet config --config-file=/etc/nvidia-container-runtime/config.toml --in-place
8+
9+
if command -v systemctl >/dev/null 2>&1 \
10+
&& systemctl --quiet is-system-running 2>/dev/null; then
11+
12+
systemctl daemon-reload || true
13+
14+
if [ -z "$2" ]; then # $2 empty → first install
15+
systemctl enable --now nvidia-cdi-refresh.path || true
16+
fi
17+
fi
818
;;
919

1020
abort-upgrade|abort-remove|abort-deconfigure)

packaging/debian/rules

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,14 @@
55

66
%:
77
dh $@
8+
9+
override_dh_fixperms:
10+
dh_fixperms
11+
chmod 755 debian/$(shell dh_listpackages)/usr/bin/nvidia-container-runtime-hook || true
12+
chmod 755 debian/$(shell dh_listpackages)/usr/bin/nvidia-container-runtime || true
13+
chmod 755 debian/$(shell dh_listpackages)/usr/bin/nvidia-container-runtime.cdi || true
14+
chmod 755 debian/$(shell dh_listpackages)/usr/bin/nvidia-container-runtime.legacy || true
15+
chmod 755 debian/$(shell dh_listpackages)/usr/bin/nvidia-ctk || true
16+
chmod 755 debian/$(shell dh_listpackages)/usr/bin/nvidia-cdi-hook || true
17+
chmod 644 debian/$(shell dh_listpackages)/etc/systemd/system/nvidia-cdi-refresh.service || true
18+
chmod 644 debian/$(shell dh_listpackages)/etc/systemd/system/nvidia-cdi-refresh.path || true

packaging/rpm/SPECS/nvidia-container-toolkit.spec

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Source3: nvidia-container-runtime
1717
Source4: nvidia-container-runtime.cdi
1818
Source5: nvidia-container-runtime.legacy
1919
Source6: nvidia-cdi-hook
20+
Source7: nvidia-cdi-refresh.service
21+
Source8: nvidia-cdi-refresh.path
2022

2123
Obsoletes: nvidia-container-runtime <= 3.5.0-1, nvidia-container-runtime-hook <= 1.4.0-2
2224
Provides: nvidia-container-runtime
@@ -28,23 +30,38 @@ Requires: nvidia-container-toolkit-base == %{version}-%{release}
2830
Provides tools and utilities to enable GPU support in containers.
2931

3032
%prep
31-
cp %{SOURCE0} %{SOURCE1} %{SOURCE2} %{SOURCE3} %{SOURCE4} %{SOURCE5} %{SOURCE6} .
33+
cp %{SOURCE0} %{SOURCE1} %{SOURCE2} %{SOURCE3} %{SOURCE4} %{SOURCE5} %{SOURCE6} %{SOURCE7} %{SOURCE8} .
3234

3335
%install
3436
mkdir -p %{buildroot}%{_bindir}
37+
mkdir -p %{buildroot}%{_sysconfdir}/systemd/system/
38+
3539
install -m 755 -t %{buildroot}%{_bindir} nvidia-container-runtime-hook
3640
install -m 755 -t %{buildroot}%{_bindir} nvidia-container-runtime
3741
install -m 755 -t %{buildroot}%{_bindir} nvidia-container-runtime.cdi
3842
install -m 755 -t %{buildroot}%{_bindir} nvidia-container-runtime.legacy
3943
install -m 755 -t %{buildroot}%{_bindir} nvidia-ctk
4044
install -m 755 -t %{buildroot}%{_bindir} nvidia-cdi-hook
45+
install -m 644 -t %{buildroot}%{_sysconfdir}/systemd/system nvidia-cdi-refresh.service
46+
install -m 644 -t %{buildroot}%{_sysconfdir}/systemd/system nvidia-cdi-refresh.path
4147

4248
%post
4349
if [ $1 -gt 1 ]; then # only on package upgrade
4450
mkdir -p %{_localstatedir}/lib/rpm-state/nvidia-container-toolkit
4551
cp -af %{_bindir}/nvidia-container-runtime-hook %{_localstatedir}/lib/rpm-state/nvidia-container-toolkit
4652
fi
4753

54+
# Reload systemd unit cache
55+
if command -v systemctl >/dev/null 2>&1 \
56+
&& systemctl --quiet is-system-running 2>/dev/null; then
57+
systemctl daemon-reload || true
58+
59+
# On fresh install ($1 == 1) enable the path unit so it starts at boot
60+
if [ "$1" -eq 1 ]; then
61+
systemctl enable --now nvidia-cdi-refresh.path || true
62+
fi
63+
fi
64+
4865
%posttrans
4966
if [ ! -e %{_bindir}/nvidia-container-runtime-hook ]; then
5067
# repairing lost file nvidia-container-runtime-hook
@@ -89,6 +106,8 @@ Provides tools such as the NVIDIA Container Runtime and NVIDIA Container Toolkit
89106
%{_bindir}/nvidia-container-runtime
90107
%{_bindir}/nvidia-ctk
91108
%{_bindir}/nvidia-cdi-hook
109+
%{_sysconfdir}/systemd/system/nvidia-cdi-refresh.service
110+
%{_sysconfdir}/systemd/system/nvidia-cdi-refresh.path
92111

93112
# The OPERATOR EXTENSIONS package consists of components that are required to enable GPU support in Kubernetes.
94113
# This package is not distributed as part of the NVIDIA Container Toolkit RPMs.

0 commit comments

Comments
 (0)