Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding dbus and avahi to enable shairport-sync to work correctly #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

smplman
Copy link

@smplman smplman commented Feb 5, 2024

This PR came about to fix #3. It modifies the Dockerfile to add the dbus apk along with service startups for both dbus and avahi. I was going to add an ENV var to be able to toggle these features, but ran into issues making dbus and avahi optional dependencies of svc-snapserver.

Any suggestions or feedback are welcome.

@smplman
Copy link
Author

smplman commented Feb 7, 2024

@sweisgerber can you take a look at this when you get a chance.

@sweisgerber
Copy link
Owner

Yeah, I will have a look, thanks for the submission.
Didn't find time yet, as I want to try keeping it behind an ENV toggle

@sweisgerber
Copy link
Owner

Hey there,

did you manage to successfully start this image?
after building and start-up, neither avahi/dbus, nor snapserver come up anymore.

Building with: sudo docker buildx build ./ -t local/docker-snapcast:latest

running with:

version: "3"
services:
  snapcast:
    image: local/docker-snapcast:latest
    hostname: snapcast-local
    environment:
      - PUID=1000
      - PGID=1000 # set to audio group ID
      - TZ=Europe/Berlin
      - START_SNAPCLIENT=false # set to `true` for snapclient to start
      # --host: name or ip of compose service or dockerhost
      # --soundcard: <ID> from `snapclient -l` from inside the container
      # - SNAPCLIENT_OPTS=--host snapcast --soundcard <ID>
      #   => Don't use quotes for SNAPCLIENT_OPTS="" !
      # - HOST_AUDIO_GROUP=<AUDIO-GID> # set to GID of host audio group
    restart: "unless-stopped"
    ports:
      - 1704:1704 # port for the actual audio streaming
      - 1705:1705 # port for TCP Json RPC
      - 1780:1780 # port for the SnapWeb Webinterface
    # devices:
      # - /dev/snd:/dev/snd # optional, only if you want to use snapclient
    volumes:
      - /srv/snapcast/config/:/config/
      - /srv/snapcast/data/:/data/
      # /audio should get used to place FIFOs for audio playback from mpd/mopidy/host/etc
      - /srv/audio-fifos/:/audio/

Unchanged commit c0ae760

@smplman
Copy link
Author

smplman commented Feb 28, 2024

Thanks for taking a look @sweisgerber.

Here is my docker-compose.yaml

version: "3"
services:
  snapcast:
    build: .
    hostname: falcon
    network_mode: host
    environment:
      - PUID=1000
      - PGID=1000 # set to audio group ID
      - TZ=Europe/Berlin
      - START_SNAPCLIENT=false # set to `true` for snapclient to start
    restart: "unless-stopped"
    ports:
      - 1704:1704 # port for the actual audio streaming
      - 1705:1705 # port for TCP Json RPC
      - 1780:1780 # port for the SnapWeb Webinterface
    devices:
      - /dev/snd:/dev/snd # optional, only if you want to use snapclient
    privileged: true
    volumes:
      - ./snapcast/config/:/config/
      - ./snapcast/data/:/data/

and here is how I'm building

docker compose build --no-cache

Then running docker-compose up

Here are the docker logs

 ✘ smplman@falcon  ~/projects/docker-snapcast   smplman/shairport-sync  docker compose up              
[+] Running 1/0
 ✔ Container docker-snapcast-snapcast-1  Created                                                                                                                       0.0s 
