Browse Source

new: [check-fix] new action to launch all fixes

A new fix was also added to find and fix `no-matching-entries` issue.
By default, all containers are checked against all checks.
rc1
Valentin Lab 1 year ago
parent
commit
8c78dc71ed
  1. 29
      README.org
  2. 79
      bin/vps

29
README.org

@ -311,6 +311,35 @@ compose --debug logs odoo
docker-ip
#+END_SRC
*** Vérification de santé générale
La commande =vps check-fix= contrôler les containers en cours de
fonctionnement pour vérifier s'ils ne sont pas touché par quelques
problème identifiés et connus. Et elle va réparer ce qu'elle peut.
#+begin_src sh
vps check-fix
#+end_src
Il est possible de lancer ces vérifications sur une liste de service
spécifique ou de sélectionner le test voulu. Voir =vps check-fix
--help= pour plus d'info.
Il peut être opportun d'ajouter dans sur l'hôte, par exemple, une
vérification périodique et automatique:
#+begin_src sh
cat <<EOF > /etc/cron.d/vps-check
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
*/15 * * * * root vps check-fix -s -c container-aliveness 2>&1 | logger -t check-fix
*/5 * * * * root vps check-fix -s rocketchat 2>&1 | logger -t check-fix
EOF
#+end_src
** Par services
*** odoo

79
bin/vps

@ -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
}

Loading…
Cancel
Save