Skip to content

Commit

Permalink
RHELAI-429: Adding upgrade informer service
Browse files Browse the repository at this point in the history
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

Signed-off-by: Igal Tsoiref <[email protected]>
  • Loading branch information
tsorya committed Jul 18, 2024
1 parent 73ada6b commit 425e861
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 64 deletions.
7 changes: 6 additions & 1 deletion training/common/Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ ENABLE_RT ?=
SSH_PUBKEY ?= $(shell cat ${HOME}/.ssh/id_rsa.pub 2> /dev/null)

.PHONY: prepare-files
prepare-files: $(OUTDIR)/$(WRAPPER) $(OUTDIR)/$(QLORA_WRAPPER) $(OUTDIR)/$(TRAIN_WRAPPER) $(OUTDIR)
prepare-files: $(OUTDIR)/$(WRAPPER) $(OUTDIR)/$(QLORA_WRAPPER) $(OUTDIR)/$(TRAIN_WRAPPER) $(OUTDIR) common-services

$(OUTDIR):
mkdir -p $(OUTDIR)
Expand All @@ -63,6 +63,11 @@ $(OUTDIR)/$(QLORA_WRAPPER): $(OUTDIR)
$(OUTDIR)/$(TRAIN_WRAPPER): $(OUTDIR)
cp -pf $(TRAIN_WRAPPER) $(OUTDIR)

.PHONY: common-services
common-services:
mkdir -p build; cp -pR ../common/usr build


.PHONY: check-sshkey
check-sshkey:
@test -n "$(SSH_PUBKEY)" || \
Expand Down

This file was deleted.

This file was deleted.

12 changes: 12 additions & 0 deletions training/common/usr/lib/systemd/system/upgrade-informer.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Check for available operating system updates
ConditionPathExists=/run/ostree-booted
After=network-online.target
StartLimitIntervalSec=400
StartLimitBurst=3

[Service]
Type=oneshot
ExecStart=/usr/libexec/upgrade-informer
Restart=on-failure
RestartSec=90
11 changes: 11 additions & 0 deletions training/common/usr/lib/systemd/system/upgrade-informer.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=Runs upgrade informer periodically
ConditionPathExists=/run/ostree-booted

[Timer]
OnBootSec=1h
OnUnitInactiveSec=8h
RandomizedDelaySec=2h

[Install]
WantedBy=timers.target
41 changes: 0 additions & 41 deletions training/common/usr/libexec/bootc-generic-growpart

This file was deleted.

32 changes: 32 additions & 0 deletions training/common/usr/libexec/upgrade-informer
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash

# Run the command and capture its output
output=$(bootc upgrade --check | sed -e 1q)
message_file="/etc/motd.d/upgrade-message"
bootc_auth="/etc/ostree/auth.json"

if [[ $output == Update\ available* ]]; then
if [[ ! -f $message_file ]]; then
echo "New version was found"
bootc_image=$(echo "$output" | awk '{print $4}')
# If auth file exists we should use it
auth_params=""
if [[ -f $bootc_auth ]]; then
auth_params="--authfile $bootc_auth"
fi

# Get image version
# shellcheck disable=SC2086
image_version_id=$(skopeo inspect --format json $auth_params "$bootc_image" | jq '.Labels | .["image_version_id"] // empty' | tr -d '"')

# If upgrade available, write the output to the file
echo -e "\n\n ** Attention! ** \n** A new $image_version_id version is available **\n\
** In order to apply it run: bootc upgrade --apply \n\
** Please note that the system will reboot after the upgrade ** \n\n" > $message_file
fi
else
echo "No upgrade was found"
rm $message_file 2> /dev/null
fi

echo "Finished running upgrade informer"
13 changes: 12 additions & 1 deletion training/nvidia-bootc/Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ COPY --from=builder /home/builder/yum-packaging-precompiled-kmod/RPMS/*/*.rpm /r
COPY --from=builder --chmod=444 /home/builder/yum-packaging-precompiled-kmod/tmp/firmware/*.bin /lib/firmware/nvidia/${DRIVER_VERSION}/
# Temporary workaround until the permanent fix for libdnf is merged
COPY nvidia-toolkit-firstboot.service /usr/lib/systemd/system/nvidia-toolkit-firstboot.service
# Enable common services
COPY build/usr /usr

ARG IMAGE_VERSION_ID

Expand Down Expand Up @@ -148,12 +150,20 @@ RUN mv /etc/selinux /etc/selinux.tmp \
dnf module enable -y nvidia-driver:${DRIVER_BRANCH} && \
dnf install -y nvidia-fabric-manager-${DRIVER_VERSION} libnvidia-nscq-${DRIVER_BRANCH}-${DRIVER_VERSION} ; \
fi \
# Install rhc connect for insights telemetry gathering
&& . /etc/os-release && if [ "${ID}" == "rhel" ]; then \
# Install rhc connect for insights telemetry gathering
dnf install -y rhc rhc-worker-playbook; \
# Adding rhel ai identity to os-release file for insights usage
sed -i -e "/^VARIANT=/ {s/^VARIANT=.*/VARIANT=\"RHEL AI\"/; t}" -e "\$aVARIANT=\"RHEL AI\"" /usr/lib/os-release; \
sed -i -e "/^VARIANT_ID=/ {s/^VARIANT_ID=.*/VARIANT_ID=rhel_ai/; t}" -e "\$aVARIANT_ID=rhel_ai" /usr/lib/os-release; \
sed -i -e "/^RHEL_AI_VERSION_ID=/ {s/^RHEL_AI_VERSION_ID=.*/RHEL_AI_VERSION_ID='${IMAGE_VERSION_ID}'/; t}" -e "\$aRHEL_AI_VERSION_ID='${IMAGE_VERSION_ID}'" /usr/lib/os-release; \

# enable upgrade informer timer
ln -s /usr/lib/systemd/system/upgrade-informer.timer /usr/lib/systemd/system/timers.target.wants/upgrade-informer.timer; \
# enable upgrade informer service, added as we need it to start on boot
ln -s /usr/lib/systemd/system/upgrade-informer.service /usr/lib/systemd/system/basic.target.wants/upgrade-informer.service; \
# disable auto upgrade service
rm -f /usr/lib/systemd/system/default.target.wants/bootc-fetch-apply-updates.timer; \
fi \
&& dnf clean all \
&& ln -s ../cloud-init.target /usr/lib/systemd/system/default.target.wants \
Expand All @@ -164,6 +174,7 @@ RUN mv /etc/selinux /etc/selinux.tmp \
&& ln -s /usr/lib/systemd/system/nvidia-fabricmanager.service /etc/systemd/system/multi-user.target.wants/nvidia-fabricmanager.service \
&& ln -s /usr/lib/systemd/system/nvidia-persistenced.service /etc/systemd/system/multi-user.target.wants/nvidia-persistenced.service


ARG SSHPUBKEY

# The --build-arg "SSHPUBKEY=$(cat ~/.ssh/id_rsa.pub)" option inserts your
Expand Down

0 comments on commit 425e861

Please sign in to comment.