|
|
@ -936,7 +936,7 @@ nextcloud:src:version() { |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
container:health:check-fix() { |
|
|
|
container:health:check-fix:container-aliveness() { |
|
|
|
local container_id="$1" |
|
|
|
|
|
|
|
timeout 5s docker inspect "$container_id" >/dev/null 2>&1 |
|
|
@ -963,6 +963,32 @@ EOF |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
container:health:check-fix:no-matching-entries() { |
|
|
|
local container_id="$1" |
|
|
|
|
|
|
|
out=$(docker exec "$container_id" echo 2>&1) |
|
|
|
errlvl=$? |
|
|
|
[ "$errlvl" == 0 ] && return 0 |
|
|
|
service_name=$(docker ps --filter id="$container_id" --format '{{.Label "com.docker.compose.service"}}') |
|
|
|
container_name=($(docker ps --filter id="$container_id" --format '{{.Names}}')) |
|
|
|
if [ "$errlvl" == 126 ] && [[ "$out" == *"no matching entries in passwd file"* ]]; then |
|
|
|
echo "container ${DARKCYAN}${container_name[0]}${NORMAL} for ${DARKYELLOW}$service_name${NORMAL} has ${DARKRED}no-matching-entries${NORMAL} bug." >&2 |
|
|
|
Wrap -d "restarting container of ${DARKYELLOW}$service_name${NORMAL} twice" <<EOF |
|
|
|
docker restart "$container_id" |
|
|
|
sleep 2 |
|
|
|
docker restart "$container_id" |
|
|
|
EOF |
|
|
|
return $errlvl |
|
|
|
fi |
|
|
|
warn "Unknown issue with ${DARKYELLOW}$service_name${NORMAL}'s container:" |
|
|
|
echo " ${WHITE}cmd:${NORMAL} docker exec -ti $container_id echo" >&2 |
|
|
|
echo "$out" | prefix " ${DARKGRAY}|${NORMAL} " >&2 |
|
|
|
echo " ${DARKGRAY}..${NORMAL} leaving this as-is." |
|
|
|
return $errlvl |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[ "$SOURCED" ] && return 0 |
|
|
|
|
|
|
@ -1611,22 +1637,57 @@ cmdline.spec:nextcloud:cmd:upgrade:run() { |
|
|
|
|
|
|
|
|
|
|
|
cmdline.spec.gnu check-fix |
|
|
|
|
|
|
|
cmdline.spec::cmd:check-fix:run() { |
|
|
|
: |
|
|
|
} |
|
|
|
|
|
|
|
cmdline.spec.gnu upgrade |
|
|
|
cmdline.spec:check-fix:cmd:container-aliveness:run() { |
|
|
|
: :posarg: [SERVICES...] "Optional service to check" |
|
|
|
: :optval: --check,-c "Specify a check or a list of checks separated by commas" |
|
|
|
: :optfla: --silent,-s "Don't ouput anything if everything goes well" |
|
|
|
|
|
|
|
local project_name containers container |
|
|
|
local project_name service_name containers container check |
|
|
|
|
|
|
|
all_checks=$(declare -F | |
|
|
|
egrep '^declare -fx? container:health:check-fix:[^ ]+$' | |
|
|
|
cut -f 4 -d ":") |
|
|
|
checks=(${opt_check//,/ }) |
|
|
|
for check in "${checks[@]}"; do |
|
|
|
fn.exists container:health:check-fix:$check || { |
|
|
|
err "check '$check' not found." |
|
|
|
return 1 |
|
|
|
} |
|
|
|
done |
|
|
|
if [ "${#checks[*]}" == 0 ]; then |
|
|
|
checks=($all_checks) |
|
|
|
fi |
|
|
|
## XXXvlab: could make it parallel |
|
|
|
project_name=$(compose:project_name) || exit 1 |
|
|
|
containers=($(compose:project:containers "${project_name}")) || exit 1 |
|
|
|
## XXXvlab: could make it parallel |
|
|
|
|
|
|
|
found= |
|
|
|
for container in "${containers[@]}"; do |
|
|
|
container:health:check-fix "$container" |
|
|
|
service_name=$(docker ps --filter id="$container" --format '{{.Label "com.docker.compose.service"}}') |
|
|
|
if [ "${#SERVICES[@]}" -gt 0 ]; then |
|
|
|
[[ " ${SERVICES[*]} " == *" $service_name "* ]] || continue |
|
|
|
fi |
|
|
|
found=1 |
|
|
|
one_bad= |
|
|
|
for check in "${checks[@]}"; do |
|
|
|
if ! container:health:check-fix:"$check" "$container"; then |
|
|
|
one_bad=1 |
|
|
|
fi |
|
|
|
done |
|
|
|
if [ -z "$opt_silent" ] && [ -z "$one_bad" ]; then |
|
|
|
Elt "containers have been checked for ${DARKYELLOW}$service_name${NORMAL}" |
|
|
|
Feedback |
|
|
|
fi |
|
|
|
done |
|
|
|
if [ -z "$found" ]; then |
|
|
|
if [ "${#SERVICES[@]}" -gt 0 ]; then |
|
|
|
warn "No container for given services found in current project '$project_name'." |
|
|
|
else |
|
|
|
warn "No container found for current project '$project_name'." |
|
|
|
fi |
|
|
|
return 1 |
|
|
|
fi |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|