0

Long story short, I'm trying to setup PulseAudio to act as a loopback interface for a local music stream. However, I'm hitting a breaking point in getting it setup.

As I understand it, you cannot start pulseaudio in "non-system mode" without having an X server running, but seeing as the server is is headless this is not an option. So I began writing a cobbled together systemd script to start the daemon as a system-wide instance. This however fails for some inexplicable reason.

If I run the command that in in the systemd script, the system-wide pulse starts up just fine! However, if I run it from within the start script (eg. with systemctl start pulseaudio), it fails with Failed to create '/var/run/pulse': Permission denied. I can't for the life of me figure out how it would work for the same user in to different ways. I also tried replacing the start script with a ls /var/run/pulse. When the script is setup to run as "pulse", it prints nothing in the journal. However, if I wrap the whole call in a sudo -u pulse, it prints the contents of /var/run/pulse. When I wrap the pulse startup command in a sudo -u root, it just crashes with the same error.

[root@ian-primary ian]# ls -al /var/run/pulse
total 4
drwx------.  3 pulse pulse  80 Nov  5 23:10 .
drwxr-xr-x. 29 root  root  840 Nov  5 23:03 ..
drwxr-xr-x.  3 pulse pulse  60 Nov  5 23:04 .config
-rw-------.  1 pulse pulse  16 Nov  5 23:04 .esd_auth

[root@ian-primary ian]# sudo -u pulse ls -al /var/run/pulse
total 4
drwx------.  3 pulse pulse  80 Nov  5 23:10 .
drwxr-xr-x. 29 root  root  840 Nov  5 23:03 ..
drwxr-xr-x.  3 pulse pulse  60 Nov  5 23:04 .config
-rw-------.  1 pulse pulse  16 Nov  5 23:04 .esd_auth

Nov 06 13:56:02 ian-primary systemd[1]: Starting PulseAudio system server...
Nov 06 13:56:02 ian-primary pulseaudio[23251]: W: [pulseaudio] main.c: Running in system mode, but --disallow-exit not set.
Nov 06 13:56:02 ian-primary pulseaudio[23251]: W: [pulseaudio] main.c: Running in system mode, but --disallow-module-loading not set.
Nov 06 13:56:02 ian-primary pulseaudio[23251]: N: [pulseaudio] main.c: Running in system mode, forcibly disabling SHM mode.
Nov 06 13:56:02 ian-primary pulseaudio[23251]: N: [pulseaudio] main.c: Running in system mode, forcibly disabling exit idle time.
Nov 06 13:56:02 ian-primary pulseaudio[23253]: Timer slack is set to 50 us.
Nov 06 13:56:02 ian-primary pulseaudio[23253]: setpriority() worked.
Nov 06 13:56:02 ian-primary pulseaudio[23253]: Successfully gained nice level -11.
Nov 06 13:56:02 ian-primary pulseaudio[23253]: Found user 'pulse' (UID 171) and group 'pulse' (GID 171).
Nov 06 13:56:02 ian-primary pulseaudio[23253]: Home directory of user 'pulse' is not '/var/run/pulse', ignoring.
Nov 06 13:56:02 ian-primary pulseaudio[23251]: E: [pulseaudio] main.c: Daemon startup failed.
Nov 06 13:56:02 ian-primary pulseaudio[23253]: Failed to create '/var/run/pulse': Permission denied
Nov 06 13:56:02 ian-primary systemd[1]: pulseaudio.service: main process exited, code=exited, status=1/FAILURE
Nov 06 13:56:02 ian-primary systemd[1]: Failed to start PulseAudio system server.
Nov 06 13:56:02 ian-primary systemd[1]: Unit pulseaudio.service entered failed state.
Nov 06 13:56:02 ian-primary systemd[1]: pulseaudio.service failed.

[root@ian-primary ian]# /bin/pulseaudio -vvv --daemonize --system --realtime
W: [pulseaudio] main.c: Running in system mode, but --disallow-exit not set.
W: [pulseaudio] main.c: Running in system mode, but --disallow-module-loading not set.
N: [pulseaudio] main.c: Running in system mode, forcibly disabling SHM mode.
N: [pulseaudio] main.c: Running in system mode, forcibly disabling exit idle time.
I: [pulseaudio] main.c: Daemon startup successful.

[root@ian-primary ian]# cat /etc/systemd/system/pulseaudio.service
[Unit]
Description=PulseAudio system server

[Service]
Type=notify
Environment=PULSE_RUNTIME_PATH=/run/pulse

# ExecStart=/bin/printenv
# export PULSE_RUNTIME_PATH="/run/pulse"
ExecStart=/bin/pulseaudio -vvv --daemonize --system --realtime

[Install]
WantedBy=multi-user.target
0

This doesn't really explain the Failed to create '/var/run/pulse': Permission denied message, but there's one apparent issue in your configuration, which is that you're running PulseAudio with --daemonize from the systemd service unit, while systemd actually expects it to run in foreground. You should change that to --daemonize=no.

You might also want to explicitly list --disallow-exit and --disallow-module-loading as suggested from the log messages.

PulseAudio is also complaining that user pulse's home directory is not /var/run/pulse, as it seems to expect that, you might want to update the system account to reflect that.

For further research, you might want to look at this article for more details and instructions on running a system-wide instance of PulseAudio, and also this page from the PulseAudio wiki (including some references on why you would not want to run PulseAudio as a system-wide service.)

  • My working theory at the time was that pulse wasn't understanding the symlink from /var/run to /run so I had adjusted the home directory of the pulse user to /run. This however did not resolve the issue. I also tried with those options in there, and it didn't seem to do anything. – duper51 Nov 7 '18 at 1:03
  • The symlink is there so applications using the /var/run paths can run unmodified. I suggest you just use /var/run paths everywhere. (Right now you have a mix of both!) – filbranden Nov 7 '18 at 1:08
  • The fact is it tries to make /var/run/pulse even though it exists and by all rights should be able to see that it does. /var/run/pulse -> /run/pulse – duper51 Nov 7 '18 at 1:23
  • Is it possible this is SELinux related? Do you have it enabled? Do you have messages about AVC in your logs? – filbranden Nov 7 '18 at 2:52
  • In any case, the other problems mentioned are issues you'll have to address, so I suggest you start with those, see if it's still not working and then we can look at what's next... – filbranden Nov 7 '18 at 2:52
0

You can try putting pulseaudio.service with --user in a shell script to start it. Now run the start script inside screen as a normal user. Then detach the screen and logout. The pulseaudio server continues as if it were headless.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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