Add test condition when there are no errors

Also log unjoinable instances
This commit is contained in:
Benoit S 2022-04-21 22:15:32 +09:00
parent 90f231e59f
commit d5c632e74f

View file

@ -40,52 +40,68 @@ accounts_cull() {
# Remove instances that have an expired certificate from more than
# TLS_EXPIRED_MAX_SEC
grep 'certificate has expired' "$CULL_LOG" \
| awk '{print $NF}' \
| cut -d'/' -f3 \
| sort -u \
> "$TLS_EXPIRED_LOG"
if grep -q 'certificate has expired' "$CULL_LOG"; then
grep 'certificate has expired' "$CULL_LOG" \
| awk '{print $NF}' \
| cut -d'/' -f3 \
| sort -u \
> "$TLS_EXPIRED_LOG"
while read -r instance; do
TLS_EXPIRED_TS=$(
date -d "$(
echo Q \
| openssl s_client \
-servername "$instance" \
-connect "${instance}":443 \
2>/dev/null \
| openssl x509 -noout -dates \
| grep 'notAfter' \
| cut -d'=' -f2
)" +%s
)
DATE_DIFF=$(($(date +%s) - TLS_EXPIRED_TS))
if [[ $DATE_DIFF -gt $TLS_EXPIRED_MAX_SEC ]]; then
echo "${instance} has a certificate expired for more than TLS_EXPIRED_MAX_SEC, purging..."
$DRY_RUN \
&& $TOOTCTL domains purge \
--concurrency "$DB_POOL" \
--dry-run \
"$instance"
$DRY_RUN \
|| $TOOTCTL domains purge \
--concurrency "$DB_POOL" \
"$instance"
fi
done < "$TLS_EXPIRED_LOG"
while read -r instance; do
TLS_EXPIRED_TS=$(
date -d "$(
echo Q \
| openssl s_client \
-servername "$instance" \
-connect "${instance}":443 \
2>/dev/null \
| openssl x509 -noout -dates \
| grep 'notAfter' \
| cut -d'=' -f2
)" +%s
)
DATE_DIFF=$(($(date +%s) - TLS_EXPIRED_TS))
if [[ $DATE_DIFF -gt $TLS_EXPIRED_MAX_SEC ]]; then
echo "${instance} has a certificate expired for more than TLS_EXPIRED_MAX_SEC, purging..."
$DRY_RUN \
&& $TOOTCTL domains purge \
--concurrency "$DB_POOL" \
--dry-run \
"$instance"
$DRY_RUN \
|| $TOOTCTL domains purge \
--concurrency "$DB_POOL" \
"$instance"
fi
done < "$TLS_EXPIRED_LOG"
fi
# Log other instances errors, then if they were already in the log, purge
# them
grep \
-e 'certificate verify failed' \
-e 'timed out' \
-e 'sslv3 alert handshake failure' \
-e 'TooManyRedirectsError' \
"$CULL_LOG" \
| awk '{print $NF}' \
| cut -d'/' -f3 \
| sort -u \
> "$OTHER_ERRORS_LOG"
# Log other instances errors, then if they were already in the log, purge them
if grep -q 'https' "$CULL_LOG"; then
grep \
-e 'certificate verify failed' \
-e 'timed out' \
-e 'sslv3 alert handshake failure' \
-e 'TooManyRedirectsError' \
-e 'EndlessRedirectError' \
-e 'HostValidationError' \
"$CULL_LOG" \
| awk '{print $NF}' \
| cut -d'/' -f3 \
| sort -u \
> "$OTHER_ERRORS_LOG"
fi
# Log unjoinable instances, then if they were already in the log, purge them
if grep -q 'not available during the check:' "$CULL_LOG"; then
grep \
-A 9999 \
'not available during the check:' \
"$CULL_LOG" \
| tail -n +2 \
| sed -E 's/\s+//' \
> "$OTHER_ERRORS_LOG"
fi
test -f $PREV_ERRORS_LOG || touch $PREV_ERRORS_LOG
while read -r instance; do