diff --git a/rootfs/services/_parent/run b/rootfs/services/_parent/run index 565a462..d4fbc6d 100644 --- a/rootfs/services/_parent/run +++ b/rootfs/services/_parent/run @@ -17,6 +17,18 @@ sleep 1 s6-svc -u /services/rsyslogd && s6-svwait -u /services/rsyslogd s6-svc -u /services/unbound && [ "$DISABLE_DNS_RESOLVER" = true ] || s6-svwait -u /services/unbound + +# s6-svwait only waits for the run script to start. Wait until unbound accepts +# connections, or freshclam can fail to resolve its mirrors and clamd is then +# started without a database. +if [ "$DISABLE_DNS_RESOLVER" != true ]; then + for _ in {1..150}; do + nc -z 127.0.0.1 53 2>/dev/null && break + sleep 0.2 + done + nc -z 127.0.0.1 53 2>/dev/null || logger -p mail.warn "s6-supervise : unbound is not answering after 30 seconds, starting the other services anyway" +fi + s6-svc -u /services/postfix && s6-svwait -u /services/postfix s6-svc -u /services/dovecot s6-svc -u /services/rspamd diff --git a/test/default.bats b/test/default.bats index f81feea..0c9245f 100644 --- a/test/default.bats +++ b/test/default.bats @@ -1039,10 +1039,17 @@ wait_for_log() { assert_failure } -@test "checking logs: /var/log/mail.err in mailserver_default does not exist" { - run docker exec mailserver_default cat /var/log/mail.err - assert_failure - assert_output --partial 'No such file or directory' +# `rspamc stat`, which the rspamd tests above run, makes rspamd ask its public +# fuzzy server (fuzzy-a.rspamd.com) for its hash counts. When the server does +# not answer within the rule's timeout, rspamd logs an error at mail.err, but +# the statistics come back all the same and those tests check them. A slow +# public server says nothing about this image. A lookup made while scanning a +# message would time out the same way and only leave out the fuzzy symbols; +# no test depends on one. Any other line still fails this test. +@test "checking logs: /var/log/mail.err in mailserver_default does not exist or only has fuzzy timeouts" { + run docker exec mailserver_default /bin/sh -c "[ ! -e /var/log/mail.err ] || ! grep -v 'fuzzy_check_timer_callback: got IO timeout with server' /var/log/mail.err" + assert_success + assert_output '' } # run.sh raises the soft open-files limit to the hard limit, which is what @@ -1055,80 +1062,18 @@ wait_for_log() { # Last on purpose: these make the clamav-unofficial-sigs cron job fail, which # writes to mail.log, mail.warn and mail.err, all checked clean above. # -# The next test fails now and then in CI: the job succeeds and prints nothing, -# but its error never reaches syslog at all (not even mail.log), so it is not -# rsyslog being late. To tell the possible causes apart, it runs the job with -# a logger in front of the real one that keeps a copy of what it is given, -# and on failure writes these to the test output (TAP comments): -# -# - the owner of current-dbs.txt just before and after the job, in case it -# was not root-owned when the job wrote it -# - what the job handed to logger, at each priority, in case logger or -# rsyslog lost it -# - the cron line (its minute) and any update running when the job started, -# in case the container's own hourly job overlapped the test - -SIGS_DIAG=/tmp/sigs-diag -SIGS_DBS=/var/lib/clamav-unofficial-sigs/configs/current-dbs.txt - -# Install the copying logger in $SIGS_DIAG. Each call keeps its arguments and -# input in a file of its own. -sigs_diag_setup() { - docker exec mailserver_default /bin/sh -c "rm -rf $SIGS_DIAG && mkdir -m 1777 $SIGS_DIAG" - docker exec -i mailserver_default /bin/sh -c "cat > $SIGS_DIAG/logger && chmod 755 $SIGS_DIAG/logger" <<'EOF' -#!/bin/sh -f=$(mktemp /tmp/sigs-diag/logger.XXXXXX) -echo "logger $*" > "$f" -tee -a "$f" | /usr/bin/logger "$@" -EOF -} - -# sigs_cron_job, with the copying logger first on the PATH -sigs_cron_job_diag() { - docker exec mailserver_default /bin/sh -c "grep -q '^enable_random=\"no\"' /etc/clamav-unofficial-sigs/user.conf || echo 'enable_random=\"no\"' >> /etc/clamav-unofficial-sigs/user.conf" - docker exec mailserver_default /bin/sh -c "grep -v '^#' /etc/cron.d/clamav-unofficial-sigs | grep . | { read -r m h dom mon dow user cmd; su -s /bin/sh \"\$user\" -c \"PATH=$SIGS_DIAG:\\\$PATH; export PATH; \$cmd\"; }" -} - -sigs_owner() { - docker exec mailserver_default stat -c '%U (inode %i, modified %y)' $SIGS_DBS 2>&1 -} - -sigs_running() { - docker exec mailserver_default /bin/sh -c "ps -eo pid,user,lstart,args | grep '[c]lamav-unofficial-sigs[-a-z]*\.sh' || echo '(none)'" - docker exec mailserver_default ls -l /var/lib/clamav-unofficial-sigs/pid/ 2>&1 || true -} - -# Write lines to the test output as TAP comments -sigs_diag_note() { - sed 's/^/# /' >&3 -} - +# chown alone does not always keep clamav from writing the file. When the +# update at startup fails, the file is first created by a job these tests run +# through su, whose umask makes it writable by the clamav group. @test "checking clamav-unofficial-sigs: cron job stderr goes to mail.err" { - sigs_diag_setup - docker exec mailserver_default chown root $SIGS_DBS - before=$(sigs_owner) - running=$(sigs_running) - started=$(date -u +%T.%N) - run sigs_cron_job_diag - job_status=$status job_output=$output - after=$(sigs_owner) - docker exec mailserver_default chown clamav $SIGS_DBS + docker exec mailserver_default chown root /var/lib/clamav-unofficial-sigs/configs/current-dbs.txt + docker exec mailserver_default chmod 644 /var/lib/clamav-unofficial-sigs/configs/current-dbs.txt + run sigs_cron_job + docker exec mailserver_default chown clamav /var/lib/clamav-unofficial-sigs/configs/current-dbs.txt + assert_success + assert_output '' run wait_for_log 'clamav-unofficial-sigs.*current-dbs.txt: Permission denied' /var/log/mail.err - if [ "$status" -ne 0 ]; then - { - echo "diagnostics: job started at $started UTC, exit status $job_status" - echo "cron line: $(docker exec mailserver_default grep -v '^#' /etc/cron.d/clamav-unofficial-sigs | grep .)" - echo "current-dbs.txt before the job: $before" - echo "current-dbs.txt after the job: $after" - echo "updates running when the job started, and the pid directory:" - echo "$running" - echo "what the job handed to logger:" - docker exec mailserver_default /bin/sh -c "for f in $SIGS_DIAG/logger.*; do [ -e \"\$f\" ] || { echo '(logger was not called)'; break; }; echo \"--- \$f\"; cat \"\$f\"; done" - } | sigs_diag_note - fi assert_success - assert_equal "$job_status" 0 - assert_equal "$job_output" '' } @test "checking clamav-unofficial-sigs: cron job stdout goes to mail.warning" {