From af951dd74d6ffc23d219c63f69db293b606aa3ee Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Fri, 16 Sep 2022 10:53:33 +0200 Subject: [PATCH] new: [vps] add ``check-fix container-aliveness`` action Signed-off-by: Valentin Lab --- bin/vps | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/bin/vps b/bin/vps index 4fa3d1a..242734d 100755 --- a/bin/vps +++ b/bin/vps @@ -593,6 +593,16 @@ compose:service:container_first() { export -f compose:service:container_first +compose:project:containers() { + local project="$1" opts + + opts+=(--filter label="com.docker.compose.project=$project") + docker ps "${opts[@]}" \ + --format="{{.ID}}" +} +export -f compose:project:containers + + compose:charm:containers() { local project="$1" charm="$2" @@ -926,6 +936,30 @@ nextcloud:src:version() { } +container:health:check-fix() { + local container_id="$1" + + timeout 5s docker inspect "$container_id" >/dev/null 2>&1 + errlvl=$? + if [ "$errlvl" == 124 ]; then + service_name=$(docker ps --filter id="$container_id" --format '{{.Label "com.docker.compose.service"}}') + container_name=($(docker ps --filter id="$container_id" --format '{{.Names}}')) + pid=$(ps ax -o pid,command -ww | grep docker-containerd-shim | grep "/$container_id" | + cut -f 1 -d " ") + if [ -z "$pid" ]; then + err "container ${DARKCYAN}${container_name[0]}${NORMAL} for ${DARKYELLOW}$service_name${NORMAL} doesn't answer to 'inspect' command. Can't find its PID neither." + return 1 + fi + echo "container ${DARKCYAN}${container_name[0]}${NORMAL} for ${DARKYELLOW}$service_name${NORMAL} doesn't answer to 'inspect' command (pid: $pid)." + Wrap -d "kill pid $pid and restart" <