[aur-general] Sound in systemd service

David Runge dave at sleepmap.de
Wed Jan 2 23:14:18 UTC 2019


Hi!

TL;DR: Don't. Use what the package provides and start it as a systemd
user service!

On 2019-01-02 00:56:24 (+0100), NicoHood wrote:
> I currently try to create a system-wide spotifyd service that can play
> music from a dedicated user/group. I used the spotifyd package from AUR
> as a base:
> https://aur.archlinux.org/packages/spotifyd/
> 
> I added a user directory for the user and added it to the audio group:
> u spotifyd - "Spotify daemon user" /var/lib/spotifyd
> m spotifyd audio
That's not a good idea.

> The directory is created like this:
> d /var/lib/spotifyd 0750 spotifyd spotifyd -
That also is unneeded.

> I've added to the system service to start with a config file in
> /etc/sptoifyd.conf and start with:
> User=spotifyd
> Group=spotifyd
Also pointless.

> Now the service is running fine in the background, I can select it in
> spotify. But no sound will play. I am also running a gnome desktop
> environment with pulseaudio on the machine. And I dont know how to get
> audio working within this service. The software supports alsa backend
> and pulseaudio backend, but none of them seem to give me a sound.
Not sure how to operate multiple pulseaudio sinks of multiple users to
work together. However, ALSA will only allow to be accessed by *one*
application/mixer/whatever.

> If I run locally, I get:
> $ sudo -u spotifyd -g spotifyd /usr/bin/spotifyd --no-daemon --config
> /etc/spotifyd.conf
> 
> ```
> No protocol specified
> xcb_connection_has_error() returned true
> ALSA lib pcm_dmix.c:1099:(snd_pcm_dmix_open) unable to open slave
> 00:42:24 [ERROR] Alsa error PCM open -2
> 00:42:24 [ERROR] Could not start audio: Alsa error: PCM open failed
> ```
AFAICS this is because your user session with activated pulseaudio
already grabs the ALSA device. There can only be one client.
Additionally: Arch actually doesn't require being in the audio group and
might be more in the way than anything else (it's also not required for
your own user!):
https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/PerfectSetup/

> This does not happen with my local user, even with `sudo -u nicohood`.
Well, if you have a user session with that user, pulseaudio will have
already grabbed the device.
Running notifyd with sudo -u (see `man sudo`) roughly equals just
running directly as your user.

> Using a more simpler command gives me the same problem:
> $ sudo -u spotifyd -g spotifyd aplay
> /usr/share/sounds/alsa/Front_Center.wav No protocol specified
> xcb_connection_has_error() returned true
> ALSA lib pcm_dmix.c:1099:(snd_pcm_dmix_open) unable to open slave
> aplay: main:828: audio open error: No such file or directory
Same problem as above.

> Can anyone give me a hint how to get audio running with this separated
> user/service?
Start the user service with your session (running spotifyd as your user)
and use the pulseaudio backend to not use ALSA directly and block your
device for other applications.

That's btw. also what upstream intends:
https://github.com/Spotifyd/spotifyd#running-as-a-systemd-service
And it's also how the packager installs it:
https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=spotifyd#n35

Additionally:

If it was Tidal, you could use mpd:
https://www.musicpd.org/doc/html/plugins.html#tidal
While looking at mpd, I realized, that the mpd user is in the audio
group... and I'm not sure, but this might actually break fast user
switching and should probably be removed.

If it had a JACK backend, you could use $JACK_PROMISCUOUS_MODE to access
a local jackd with multiple clients (from different users).

Best,
David

P.S.: We now have the arch-proaudio mailing list, where one can ask
about these types of setups/ideas.

-- 
https://sleepmap.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.archlinux.org/pipermail/aur-general/attachments/20190103/c68b662d/attachment.asc>


More information about the aur-general mailing list