From d33617131f3faa8f1d936e13b891c1163ef8ad87 Mon Sep 17 00:00:00 2001 From: Adam Oleksy Date: Mon, 22 Sep 2025 17:49:22 +0200 Subject: [PATCH] Add ENABLE_AVAHI env var to control dbus/avahi usage in container ENABLE_AVAHI decides whether dbus and avahi daemons run inside the container or if the host's instances are reused. When set to 0, /var/run/dbus and /var/run/avahi-daemon/socket must be bind-mounted by the user from the host into the container. --- docker/Dockerfile | 2 +- docker/classic/Dockerfile | 2 +- docker/classic/run.sh | 7 ++++--- docker/docker-compose.yaml | 3 +++ docker/run.sh | 12 +++++++----- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index f0680e9a..9b1347eb 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -165,5 +165,5 @@ RUN apk -U add \ # Added the shairport-sync user to the pre-existing audio group, which has ID 29, for access to the ALSA stuff COPY --from=files / / - +ENV ENABLE_AVAHI=1 ENTRYPOINT ["./run.sh"] diff --git a/docker/classic/Dockerfile b/docker/classic/Dockerfile index a7fd6b71..5b7f96e8 100644 --- a/docker/classic/Dockerfile +++ b/docker/classic/Dockerfile @@ -139,5 +139,5 @@ RUN apk --no-cache add \ # Added the shairport-sync user to the pre-existing audio group, which has ID 29, for access to the ALSA stuff COPY --from=files / / - +ENV ENABLE_AVAHI=1 ENTRYPOINT ["./run.sh"] diff --git a/docker/classic/run.sh b/docker/classic/run.sh index 0303fa9b..2d562bdb 100755 --- a/docker/classic/run.sh +++ b/docker/classic/run.sh @@ -3,13 +3,14 @@ # exist if any command returns a non-zero result set -e -rm -rf /run/dbus/dbus.pid -rm -rf /run/avahi-daemon/pid +if [ -z ${ENABLE_AVAHI+x} ] || [ $ENABLE_AVAHI -eq 0 ]; then + rm -rf /run/dbus/dbus.pid + rm -rf /run/avahi-daemon/pid dbus-uuidgen --ensure dbus-daemon --system -avahi-daemon --daemonize --no-chroot +[ -z ${ENABLE_AVAHI+x} ] || [ $ENABLE_AVAHI -eq 0 ] || avahi-daemon --daemonize --no-chroot while [ ! -f /var/run/avahi-daemon/pid ]; do echo "Warning: avahi is not running, sleeping for 1 second before trying to start shairport-sync" diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index 8a435bba..24d2f707 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -10,12 +10,15 @@ services: # PULSE_SERVER: unix:/tmp/pulseaudio.socket # Path for PulseAudio socket # PULSE_COOKIE: /tmp/pulseaudio.cookie # Path for PulseAudio cookie # XDG_RUNTIME_DIR: /tmp # Path for pipewire + # ENABLE_AVAHI: 0 # Disable DBus and Avahi daemon inside the container devices: - "/dev/snd" # ALSA device, omit if using PulseAudio # volumes: # - ./volumes/shairport-sync/shairport-sync.conf:/etc/shairport-sync.conf # Customised Shairport Sync configuration file. # - /run/user/1000/pulse/native:/tmp/pulseaudio.socket # PulseAudio socket when using that backend # - /run/user/1000/pipewire-0:/tmp/pipewire-0 # Pipewire socket when using pipewire + # - /var/run/dbus:/var/run/dbus # DBus when ENABLE_AVAHI set to 0 + # - /var/run/avahi-daemon:/var/run/avahi-daemon # Avahi socket when ENABLE_AVAHI set to 0 # command: -o pw # You can specify the desired output with command: logging: options: diff --git a/docker/run.sh b/docker/run.sh index b9caca72..3b656e9b 100755 --- a/docker/run.sh +++ b/docker/run.sh @@ -3,15 +3,17 @@ # exist if any command returns a non-zero result set -e -rm -rf /run/dbus/dbus.pid -rm -rf /run/avahi-daemon/pid +if [ -z ${ENABLE_AVAHI+x} ] || [ $ENABLE_AVAHI -eq 0 ]; then + rm -rf /run/dbus/dbus.pid + rm -rf /run/avahi-daemon/pid -dbus-uuidgen --ensure -dbus-daemon --system + dbus-uuidgen --ensure + dbus-daemon --system +fi (/usr/local/bin/nqptp > /dev/null 2>&1) & -avahi-daemon --daemonize --no-chroot +[ -z ${ENABLE_AVAHI+x} ] || [ $ENABLE_AVAHI -eq 0 ] || avahi-daemon --daemonize --no-chroot while [ ! -f /var/run/avahi-daemon/pid ]; do echo "Warning: avahi is not running, sleeping for 1 second before trying to start shairport-sync" -- 2.47.3