6

I want to run Pulseaudio system wide, on a headless CentOS 7 server. Pulseaudio works great if I startx but in text mode (runlevel 3 equivalent) pulse audio clients fail.

So I created a systemd service file:

[Unit]
Description=PulseAudio Daemon

[Install]
WantedBy=multi-user.target

[Service]
Type=simple
PrivateTmp=true
ExecStart=/usr/bin/pulseaudio --system --realtime --disallow-exit --no-cpu-limit 

which starts, but I see the following in journalctl:

Jan 19 13:31:47 lserver.mydomain pulseaudio[2523]: W: [pulseaudio] main.c: Running in system mode, but --disallow-module-loading not set!
Jan 19 13:31:47 lserver.mydomain pulseaudio[2523]: N: [pulseaudio] main.c: Running in system mode, forcibly disabling SHM mode!
Jan 19 13:31:47 lserver.mydomain pulseaudio[2523]: N: [pulseaudio] main.c: Running in system mode, forcibly disabling exit idle time!
Jan 19 13:31:47 lserver.mydomain pulseaudio[2523]: W: [pulseaudio] main.c: OK, so you are running PA in system mode. Please note that you most likely shouldn't be doing that.
Jan 19 13:31:47 lserver.mydomain pulseaudio[2523]: W: [pulseaudio] main.c: If you do it nonetheless then it's your own fault if things don't work as expected.
Jan 19 13:31:47 lserver.mydomain pulseaudio[2523]: W: [pulseaudio] main.c: Please read http://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/WhatIsWrongWithSystemWide/ for an explanation why system mode is usually a bad idea.
Jan 19 13:31:48 lserver.mydomain pulseaudio[2523]: N: [pulseaudio] alsa-util.c: Disabling timer-based scheduling because running inside a VM.
Jan 19 13:31:48 lserver.mydomain pulseaudio[2523]: N: [pulseaudio] alsa-util.c: Disabling timer-based scheduling because running inside a VM.
Jan 19 13:31:48 lserver.mydomain pulseaudio[2523]: W: [pulseaudio] authkey.c: Failed to open cookie file '/var/run/pulse/.config/pulse/cookie': No such file or directory
Jan 19 13:31:48 lserver.mydomain pulseaudio[2523]: W: [pulseaudio] authkey.c: Failed to load authentication key '/var/run/pulse/.config/pulse/cookie': No such file or directory
Jan 19 13:31:48 lserver.mydomain pulseaudio[2523]: W: [pulseaudio] authkey.c: Failed to open cookie file '/var/run/pulse/.pulse-cookie': No such file or directory
Jan 19 13:31:48 lserver.mydomain pulseaudio[2523]: W: [pulseaudio] authkey.c: Failed to load authentication key '/var/run/pulse/.pulse-cookie': No such file or directory
Jan 19 13:31:48 lserver.mydomain systemd[1]: Got message type=signal sender=org.freedesktop.DBus destination=n/a object=/org/freedesktop/DBus interface=org.freedesktop.DBus member=NameOwnerChanged cookie=56 reply_cookie=0 error=n/a
Jan 19 13:31:48 lserver.mydomain systemd-logind[575]: Got message type=signal sender=org.freedesktop.DBus destination=n/a object=/org/freedesktop/DBus interface=org.freedesktop.DBus member=NameOwnerChanged cookie=56 reply_cookie=0 error=n/a
Jan 19 13:31:48 lserver.mydomain systemd-logind[575]: Got message type=signal sender=org.freedesktop.DBus destination=n/a object=/org/freedesktop/DBus interface=org.freedesktop.DBus member=NameOwnerChanged cookie=57 reply_cookie=0 error=n/a
Jan 19 13:31:48 lserver.mydomain systemd[1]: Got message type=signal sender=org.freedesktop.DBus destination=n/a object=/org/freedesktop/DBus interface=org.freedesktop.DBus member=NameOwnerChanged cookie=57 reply_cookie=0 error=n/a

and attempts to access audio fail:

speaker-test 1.1.1

Playback device is default
Stream parameters are 48000Hz, S16_LE, 1 channels
Using 16 octaves of pink noise
ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Access denied

Playback open error: -111,Connection refused

And after speaker-test the log shows:

Jan 19 14:06:39 lserver.ocg.ca pulseaudio[2795]: W: [pulseaudio] protocol-native.c: Denied access to client with invalid authentication data.

User root is added to the 'audio' group. And speaker-test is being run as root. Can someone suggest how to fix this?

  • That posting is how to run under user - not the same as this question: Pulse has to run as system – TSG Jan 19 '17 at 19:12
  • I changed permissions on /var/run/pulse/.config/pulse/cookie to 550 and now on service start the cookie file/authentication error is gone. But still the denied message exists on running speaker-test – TSG Jan 19 '17 at 19:38
8

After some experimentation I found that modifying /etc/pulse/system.pa to permit anonymous:

load-module module-native-protocol-unix auth-anonymous=1

The audio now plays fine. Hope this helps others needing system mode pulse

  • Valid hack (+1). That will run /usr/bin/pactl load-module (...) which is what the default xinitrc (or gnome/kde equivalent) seems to be doing. It should work, but asking the user to run this instead with /usr/bin/pactl load-module module-native-protocol-unix (without annonymous-auth) should be better since it prevents remote access (that may be possible if you use a network socket instead of a unix socket for commonication). On the other hand you could also install X11 libs and load module-x11-publish, it does not need Xorg running. Disclaimer didn't test it though. – grochmal Jan 20 '17 at 0:01
0

Included in your output is this feedback about running PulseAudio as a system user:

Please read http://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/WhatIsWrongWithSystemWide/ for an explanation why system mode is usually a bad idea.

The alternative is run PulseAudio as the user you login as. How to do that is a question that has already been answered.

  • 1
    This is running headless on a server, no user login. Multiple processes may output sound simultaneously. Already saw that link, and it indicates this situation is appropriate to run under system. So question is ok – TSG Jan 19 '17 at 19:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.