-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df3de76
commit df99cdf
Showing
3 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
package/harvester-os/files/etc/systemd/system/rke2-shutdown.service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
25
package/harvester-os/files/usr/sbin/rke2-kill-containers.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |