#!/usr/bin/bash

# Ramdisk logs path
LOG_DIR="/shared/log/ironic/deploy"

# The ironic container creates the directory, wait for
# it to exist before running inotifywait or it can fail causing
# a spurious restart
while [ ! -d "${LOG_DIR}" ]; do
  echo "Waiting for ${LOG_DIR}"
  sleep 5
done

inotifywait -m "${LOG_DIR}" -e close_write |
    while read -r path _action file; do
        echo "************ Contents of ${path}/${file} ramdisk log file bundle **************"
        tar -xOzvvf "${path}/${file}" | sed -e "s/^/${file}: /"
        rm -f "${path}/${file}"
    done
