How to make PulseAudio run once at boot for all your users

by Rudd-O published 2009/07/13 13:25:00 GMT+0, last modified 2013-06-26T03:24:21+00:00
Running PulseAudio as a system-wide service has advantages -- you can play audio without having logged on, multiple users can play audio on the same audio gear, and music daemons like MPD won't fight for the audio device with PulseAudio. Here's how.

These instructions should work in Fedora 11, and probably Ubuntu as well.  You will probably lose the ability to pair up Bluetooth audo gear, like lose  autotunneling capabilities to networked audio devices through Zeroconf, but hey, you get what you pay for ;-)  I also hear there are security considerations stemming from the fact that users allowed access to PulseAudio may break something in it, but for home use it is probably going to be just fine.

Starting up PulseAudio on boot

Put this text in the file /etc/event.d/pulseaudio:

start on runlevel [2345]
stop on runlevel [016]

exec pulseaudio --system --realtime --log-target=syslog


description "PulseAudio system server"

pre-start script
	for a in `seq 60` ; do
		sleep 1
		killall -0 hald && killall -0 dbus-daemon && break
end script

post-start script
	( sleep 1 ; paplay /usr/share/sounds/login.wav ) &
end script

The text in italics is optional -- either don't include it, or replace it with something that will play a sound file confirming that PulseAudio has started.

As you can see, this is a straightforward script that waits until hald and D-Bus are active before starting PulseAudio (both are needed to get the hardware list), and then starts it up.

Setting up default client settings

Add these lines in the file /etc/pulse/client.conf:

default-server = /var/run/pulse/native
autospawn = no

Allowing users access to the audio service

Add every user that is allowed to use the audio device to the group pulse-access.

Allowing PulseAudio access to Bluetooth

In order to pair up with Bluetooth devices, you need to add the following text to the file /etc/dbus-1/system.d/pulse.conf:

<!DOCTYPE busconfig PUBLIC
 "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
	<policy user="root">
		<allow own="org.pulseaudio.Server"/>
                <allow send_destination="org.bluez"/>
                <allow send_interface="org.bluez.Manager"/>
	<policy user="pulse">
		<allow own="org.pulseaudio.Server"/>
                <allow send_destination="org.bluez"/>
                <allow send_interface="org.bluez.Manager"/>
	<policy context="default">
                <deny own="org.pulseaudio.Server"/>
                <deny send_destination="org.bluez"/>
                <deny send_interface="org.bluez.Manager"/>

Preventing PulseAudio from starting on graphical logon

A pesky program tries to start PulseAudio every time you log on, which may cause conflicts.  Prevent this by running the following command as root:

chmod -x /usr/bin/start-pulseaudio-x11

You may need to run this command whenever you upgrade your system and, in the course of the upgrade, PulseAudio itself is upgraded.

I've submitted a patch for PulseAudio that will render this step unnecessary soon, if it's accepted. It's logged as ticket 606 in the PulseAudio bug tracker.

That's it!

Close your session and reboot your machine.  PulseAudio should start on boot now, and all applications will be able to play sound, whether they are console or graphical applications, and without the need to actually log on beforehand.  In addition, if PulseAudio dies, it will be automatically restarted and you will hear a confirmatory sound (provided you actually put the italicized text with a command to play audio).