[aur-general] Sound in systemd service
Hi, 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 The directory is created like this: d /var/lib/spotifyd 0750 spotifyd spotifyd - I've added to the system service to start with a config file in /etc/sptoifyd.conf and start with: User=spotifyd Group=spotifyd 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. The spotifyd config looks like this: $ cat /etc/spotifyd.conf [global] #username = USER #password = PASS #backend = alsa #device = alsa_audio_device # Given by `aplay -L` #mixer = PCM #volume-control = alsa # or alsa_linear, or softvol #onevent = command_run_on_playback_event device_name = Nico_Spotifyd # Cannot contain spaces #bitrate = 96|160|320 #cache_path = cache_directory #volume-normalisation = true #normalisation-pregain = -10 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 ``` This does not happen with my local user, even with `sudo -u nicohood`. 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 Can anyone give me a hint how to get audio running with this separated user/service? ~Nico
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/Perf...
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
On Thu, 3 Jan 2019 00:14:18 +0100, David Runge wrote:
P.S.: We now have the arch-proaudio mailing list, where one can ask about these types of setups/ideas.
These type of setups/ideas is not related to pro-audio!
On 1/3/19 12:14 AM, David Runge wrote:
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/Perf...
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.
I understand the problem better now, thanks. I want to run it on a headless device where no user should be logged in. I try to avoid autologin, as it looks hacky to me. My problem was that I tested it on my desktop with a logged in user that has the master audio permission. And then the playback failed. BTW: This workaround worked, but is not what I really want to do: http://billauer.co.il/blog/2014/01/pa-multiple-users/ I guess the best idea is to run pulseaudio in system mode. I am aware that this is not adviced, but in this case it looks like the correct setup for a headless PC with no logged in user. I'd still create a spotifyd user with its own UID, so it is not run as root. About the audio group: I am not sure if it is required, I remember alsamixer did not work in some setups without the audio group. About the user directory of the service: I assume it does cache some tracks, so I gave it a user directory. Does anyone has a pulseaudio systemd service file for system mode? I've seen some online, but all differ a bit. I want to set it up properly with the correct options enabled. ~Nico
participants (3)
-
David Runge
-
NicoHood
-
Ralf Mardorf