Skip to content

Commit 8286896

Browse files
committed
RHELAI-429: Adding upgrade informer service
Upgrade informer will run every couple of our and will be triggered by systemd timer. In order to start it on boot and run once i enabled it and timer. Disabling auto upgrade service in order to remove unexpected reboots. Service will run "bootc upgrade --check" and in case new version exists it will create motd file with upgrade info. Removed unused grow-part services
1 parent 9fa8f28 commit 8286896

File tree

9 files changed

+78
-63
lines changed

9 files changed

+78
-63
lines changed

training/common/Makefile.common

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ CONTAINER_TOOL_EXTRA_ARGS ?=
1616
EXTRA_RPM_PACKAGES ?=
1717
GRAPH_ROOT=$(shell podman info --format '{{ .Store.GraphRoot }}')
1818
UMASK=$(shell umask)
19+
IMAGE_VERSION := $(or ${IMAGE_VERSION},$(shell git rev-parse --short HEAD))
1920

2021
AUTH_JSON ?=
2122

@@ -50,7 +51,7 @@ ENABLE_RT ?=
5051
SSH_PUBKEY ?= $(shell cat ${HOME}/.ssh/id_rsa.pub 2> /dev/null)
5152

5253
.PHONY: prepare-files
53-
prepare-files: $(OUTDIR)/$(WRAPPER) $(OUTDIR)/$(QLORA_WRAPPER) $(OUTDIR)/$(TRAIN_WRAPPER) $(OUTDIR)
54+
prepare-files: $(OUTDIR)/$(WRAPPER) $(OUTDIR)/$(QLORA_WRAPPER) $(OUTDIR)/$(TRAIN_WRAPPER) $(OUTDIR) common-services
5455

5556
$(OUTDIR):
5657
mkdir -p $(OUTDIR)
@@ -61,6 +62,11 @@ $(OUTDIR)/$(QLORA_WRAPPER): $(OUTDIR)
6162
$(OUTDIR)/$(TRAIN_WRAPPER): $(OUTDIR)
6263
cp -pf $(TRAIN_WRAPPER) $(OUTDIR)
6364

65+
.PHONY: common-services
66+
common-services:
67+
mkdir -p build; cp -pR ../common/usr build
68+
69+
6470
.PHONY: check-sshkey
6571
check-sshkey:
6672
@test -n "$(SSH_PUBKEY)" || \

training/common/usr/lib/systemd/system/bootc-generic-growpart.service

Lines changed: 0 additions & 20 deletions
This file was deleted.

training/common/usr/lib/systemd/system/local-fs.target.wants/bootc-generic-growpart.service

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[Unit]
2+
Description=Check for available bootc updates
3+
ConditionPathExists=/run/ostree-booted
4+
After=network-online.target
5+
StartLimitIntervalSec=400
6+
StartLimitBurst=3
7+
8+
[Service]
9+
Type=oneshot
10+
ExecStart=/usr/libexec/upgrade-informer
11+
Restart=on-failure
12+
RestartSec=90
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[Unit]
2+
Description=Runs upgrade informer periodically
3+
ConditionPathExists=/run/ostree-booted
4+
5+
[Timer]
6+
OnBootSec=1h
7+
# This time is relatively arbitrary and obviously expected to be overridden/changed
8+
OnUnitInactiveSec=8h
9+
# When deploying a large number of systems, it may be beneficial to increase this value to help with load on the registry.
10+
RandomizedDelaySec=2h
11+
12+
[Install]
13+
WantedBy=timers.target

training/common/usr/libexec/bootc-generic-growpart

