snapcast
snapcast copied to clipboard
Snapserver won't start at boot, works fine starting manually. (Alsa USB codec)
For some reason the snapserver service does not recognise the Alsa USB input device when starting from boot. When I start the service manually however it works fine. I'm running a fresh install of Raspberry Pi OS Lite. I have checked in dmesg that the USB device is initialized several seconds before the Snapserver service is called for the first time. I have checked that the user 'snapserver' is a member of the 'audio' group.
Syslog at boot: Jul 23 08:57:47 raspberrypi snapserver[354]: Version 0.26.0, revision e30a9f33 Jul 23 08:57:47 raspberrypi snapserver[354]: Adding source: alsa://?name=Line_In&device=hw:CARD=CODEC,DEV=0 Jul 23 08:57:47 raspberrypi snapserver[354]: Settings file: "/var/lib/snapserver/server.json" Jul 23 08:57:47 raspberrypi snapserver[354]: Using HTTP host name: raspberrypi Jul 23 08:57:47 raspberrypi snapserver[354]: Adding service 'Snapcast' Jul 23 08:57:47 raspberrypi snapserver[354]: PcmStream: Line_In, sampleFormat: 48000:16:2 Jul 23 08:57:47 raspberrypi snapserver[354]: Stream: {"fragment":"","host":"","path":"","query":{"chunk_ms":"20","codec":"flac","device":"hw:CARD=CODEC,DEV=0","name":"Line_In","sampleformat":"48000:16:2"},"raw":"alsa:///?chunk_ms=20&codec=flac&device=hw:CARD=CODEC,DEV=0&name=Line_In&sampleformat=48000:16:2","scheme":"alsa"} Jul 23 08:57:47 raspberrypi snapserver[354]: ALSA lib pcm_hw.c:1829:(_snd_pcm_hw_open) Invalid value for card Jul 23 08:57:47 raspberrypi snapserver[354]: Server::start: Can't open device 'hw:CARD=CODEC,DEV=0', error: No such device Jul 23 08:57:47 raspberrypi snapserver[354]: Exception: Can't open device 'hw:CARD=CODEC,DEV=0', error: No such device Jul 23 08:57:47 raspberrypi snapserver[354]: Snapserver terminated. Jul 23 08:57:47 raspberrypi systemd[1]: snapserver.service: Main process exited, code=exited, status=1/FAILURE Jul 23 08:57:47 raspberrypi systemd[1]: snapserver.service: Failed with result 'exit-code'. Jul 23 08:57:47 raspberrypi systemd[1]: snapserver.service: Scheduled restart job, restart counter is at 4.
But then if I log in and start it manually pi@raspberrypi:~ $ service snapserver start Then all works normally.
Jul 23 09:25:23 raspberrypi snapserver[2180]: Version 0.26.0, revision e30a9f33 Jul 23 09:25:23 raspberrypi snapserver[2180]: Adding source: alsa://?name=Line_In&device=hw:CARD=CODEC,DEV=0 Jul 23 09:25:23 raspberrypi snapserver[2180]: Settings file: "/var/lib/snapserver/server.json" Jul 23 09:25:23 raspberrypi snapserver[2180]: Using HTTP host name: raspberrypi Jul 23 09:25:23 raspberrypi snapserver[2180]: Adding service 'Snapcast' Jul 23 09:25:23 raspberrypi snapserver[2180]: PcmStream: Line_In, sampleFormat: 48000:16:2 Jul 23 09:25:23 raspberrypi snapserver[2180]: Stream: {"fragment":"","host":"","path":"","query":{"chunk_ms":"20","codec":"flac","device":"hw:CARD=CODEC,DEV=0","name":"Line_In","sampleformat":"48000:16:2"},"raw":"alsa:///?chunk_ms=20&codec=flac&device=hw:CARD=CODEC,DEV=0&name=Line_In&sampleformat=48000:16:2","scheme":"alsa"} Jul 23 09:25:23 raspberrypi snapserver[2180]: Init - compression level: 2 Jul 23 09:25:23 raspberrypi snapserver[2180]: No data availabale, playing silence. Jul 23 09:25:23 raspberrypi snapserver[2180]: Creating TCP acceptor for address: 0.0.0.0, port: 1705 Jul 23 09:25:23 raspberrypi snapserver[2180]: Creating HTTP acceptor for address: 0.0.0.0, port: 1780 Jul 23 09:25:23 raspberrypi snapserver[2180]: Creating stream acceptor for address: 0.0.0.0, port: 1704 Jul 23 09:25:23 raspberrypi snapserver[2180]: Number of threads: 2, hw threads: 1 Jul 23 09:25:23 raspberrypi snapserver[2180]: StreamServer::NewConnection: 192.168.1.5 Jul 23 09:25:23 raspberrypi snapserver[2180]: State changed: Line_In, state: idle => playing
i think you need to use other device-ids because alsa is initialized differently for users and system-accounts. i am affected on raspberrypi-os. to fix it i altered a script to output the alsa-device list to systlog on boot and used this as reference.
Maybe Snapserver is started before audio is initialized. Please try to add After=sound.target
to the systemd unit file /lib/systemd/system/snapserver.service
:
it should look like this:
[Unit]
Description=Snapcast server
Documentation=man:snapserver(1)
Wants=avahi-daemon.service
After=network-online.target time-sync.target avahi-daemon.service
---
Change it to:
[Unit]
Description=Snapcast server
Documentation=man:snapserver(1)
Wants=avahi-daemon.service
After=network-online.target time-sync.target avahi-daemon.service sound.target
...