diff --git a/lib/common.sh b/lib/common.sh index ded9f90..11f3cf4 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -199,3 +199,18 @@ verbose() { if [ "${KRUNVM_RUNNER_VERBOSE:-0}" -ge "1" ]; then _log NFO "$@"; fi info() { if [ "${KRUNVM_RUNNER_VERBOSE:-0}" -ge "1" ]; then _log NFO "$@"; fi; } warn() { _log WRN "$@"; } error() { _log ERR "$@" && exit 1; } + +sublog() { + # Eagerly wait for the log file to exist + while ! [ -f "${1-0}" ]; do sleep 0.1; done + verbose "$1 now present on disk" + + # Then reroute its content through our logging printf style + tail -n +0 -f "$1" | while IFS= read -r line; do + printf '[%s] [%s] %s\n' \ + "${2-"${KRUNVM_RUNNER_BIN:-$(basename "$0")}"}" \ + "$(date +'%Y%m%d-%H%M%S')" \ + "$line" \ + >&"$KRUNVM_RUNNER_LOG" + done +} diff --git a/runner/runner.sh b/runner/runner.sh index b4c313a..8a9d7f3 100755 --- a/runner/runner.sh +++ b/runner/runner.sh @@ -297,6 +297,8 @@ docker_daemon() { # to be able to access the socket. chgrp "docker" /var/run/docker.sock chmod g+rw /var/run/docker.sock + # Forwards podman's log file (must be same as in containers.conf) + sublog /var/log/podman.log podman & elif [ -n "$dockerd" ]; then # For docker, the user must be in the docker group to access the daemon. verbose "Starting $dockerd as a daemon"