Lines changed: 0 additions & 41 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
# Run the command and capture its output
4+
output=$(bootc upgrade --check | sed -e 1q)
5+
message_file="/etc/motd.d/upgrade-message"
6+
bootc_auth="/etc/ostree/auth.json"
7+
8+
if [[ $output == Update\ available* ]]; then
9+
if [[ ! -f $message_file ]]; then
10+
echo "New version was found"
11+
bootc_image=$(echo "$output" | awk '{print $4}')
12+
# If auth file exists we should use it
13+
auth_params=""
14+
if [[ -f $bootc_auth ]]; then
15+
auth_params="--authfile $bootc_auth"
16+
fi
17+
18+
# Get image version
19+
# shellcheck disable=SC2086
20+
image_version=$(skopeo inspect --format json $auth_params "$bootc_image" | jq '.Labels | .["image_version"] // empty' | tr -d '"')
21+
22+
# If upgrade available, write the output to the file
23+
echo -e "\n\n ** Attention! ** \n** A new $image_version version is available **\n\
24+
** In order to apply it run: bootc upgrade --apply \n\
25+
** Please note that the system will reboot after the upgrade ** \n\n" > $message_file
26+
fi
27+
else
28+
echo "No upgrade was found"
29+
rm $message_file 2> /dev/null
30+
fi
31+
32+
echo "Finished running upgrade informer"

training/nvidia-bootc/Containerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ COPY --from=builder /home/builder/yum-packaging-precompiled-kmod/RPMS/*/*.rpm /r
9898
COPY --from=builder --chmod=444 /home/builder/yum-packaging-precompiled-kmod/tmp/firmware/*.bin /lib/firmware/nvidia/${DRIVER_VERSION}/
9999
# Temporary workaround until the permanent fix for libdnf is merged
100100
COPY nvidia-toolkit-firstboot.service /usr/lib/systemd/system/nvidia-toolkit-firstboot.service
101+
# Enable common services
102+
COPY build/usr /usr
103+
104+
ARG IMAGE_VERSION
101105

102106
# TODO: rework this monstrosity into a build.sh (or even not shell script)
103107
# The need for the `cp /etc/dnf/dnf.conf` is a workaround for https://github.com/containers/bootc/issues/637
@@ -146,6 +150,14 @@ RUN mv /etc/selinux /etc/selinux.tmp \
146150
&& ln -s ../cloud-init.target /usr/lib/systemd/system/default.target.wants \
147151
&& mv /etc/selinux.tmp /etc/selinux \
148152
&& ln -s /usr/lib/systemd/system/nvidia-toolkit-firstboot.service /usr/lib/systemd/system/basic.target.wants/nvidia-toolkit-firstboot.service \
153+
# enable upgrade informer timer
154+
&& ln -s /usr/lib/systemd/system/upgrade-informer.timer /usr/lib/systemd/system/timers.target.wants/upgrade-informer.timer \
155+
# enable upgrade informer service, added as we need it to start on boot
156+
&& ln -s /usr/lib/systemd/system/upgrade-informer.service /usr/lib/systemd/system/basic.target.wants/upgrade-informer.service \
157+
# remove auto upgrade service
158+
&& rm -f /usr/lib/systemd/system/default.target.wants/bootc-fetch-apply-updates.timer \
159+
# save version into file
160+
&& echo ${IMAGE_VERSION} > /usr/lib/ai-release \
149161
&& echo "blacklist nouveau" > /etc/modprobe.d/blacklist_nouveau.conf
150162

151163
ARG SSHPUBKEY

training/nvidia-bootc/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ bootc: driver-toolkit check-sshkey prepare-files
1616
$(DRIVER_TOOLKIT_IMAGE:%=--build-arg DRIVER_TOOLKIT_IMAGE=%) \
1717
$(DRIVER_VERSION:%=--build-arg DRIVER_VERSION=%) \
1818
$(DRIVER_VERSION:%=--label driver-version=%) \
19+
$(IMAGE_VERSION:%=--label image_version=%) \
20+
$(IMAGE_VERSION:%=--build-arg IMAGE_VERSION=%) \
1921
$(EXTRA_RPM_PACKAGES:%=--build-arg EXTRA_RPM_PACKAGES=%) \
2022
$(FROM:%=--build-arg BASEIMAGE=%) \
2123
$(INSTRUCTLAB_IMAGE:%=--build-arg INSTRUCTLAB_IMAGE=%) \

0 commit comments

Comments
 (0)