Attaching to snapcast-1
snapcast-1  | [migrations] started
snapcast-1  | [migrations] no migrations found
snapcast-1  | usermod: no changes
snapcast-1  | ───────────────────────────────────────
snapcast-1  |   _____ __ __ _____ _____ _____ _____ 
snapcast-1  |  |     |  |  |   __|_   _|     |     |
snapcast-1  |  |   --|  |  |__   | | | |  |  | | | |
snapcast-1  |  |_____|_____|_____| |_| |_____|_|_|_|
snapcast-1  |        _____ __ __ _ __    ____  
snapcast-1  |       | __  |  |  | |  |  |    \ 
snapcast-1  |       | __ -|  |  | |  |__|  |  |
snapcast-1  |       |_____|_____|_|_____|____/ 
snapcast-1  | 
snapcast-1  |   Based on images from linuxserver.io
snapcast-1  | ───────────────────────────────────────
snapcast-1  | 
snapcast-1  | To support LSIO projects visit:
snapcast-1  | https://www.linuxserver.io/donate/
snapcast-1  | 
snapcast-1  | ───────────────────────────────────────
snapcast-1  | GID/UID
snapcast-1  | ───────────────────────────────────────
snapcast-1  | 
snapcast-1  | User UID:    1000
snapcast-1  | User GID:    1000
snapcast-1  | ───────────────────────────────────────
snapcast-1  | 
snapcast-1  | cp: not replacing '/config/snapserver.conf'
snapcast-1  | Not starting snapclient. Set 'START_SNAPCLIENT=true' to start it.
snapcast-1  | [custom-init] No custom files found, skipping...
snapcast-1  | Starting dbus
snapcast-1  | Starting avahi
snapcast-1  | Daemon already running on PID 168
snapcast-1  | Starting avahi
snapcast-1  | Process 168 died: No such process; trying to remove PID file. (/run/avahi-daemon//pid)
snapcast-1  | Found user 'avahi' (UID 86) and group 'avahi' (GID 86).
snapcast-1  | Successfully dropped root privileges.
snapcast-1  | avahi-daemon 0.8 starting up.
snapcast-1  | WARNING: No NSS support for mDNS detected, consider installing nss-mdns!
snapcast-1  | Loading service file /etc/avahi/services/sftp-ssh.service.
snapcast-1  | Loading service file /etc/avahi/services/ssh.service.
snapcast-1  | *** WARNING: Detected another IPv4 mDNS stack running on this host. This makes mDNS unreliable and is thus not recommended. ***
snapcast-1  | *** WARNING: Detected another IPv6 mDNS stack running on this host. This makes mDNS unreliable and is thus not recommended. ***
snapcast-1  | Joining mDNS multicast group on interface br-8228f277da68.IPv4 with address 172.20.0.1.
snapcast-1  | New relevant interface br-8228f277da68.IPv4 for mDNS.
snapcast-1  | Joining mDNS multicast group on interface docker0.IPv6 with address fe80::42:5eff:fecd:ba6d.
snapcast-1  | New relevant interface docker0.IPv6 for mDNS.
snapcast-1  | Joining mDNS multicast group on interface docker0.IPv4 with address 172.17.0.1.
snapcast-1  | New relevant interface docker0.IPv4 for mDNS.
snapcast-1  | Joining mDNS multicast group on interface br-f29671e281ee.IPv4 with address 172.18.0.1.
snapcast-1  | New relevant interface br-f29671e281ee.IPv4 for mDNS.
snapcast-1  | Joining mDNS multicast group on interface wlp2s0.IPv6 with address fe80::99ff:5cf0:8c85:a8d8.
snapcast-1  | New relevant interface wlp2s0.IPv6 for mDNS.
snapcast-1  | Joining mDNS multicast group on interface wlp2s0.IPv4 with address 192.168.1.15.
snapcast-1  | New relevant interface wlp2s0.IPv4 for mDNS.
snapcast-1  | Joining mDNS multicast group on interface lo.IPv6 with address ::1.
snapcast-1  | New relevant interface lo.IPv6 for mDNS.
snapcast-1  | Joining mDNS multicast group on interface lo.IPv4 with address 127.0.0.1.
snapcast-1  | New relevant interface lo.IPv4 for mDNS.
snapcast-1  | Network interface enumeration completed.
snapcast-1  | Registering new address record for 172.20.0.1 on br-8228f277da68.IPv4.
snapcast-1  | Registering new address record for fe80::42:5eff:fecd:ba6d on docker0.*.
snapcast-1  | Registering new address record for 172.17.0.1 on docker0.IPv4.
snapcast-1  | Registering new address record for 172.18.0.1 on br-f29671e281ee.IPv4.
snapcast-1  | Registering new address record for fe80::99ff:5cf0:8c85:a8d8 on wlp2s0.*.
snapcast-1  | Registering new address record for 192.168.1.15 on wlp2s0.IPv4.
snapcast-1  | Registering new address record for ::1 on lo.*.
snapcast-1  | Registering new address record for 127.0.0.1 on lo.IPv4.
snapcast-1  | Server startup complete. Host name is falcon.local. Local service cookie is 3015113232.
snapcast-1  | 2024-02-28 04-20-16.558 [Info] (Snapserver) Version 0.27.0
snapcast-1  | 2024-02-28 04-20-16.558 [Info] (Snapserver) Adding source: airplay:///shairport-sync?name=shairport&dryout_ms=2000&devicename=Snapcast-Air&port=5000
snapcast-1  | 2024-02-28 04-20-16.558 [Notice] (init) Settings file: "/data/server.json"
snapcast-1  | 2024-02-28 04-20-16.558 [Info] (Snapserver) Using HTTP host name: falcon
snapcast-1  | 2024-02-28 04-20-16.561 [Info] (Avahi) Adding service 'Snapcast'
snapcast-1  | 2024-02-28 04-20-16.563 [Info] (PcmStream) PcmStream: shairport, sampleFormat: 44100:16:2
snapcast-1  | 2024-02-28 04-20-16.563 [Info] (Server) Stream: {"fragment":"","host":"","path":"/shairport-sync","query":{"chunk_ms":"20","codec":"pcm","devicename":"Snapcast-Air","dryout_ms":"2000","name":"shairport","port":"5000","sampleformat":"44100:16:2"},"raw":"airplay:////shairport-sync?chunk_ms=20&codec=pcm&devicename=Snapcast-Air&dryout_ms=2000&name=shairport&port=5000&sampleformat=44100:16:2","scheme":"airplay"}
snapcast-1  | 2024-02-28 04-20-16.563 [Info] (PcmEnc) Init
snapcast-1  | 2024-02-28 04-20-16.566 [Error] (AirplayStream) Error opening metadata pipe, retrying in 500ms. Error: assign: Bad file descriptor [system:9 at /usr/include/boost/asio/detail/impl/reactive_descriptor_service.ipp:120 in function 'assign']
snapcast-1  | 2024-02-28 04-20-16.566 [Info] (ControlServer) Creating TCP acceptor for address: 0.0.0.0, port: 1705
snapcast-1  | 2024-02-28 04-20-16.566 [Info] (ControlServer) Creating HTTP acceptor for address: 0.0.0.0, port: 1780
snapcast-1  | 2024-02-28 04-20-16.566 [Info] (StreamServer) Creating stream acceptor for address: 0.0.0.0, port: 1704
snapcast-1  | 2024-02-28 04-20-16.566 [Info] (Snapserver) Number of threads: 4, hw threads: 12
snapcast-1  | 2024-02-28 04-20-16.568 [Info] (AirplayStream) (shairport) Warning: the option -u is no longer needed and is deprecated. Debug and statistics output to STDERR is now the default. Use "--log-to-syslog" to revert.
snapcast-1  | 2024-02-28 04-20-17.067 [Info] (AirplayStream) Metadata pipe opened: /tmp/shairmeta.191.5000
snapcast-1  | 2024-02-28 04-20-17.067 [Info] (AirplayStream) Waiting for metadata, retrying in 2500ms
snapcast-1  | Service "falcon" (/etc/avahi/services/ssh.service) successfully established.
snapcast-1  | Service "falcon" (/etc/avahi/services/sftp-ssh.service) successfully established.
snapcast-1  | 2024-02-28 04-20-17.473 [Info] (Avahi) Service 'Snapcast' successfully established.
snapcast-1  | 2024-02-28 04-20-17.569 [Notice] (ControlServer) ControlServer::NewConnection: 127.0.0.1
snapcast-1  | Connection to localhost (127.0.0.1) 1780 port [tcp/*] succeeded!
snapcast-1  | 2024-02-28 04-20-19.568 [Info] (AirplayStream) Waiting for metadata, retrying in 2500ms
snapcast-1  | 2024-02-28 04-20-22.068 [Info] (AirplayStream) Waiting for metadata, retrying in 2500ms
snapcast-1  | 2024-02-28 04-20-24.569 [Info] (AirplayStream) Waiting for metadata, retrying in 2500ms
snapcast-1  | 2024-02-28 04-20-27.070 [Info] (AirplayStream) Waiting for metadata, retrying in 2500ms
snapcast-1  | 2024-02-28 04-20-29.571 [Info] (AirplayStream) Waiting for metadata, retrying in 2500ms
snapcast-1  | 2024-02-28 04-20-32.072 [Info] (AirplayStream) Waiting for metadata, retrying in 2500ms
snapcast-1  | 2024-02-28 04-20-34.573 [Info] (AirplayStream) Waiting for metadata, retrying in 2500ms
snapcast-1  | 2024-02-28 04-20-36.201 [Notice] (ControlServer) ControlServer::NewConnection: 127.0.0.1
snapcast-1  | 2024-02-28 04-20-36.201 [Info] (ControlServer) Removing 1 inactive session(s), active sessions: 1
snapcast-1  | 2024-02-28 04-20-37.073 [Info] (AirplayStream) Waiting for metadata, retrying in 2500ms
snapcast-1  | 2024-02-28 04-20-37.464 [Notice] (ControlServer) ControlServer::NewConnection: 127.0.0.1
snapcast-1  | 2024-02-28 04-20-37.464 [Notice] (ControlServer) ControlServer::NewConnection: 127.0.0.1
snapcast-1  | 2024-02-28 04-20-37.581 [Notice] (ControlServer) ControlServer::NewConnection: 127.0.0.1
snapcast-1  | 2024-02-28 04-20-39.574 [Info] (AirplayStream) Waiting for metadata, retrying in 2500ms
snapcast-1  | 2024-02-28 04-20-42.074 [Info] (AirplayStream) Waiting for metadata, retrying in 2500ms
snapcast-1  | 2024-02-28 04-20-42.158 [Notice] (ControlServer) ControlServer::NewConnection: 127.0.0.1
snapcast-1  | 2024-02-28 04-20-42.158 [Info] (ControlServer) Removing 1 inactive session(s), active sessions: 5
snapcast-1  | 2024-02-28 04-20-42.169 [Info] (Server) Hello from 2f828b13-07e4-4536-8c9d-49127f34bc86, host: Snapweb client, v0.5.0, ClientName: Snapweb, OS: Linux x86_64, Arch: web, Protocol version: 2
snapcast-1  | 2024-02-28 04-20-42.169 [Info] (ControlServer) Removing 1 inactive session(s), active sessions: 4
snapcast-1  | 2024-02-28 04-20-44.575 [Info] (AirplayStream) Waiting for metadata, retrying in 2500ms
snapcast-1  | 2024-02-28 04-20-47.075 [Info] (AirplayStream) Waiting for metadata, retrying in 2500ms
snapcast-1  | 2024-02-28 04-20-49.576 [Info] (AirplayStream) Waiting for metadata, retrying in 2500ms
snapcast-1  | 2024-02-28 04-20-52.077 [Info] (AirplayStream) Waiting for metadata, retrying in 2500ms
snapcast-1  | 2024-02-28 04-20-54.578 [Info] (AirplayStream) Waiting for metadata, retrying in 2500ms
snapcast-1  | 2024-02-28 04-20-57.079 [Info] (AirplayStream) Waiting for metadata, retrying in 2500ms
snapcast-1  | 2024-02-28 04-20-59.580 [Info] (AirplayStream) Waiting for metadata, retrying in 2500ms
snapcast-1  | 2024-02-28 04-21-02.080 [Info] (AirplayStream) Waiting for metadata, retrying in 2500ms
snapcast-1  | 2024-02-28 04-21-05.504 [Info] (PcmStream) State changed: shairport, state: idle => playing
snapcast-1  | 2024-02-28 04-21-05.504 [Info] (Server) onStateChanged (shairport): playing
snapcast-1  | 2024-02-28 04-21-12.795 [Info] (PcmStream) State changed: shairport, state: playing => idle
snapcast-1  | 2024-02-28 04-21-12.795 [Info] (Server) onStateChanged (shairport): idle
snapcast-1  | 2024-02-28 04-21-14.880 [Info] (Server) onStateChanged (shairport): playing
snapcast-1  | 2024-02-28 04-21-14.880 [Info] (Server) sendAsync: WireChunk
snapcast-1  | 2024-02-28 04-21-23.730 [Info] (PcmStream) State changed: shairport, state: playing => idle
snapcast-1  | 2024-02-28 04-21-23.730 [Info] (Server) onStateChanged (shairport): idle

Here is my snapserver.conf

[server]
datadir = /data/

[http]
# enable HTTP Json RPC (HTTP POST and websockets)
enabled = true
bind_to_address = 0.0.0.0
port = 1780
doc_root = /usr/share/snapserver/snapweb

[tcp]
enabled = true
bind_to_address = 0.0.0.0
port = 1705

[stream]
bind_to_address = 0.0.0.0
port = 1704
source = airplay:///shairport-sync?name=shairport&dryout_ms=2000&devicename=Snapcast-Air&port=5000
sampleformat = 48000:16:2
codec = pcm
buffer = 1000
send_to_muted = false

[streaming_client]
initial_volume = 100

[logging]

I am able to cast Spotify from phone to my laptop via AirPlay.

@freakshock88
Copy link

Running into the same airplay issue as this PR is attempting to fix. Can the PR be merged to fix it or is there still an outstanding issue to be solved?

@sweisgerber
Copy link
Owner

Hello,

sure that avahi is even needed?
From my tests, it doesn't even start?

$ sudo docker ps                                                                                                                                                                 10:00:20 
CONTAINER ID   IMAGE                         COMMAND   CREATED          STATUS          PORTS     NAMES
1bd6af5dd431   docker-snapcast-pr-snapcast   "/init"   15 seconds ago   Up 15 seconds             docker-snapcast-pr-snapcast-1
#
$ sudo docker compose exec snapcast sh                                                                                                                                           
root@falcon:/# ps ax | grep -i avahi
     38 ?        S      0:00 s6-supervise svc-avahi
    181 pts/0    S+     0:00 grep -i avahi
# 

In contrast, d-bus works fine:

root@falcon:/# ps ax | grep -i dbus
     43 ?        S      0:00 s6-supervise svc-dbus
    145 ?        S      0:00 /package/admin/s6-2.12.0.2/command/s6-svlisten1 -U -- /run/s6-rc/servicedirs/svc-dbus /package/admin/s6-2.12.0.2/command/s6-svc -u -- /run/s6-rc/servicedirs/svc-dbus
    151 ?        Rs     0:44 dbus-daemon --system --nofork --nopidfile
    186 pts/0    S+     0:00 grep -i dbus
root@falcon:/#

I used your compose from above 1:1

I noticed it, because I restructured the s6 run files a little, that dbus & avahi are no hard-dependency for snapserver anymore and one can hide their start-up behind a feature flag.

The feature-flag dependent start-up from my side is ready and I will push it soonish.

Could you please test if avahi starts for you inside the container and report back?
If it doesn't start, you get ride of it from the docker setup and try again, if your setup works?

I'm unable to test airplay support at home.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Shairport-sync errors when uncommented in snapcast config
3 participants