#!/bin/sh [ $(id -u) -eq 0 ] || exec sudo $0 $@ for bin in {{ k3s_runtime_config['data-dir'] | default('/var/lib/rancher/k3s') }}/data/**/bin/; do [ -d "$bin" ] && export PATH=$bin:$PATH done set -x for service in /etc/systemd/system/k3s*.service; do [ -s "$service" ] && systemctl stop "$(basename $service)" done for service in /etc/init.d/k3s*; do [ -x "$service" ] && "$service" stop done pschildren() { ps -e -o ppid= -o pid= | \ sed -e 's/^\s*//g; s/\s\s*/\t/g;' | \ grep -w "^$1" | \ cut -f2 } pstree() { for pid in $@; do echo $pid for child in $(pschildren $pid); do pstree $child done done } killtree() { kill -9 $( { set +x; } 2>/dev/null; pstree $@; set -x; ) 2>/dev/null } getshims() { lsof | sed -e 's/^[^0-9]*//g; s/ */\t/g' | grep -w 'k3s/data/[^/]*/bin/containerd-shim' | cut -f1 | sort -n -u } killtree $({ set +x; } 2>/dev/null; getshims; set -x) do_unmount() { { set +x; } 2>/dev/null MOUNTS= while read ignore mount ignore; do MOUNTS="$mount\n$MOUNTS" done /dev/null | grep 'master cni0' | while read ignore iface ignore; do iface=${iface%%@*} [ -z "$iface" ] || ip link delete $iface done ip link delete cni0 ip link delete flannel.1 [ -d /var/lib/cni ] && rm -rf /var/lib/cni/ iptables-save | grep -v KUBE- | grep -v CNI- | iptables-restore