Created
June 25, 2023 00:40
-
-
Save cjvirtucio87/6f97b2992c3d4f86618faebd911942e6 to your computer and use it in GitHub Desktop.
bash script for calling crictl on the containerd unix socket; useful when running k3s in rootless mode
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
#!/usr/bin/env bash | |
function main { | |
set -eo pipefail | |
local main_pid | |
main_pid="$(systemctl show --property MainPID --user k3s-rootless | cut -d '=' -f2 | tr -d '\n')" | |
local exe_pid | |
for f in /proc/*/status; do | |
local parent_pid | |
parent_pid="$(grep PPid "${f}" | awk '{print $2}' | tr -d '\n')" | |
if [[ "${main_pid}" -ne "${parent_pid}" ]]; then | |
continue | |
fi | |
local child_process_name | |
child_process_name="$(grep Name: "${f}" | awk '{print $2}' | tr -d '\n')" | |
if ! [[ "${child_process_name}" =~ exe ]]; then | |
continue | |
fi | |
exe_pid="$(grep -E '^Pid:' "${f}" | awk '{print $2}' | tr -d '\n')" | |
break | |
done | |
k3s crictl --runtime-endpoint "unix:///proc/${exe_pid}/root/run/k3s/containerd/containerd.sock" "$@" | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
just to credit the source of inspiration: k3s-io/k3s#5786 (comment)