From 6528ac7f1f265963b481f69ca76ba23ae40334c7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 10 Nov 2025 08:20:27 +0000 Subject: [PATCH 1/4] Initial plan From 67eb7977baa548cca443e69b582c03019c84001c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 10 Nov 2025 08:23:23 +0000 Subject: [PATCH 2/4] Fix D-Bus and Avahi errors by running D-Bus daemon in container - Added dbus package to Dockerfile - Start D-Bus daemon before other services in start.sh - Removed D-Bus and Avahi socket volume mounts from docker-compose.yml - Added error handling for mkfifo commands (prevent errors on restart) - Improved script readability with blank lines and better comments - Increased PulseAudio startup delay to 2 seconds for stability Co-authored-by: tipbr <10751100+tipbr@users.noreply.github.com> --- Dockerfile | 31 +++++++++++++++++++++++++------ docker-compose.yml | 3 --- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4db082b..cffd75c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,7 @@ RUN apt-get update && apt-get install -y \ systemd \ lsb-release \ procps \ + dbus \ avahi-daemon \ avahi-utils \ libnss-mdns \ @@ -51,28 +52,46 @@ RUN echo '[stream]' > /etc/snapserver/snapserver.conf \ COPY snapserver.service /etc/avahi/services/snapserver.service COPY shairport-sync.service /etc/avahi/services/shairport-sync.service -# Create startup script with Avahi, librespot, shairport-sync, and PulseAudio for Google Cast +# Create startup script with D-Bus, Avahi, librespot, shairport-sync, and PulseAudio for Google Cast RUN echo '#!/bin/bash' > /start.sh \ + && echo 'set -e' >> /start.sh \ + && echo '' >> /start.sh \ + && echo '# Start D-Bus daemon (required for Avahi and PulseAudio)' >> /start.sh \ + && echo 'mkdir -p /var/run/dbus' >> /start.sh \ + && echo 'rm -f /var/run/dbus/pid' >> /start.sh \ + && echo 'dbus-daemon --system --fork' >> /start.sh \ + && echo 'sleep 1' >> /start.sh \ + && echo '' >> /start.sh \ && echo 'mkdir -p /tmp' >> /start.sh \ && echo '# Create named pipes for audio streams' >> /start.sh \ - && echo 'mkfifo -m a=rw /tmp/snapfifo-spotify' >> /start.sh \ - && echo 'mkfifo -m a=rw /tmp/snapfifo-airplay' >> /start.sh \ - && echo 'mkfifo -m a=rw /tmp/snapfifo-googlecast' >> /start.sh \ - && echo 'systemctl disable raspotify' >> /start.sh \ + && echo 'mkfifo -m a=rw /tmp/snapfifo-spotify 2>/dev/null || true' >> /start.sh \ + && echo 'mkfifo -m a=rw /tmp/snapfifo-airplay 2>/dev/null || true' >> /start.sh \ + && echo 'mkfifo -m a=rw /tmp/snapfifo-googlecast 2>/dev/null || true' >> /start.sh \ + && echo '' >> /start.sh \ + && echo '# Disable raspotify systemd service' >> /start.sh \ + && echo 'systemctl disable raspotify 2>/dev/null || true' >> /start.sh \ + && echo '' >> /start.sh \ && echo '# Start Avahi daemon' >> /start.sh \ && echo 'avahi-daemon --daemonize' >> /start.sh \ + && echo 'sleep 1' >> /start.sh \ + && echo '' >> /start.sh \ && echo '# Start PulseAudio in system mode for Google Cast receiver' >> /start.sh \ && echo 'pulseaudio --system --disallow-exit --disallow-module-loading=false --exit-idle-time=-1 &' >> /start.sh \ - && echo 'sleep 1' >> /start.sh \ + && echo 'sleep 2' >> /start.sh \ + && echo '' >> /start.sh \ && echo '# Create PulseAudio sink and pipe to snapcast' >> /start.sh \ && echo 'pactl load-module module-pipe-sink file=/tmp/snapfifo-googlecast sink_name=snapcast_googlecast format=s16le rate=44100 channels=2 || true' >> /start.sh \ && echo 'pactl set-default-sink snapcast_googlecast || true' >> /start.sh \ + && echo '' >> /start.sh \ && echo '# Start librespot for Spotify' >> /start.sh \ && echo 'librespot --backend pipe --device /tmp/snapfifo-spotify --name "Spotify Multiroom" &' >> /start.sh \ + && echo '' >> /start.sh \ && echo '# Start shairport-sync for AirPlay' >> /start.sh \ && echo 'shairport-sync -c /etc/shairport-sync.conf &' >> /start.sh \ + && echo '' >> /start.sh \ && echo '# Give services time to initialize' >> /start.sh \ && echo 'sleep 2' >> /start.sh \ + && echo '' >> /start.sh \ && echo '# Start snapserver' >> /start.sh \ && echo 'snapserver -c /etc/snapserver/snapserver.conf' >> /start.sh \ && chmod +x /start.sh diff --git a/docker-compose.yml b/docker-compose.yml index 902302a..bcbb13a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,9 +6,6 @@ services: container_name: librespot-snapcast network_mode: host # Use host networking for better audio performance and mDNS discovery restart: unless-stopped - volumes: - - /var/run/dbus:/var/run/dbus # Share D-Bus with host for Avahi - - /var/run/avahi-daemon/socket:/var/run/avahi-daemon/socket # Share Avahi socket with host environment: - TZ=UTC # Set your timezone privileged: true # Required for some system-level operations From 0642ebfd9bf7e36cb803f7a116358ae0bccf1562 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 10 Nov 2025 08:44:44 +0000 Subject: [PATCH 3/4] Fix PulseAudio authentication and port binding errors - Kill any existing snapserver/pulseaudio processes before starting (fixes port conflicts) - Create PulseAudio cookie directory to avoid authentication warnings - Ensures clean startup on fresh Raspberry Pi OS with host network mode Co-authored-by: tipbr <10751100+tipbr@users.noreply.github.com> --- Dockerfile | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Dockerfile b/Dockerfile index cffd75c..033eff1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -62,6 +62,11 @@ RUN echo '#!/bin/bash' > /start.sh \ && echo 'dbus-daemon --system --fork' >> /start.sh \ && echo 'sleep 1' >> /start.sh \ && echo '' >> /start.sh \ + && echo '# Kill any existing services that might conflict (from host if using host network)' >> /start.sh \ + && echo 'pkill -9 snapserver 2>/dev/null || true' >> /start.sh \ + && echo 'pkill -9 pulseaudio 2>/dev/null || true' >> /start.sh \ + && echo 'sleep 1' >> /start.sh \ + && echo '' >> /start.sh \ && echo 'mkdir -p /tmp' >> /start.sh \ && echo '# Create named pipes for audio streams' >> /start.sh \ && echo 'mkfifo -m a=rw /tmp/snapfifo-spotify 2>/dev/null || true' >> /start.sh \ @@ -75,6 +80,9 @@ RUN echo '#!/bin/bash' > /start.sh \ && echo 'avahi-daemon --daemonize' >> /start.sh \ && echo 'sleep 1' >> /start.sh \ && echo '' >> /start.sh \ + && echo '# Create PulseAudio cookie directory to avoid authentication warnings' >> /start.sh \ + && echo 'mkdir -p /var/run/pulse/.config/pulse' >> /start.sh \ + && echo '' >> /start.sh \ && echo '# Start PulseAudio in system mode for Google Cast receiver' >> /start.sh \ && echo 'pulseaudio --system --disallow-exit --disallow-module-loading=false --exit-idle-time=-1 &' >> /start.sh \ && echo 'sleep 2' >> /start.sh \ From a6b0a17bb3ccf6da811c763b8e899da199d8d2f9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 10 Nov 2025 08:46:53 +0000 Subject: [PATCH 4/4] Clean up stale PID files on container restart - Kill avahi-daemon process before restart - Remove stale PID files for avahi-daemon and pulseaudio - Fixes "Daemon already running" errors after forceful container stop - Ensures clean restart after docker compose down/stop Co-authored-by: tipbr <10751100+tipbr@users.noreply.github.com> --- Dockerfile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Dockerfile b/Dockerfile index 033eff1..75d686f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -65,6 +65,12 @@ RUN echo '#!/bin/bash' > /start.sh \ && echo '# Kill any existing services that might conflict (from host if using host network)' >> /start.sh \ && echo 'pkill -9 snapserver 2>/dev/null || true' >> /start.sh \ && echo 'pkill -9 pulseaudio 2>/dev/null || true' >> /start.sh \ + && echo 'pkill -9 avahi-daemon 2>/dev/null || true' >> /start.sh \ + && echo '' >> /start.sh \ + && echo '# Clean up stale PID files from previous runs' >> /start.sh \ + && echo 'rm -f /run/avahi-daemon/pid 2>/dev/null || true' >> /start.sh \ + && echo 'rm -f /var/run/pulse/pid 2>/dev/null || true' >> /start.sh \ + && echo 'rm -f /var/run/pulse/.pid 2>/dev/null || true' >> /start.sh \ && echo 'sleep 1' >> /start.sh \ && echo '' >> /start.sh \ && echo 'mkdir -p /tmp' >> /start.sh \