Handle recursive copy of /var/log from containers

https://review.opendev.org/#/c/578892/ handled
the recursive copy but assumed /var/log is mounted
to /var/log inside the container, The destination
mount can differ like in fluentd_client [1]. To handle
such cases use <container cli> inspect to detect if
/var/log is mounted inside container or not.

[1] https://github.com/openstack/tripleo-heat-templates/blob/stable/pike/docker/services/fluentd-client.yaml#L116

Change-Id: I349399b569774b92724978f9c6003b88393cf84d
This commit is contained in:
yatinkarel 2019-06-03 19:51:15 +05:30
parent 54095d38d9
commit cc24a877ea
1 changed files with 5 additions and 1 deletions

View File

@ -238,6 +238,8 @@
container_cp() {
docker cp ${1}:${2} $3
}
# NOTE(ykarel) podman inspect returns 'source' while docker inspect returns 'Source'
source_mount=Source
fi
if [ $engine = 'podman' ]; then
@ -250,6 +252,8 @@
cp -rT ${mnt}${2} $3
podman umount $1
}
# NOTE(ykarel) podman inspect returns 'source' while docker inspect returns 'Source'
source_mount=source
fi
BASE_CONTAINER_EXTRA=/var/log/extra/${engine};
@ -297,7 +301,7 @@
# NOTE(flaper87): This should go away. Services should be
# using a `logs` volume
# NOTE(mandre) Do not copy logs if the containers is bind mounting /var/log directory
if ! ${engine} exec $cont stat $BASE_CONTAINER_EXTRA 2>1 > /dev/null; then
if ! ${engine} inspect $cont | jq .[0].Mounts[].$source_mount | grep -x '"/var/log[/]*"' 2>1 > /dev/null; then
container_cp $cont /var/log $INFO_DIR/log;
fi;