Pulseaudio "Connection refused!"

I am trying to get Libretime 4 running on a new server (not in a container). Everything is working, except for system audio output, which I need.
I’ve tried the following so far:

  • Enabled system audio in the config file, with “pulseaudio” as the kind.
  • Verified that pulseaudio is working with my sound card by playing a file from the command line with aplay.
  • Added the libretime and liquidsoap users to the pulse and pulse-access groups.
  • Found the name of the audio device using pacmd list-sinks and added it to the device field in the config file.
    No matter what I do though, liquidsoap just keeps reporting this error:
[clock.wallclock_pulse:2] Error when starting output pulseaudio:1: Pulseaudio error: Connection refused!
[clock.wallclock_pulse:3] Raised by primitive operation at file "pulseaudio.ml" (inlined), line 47, characters 6-67
[clock.wallclock_pulse:3] Called from file "io/pulseaudio_io.ml", line 82, characters 10-120
[clock.wallclock_pulse:3] Called from file "tools/start_stop.ml", line 108, characters 8-18
[clock.wallclock_pulse:3] Called from file "clock.ml", line 245, characters 20-38

Just updating this as I was eventually able to get pulseaudio working.
First I had to modify /etc/pulse/daemon.conf to enable ‘daemonize’ and ‘system-instance’

daemonize = yes
system-instance = yes

After rebooting I found that I could get audio working from libretime by manually starting pulseaudio with:

# sudo pulseaudio

So then I created an init script to automatically start pulseaudio on launch:
/etc/init.d/startpulse

#!/bin/sh
pulseaudio

Then

# sudo chmod +x /etc/init.d/startpulse
# sudo ln -s /etc/init.d/startpulse /etc/rc3.d/S01startpulse

I don’t know if this solution was optimal, or why it was necessary, but it worked. I think maybe it has something to do with Libretime not having a ‘real’ user, but I’m not sure.