From ce566167f2d5bec85c80e43e626272a58da9c90c Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Wed, 13 Oct 2021 16:12:05 +0200 Subject: [PATCH] Improve OS logging (#1590) * Avoid duplicate log entries So far the hassos-supervisor.service starts the hassos-supervisor script which in turn attaches to the Supervisor container. This causes stdout and stderr to be forwarded to the service unit, which in turn logs it in the journal. However, Docker too logs all stdout/stderr to the journal through the systemd-journald log driver. Do not attach to the Supervisor container to avoid logging the Supervisor twice. Note that this no longer forwards signals to the container. However, the hassos-supervisor.service uses the ExecStop= setting to make sure the container gets gracefully stopped. * Use image and container name as syslog identifier By default Docker users the container id as syslog identifier. This leads to log messages which cannot easily be attributed to a particular container (since the container id is a random hex string). Use the image and container name as syslog identifier. Note that the Docker journald log driver still stores the container id as a separate field (CONTAINER_ID), in case the particular instance need to be tracked. --- .../etc/systemd/system/docker.service.d/hassos.conf | 2 +- buildroot-external/rootfs-overlay/usr/sbin/hassos-supervisor | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/buildroot-external/rootfs-overlay/etc/systemd/system/docker.service.d/hassos.conf b/buildroot-external/rootfs-overlay/etc/systemd/system/docker.service.d/hassos.conf index 87fafd279..ae8598aee 100644 --- a/buildroot-external/rootfs-overlay/etc/systemd/system/docker.service.d/hassos.conf +++ b/buildroot-external/rootfs-overlay/etc/systemd/system/docker.service.d/hassos.conf @@ -3,4 +3,4 @@ RequiresMountsFor=/etc/docker /mnt/data /var/lib/docker [Service] ExecStart= -ExecStart=/usr/bin/dockerd -H fd:// --cpu-rt-runtime=950000 --storage-driver=overlay2 --log-driver=journald --data-root /mnt/data/docker +ExecStart=/usr/bin/dockerd -H fd:// --cpu-rt-runtime=950000 --storage-driver=overlay2 --log-driver=journald --log-opt tag="{{.ImageName}}/{{.Name}}" --data-root /mnt/data/docker diff --git a/buildroot-external/rootfs-overlay/usr/sbin/hassos-supervisor b/buildroot-external/rootfs-overlay/usr/sbin/hassos-supervisor index def085137..7727968a9 100755 --- a/buildroot-external/rootfs-overlay/usr/sbin/hassos-supervisor +++ b/buildroot-external/rootfs-overlay/usr/sbin/hassos-supervisor @@ -100,4 +100,5 @@ fi # Run supervisor mkdir -p ${SUPERVISOR_DATA} echo "[INFO] Starting the Supervisor..." -exec docker container start --attach hassio_supervisor +docker container start hassio_supervisor +exec docker container wait hassio_supervisor