Skip to content

Commit

Permalink
fixed umount error during shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisho authored and Vicente-Cheng committed May 23, 2023
1 parent df3de76 commit df99cdf
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=Kill RKE2 Containers for clean unmount
DefaultDependencies=no
RefuseManualStart=yes
Before=reboot.target halt.target shutdown.target poweroff.target umount.target final.target

[Install]
RequiredBy=reboot.target halt.target shutdown.target poweroff.target umount.target final.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/sbin/rke2-kill-containers.sh
7 changes: 7 additions & 0 deletions package/harvester-os/files/system/oem/91_rke2-shutdown.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: "Enable RKE2 shutdown service"
stages:
initramfs:
- name: "enable rke2-shutdown.service"
if: 'grep -q root=LABEL=COS_ACTIVE /proc/cmdline && [ -n "$(blkid -L COS_ACTIVE)" ]'
commands:
- systemctl enable rke2-shutdown.service
25 changes: 25 additions & 0 deletions package/harvester-os/files/usr/sbin/rke2-kill-containers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash -x
function list_units() {
systemctl list-units --type=scope --no-legend | grep -Eo "(cri-containerd-.+\.scope)"
}

function get_unit_status() {
local unit_name="$1"
systemctl status "${unit_name}"
}

systemctl stop rke2-server.service || true
systemctl stop rke2-agent.service || true

unit_list=($(list_units))

max_concurrency=$(($(nproc) + 1))
if [ ${#unit_list[@]} -lt $max_concurrency ]; then
max_concurrency=${#unit_list[@]}
fi

printf '%s\0' "${unit_list[@]}" | xargs -0 -n1 -P "$max_concurrency" sh -c 'sudo systemctl stop --kill-who=all "$@" && echo "Finished $@"' _ | { grep -v '^Finished' || true; } | { grep -v 'xargs:' || true; } &
wait

echo "Finished stopping all units."
exit 0

0 comments on commit df99cdf

Please sign in to comment.