Browse Source

new: [vps] add ``check-fix container-aliveness`` action

Signed-off-by: Valentin Lab <valentin.lab@kalysto.org>
rc1
Valentin Lab 2 years ago
parent
commit
af951dd74d
  1. 58
      bin/vps

58
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" <<EOF
kill "$pid"
sleep 2
docker restart "$container_id"
EOF
fi
return $errlvl
}
[ "$SOURCED" ] && return 0
@ -1571,4 +1605,28 @@ cmdline.spec:nextcloud:cmd:upgrade:run() {
exit "$errlvl"
}
cmdline.spec.gnu check-fix
cmdline.spec::cmd:check-fix:run() {
:
}
cmdline.spec.gnu upgrade
cmdline.spec:check-fix:cmd:container-aliveness:run() {
local project_name containers container
project_name=$(compose:project_name) || exit 1
containers=($(compose:project:containers "${project_name}")) || exit 1
## XXXvlab: could make it parallel
for container in "${containers[@]}"; do
container:health:check-fix "$container"
done
}
cmdline::parse "$@"
Loading…
Cancel
Save