diff mbox series

[v2,2/2] package/docker-engine: add wrapper script for logging to syslog

Message ID 20240731181334.3717996-2-fiona.klute@gmx.de
State Accepted
Headers show
Series [v2,1/2] package/docker-engine: rewrite dockerd init script | expand

Commit Message

Fiona Klute July 31, 2024, 6:13 p.m. UTC
From: "Fiona Klute (WIWA)" <fiona.klute@gmx.de>

Dockerd logs only to stdout/stderr [1], which is lost with
--background. The upstream SysV init script [2] logs to a file by
passing --no-close to start-stop-daemon and redirecting the output,
but that option is not supported by Busybox' start-stop-daemon.

The wrapper script added with this commit captures the output of
dockerd (or whatever other command it is given) and forwards each line
to syslog.

[1] https://github.com/moby/moby/discussions/48260
[2] https://github.com/moby/moby/blob/50c3d19179e69f9e7ff01f688c4dbf32c5129ced/contrib/init/sysvinit-debian/docker

Signed-off-by: Fiona Klute (WIWA) <fiona.klute@gmx.de>
---
Changes v1 -> v2:
* slightly clarify comment about wrapper in init script

 package/docker-engine/S60dockerd                | 8 ++++++--
 package/docker-engine/docker-engine.mk          | 2 ++
 package/docker-engine/dockerd-syslog-wrapper.sh | 4 ++++
 3 files changed, 12 insertions(+), 2 deletions(-)
 create mode 100644 package/docker-engine/dockerd-syslog-wrapper.sh

--
2.45.2
diff mbox series

Patch

diff --git a/package/docker-engine/S60dockerd b/package/docker-engine/S60dockerd
index aab50d84d4..dda6dc7474 100644
--- a/package/docker-engine/S60dockerd
+++ b/package/docker-engine/S60dockerd
@@ -10,10 +10,14 @@  DOCKERD_ARGS=""

 start() {
 	printf 'Starting %s: ' "$DAEMON"
+	# Dockerd logs only to stdout/stderr, which is lost with
+	# --background. The wrapper script runs the given command
+	# (after "--", including dockerd) and forwards stdout/stderr
+	# to syslog.
 	# shellcheck disable=SC2086 # we need word splitting for DOCKERD_ARGS
 	start-stop-daemon --start --background --pidfile "$PIDFILE" \
-		--exec "/usr/bin/$DAEMON" \
-		-- --pidfile "$PIDFILE" $DOCKERD_ARGS
+		--exec /usr/libexec/dockerd-syslog-wrapper.sh \
+		-- "/usr/bin/$DAEMON" --pidfile "$PIDFILE" $DOCKERD_ARGS
 	status=$?
 	if [ "$status" -eq 0 ]; then
 		echo "OK"
diff --git a/package/docker-engine/docker-engine.mk b/package/docker-engine/docker-engine.mk
index c7c51c5ef5..268b851520 100644
--- a/package/docker-engine/docker-engine.mk
+++ b/package/docker-engine/docker-engine.mk
@@ -72,6 +72,8 @@  endef
 define DOCKER_ENGINE_INSTALL_INIT_SYSV
 	$(INSTALL) -D -m 755 package/docker-engine/S60dockerd \
 		$(TARGET_DIR)/etc/init.d/S60dockerd
+	$(INSTALL) -D -m 755 package/docker-engine/dockerd-syslog-wrapper.sh \
+		$(TARGET_DIR)/usr/libexec/dockerd-syslog-wrapper.sh
 endef

 define DOCKER_ENGINE_USERS
diff --git a/package/docker-engine/dockerd-syslog-wrapper.sh b/package/docker-engine/dockerd-syslog-wrapper.sh
new file mode 100644
index 0000000000..3d6a80a739
--- /dev/null
+++ b/package/docker-engine/dockerd-syslog-wrapper.sh
@@ -0,0 +1,4 @@ 
+#!/bin/sh
+"${@}" 2>&1 | while read -r LINE; do
+	logger -t "$(basename "${1}")" "$LINE";
+done