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

by Rudd-O published 2009/07/13 13:30:00 GMT+0, last modified 2016-08-19T14:29:38+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 to 24, the latest Ubuntu versions, and earlier versions of Ubuntu as well.

You will probably lose the ability to pair up Bluetooth audio gear, and lose autotunneling capabilities to networked audio devices through Zeroconf, but hey, you get what you pay for ;-)

The documentation warns that 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.  Consult the manual pages that ship with PulseAudio for more information.

Starting up PulseAudio on boot

For modern systems using systemd

Put this text in the file /etc/systemd/system/pulseaudio.service:

Description=PulseAudio system server
Type=notify Exec=pulseaudio --daemonize=no --system --realtime --log-target=journal

This unit file is a straightforward method that starts PulseAudio and makes sure it is running.

Now enable and start this unit file by running the following commands:

systemctl --system enable pulseaudio.service
systemctl --system start pulseaudio.service

It should be running now. You can check the status of the service with the command:

systemctl --system status pulseaudio.service

For legacy systems using Upstart

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

Now it's time to kill your existing PulseAudio instances that run as your user. Find the pulseaudio process running as your own user name (not as the user pulse) and kill it. Combined with the configuration change you just enacted, this will prevent PulseAudio from starting up again as your regular user.

Finally, kill the PulseAudio instance running as the user pulse. This will cause the system-wide PulseAudio server to restart and discover the sound hardware devices that might have been hogged by the PulseAudio server running as your own user.

Allowing users access to the audio service

Add every user that is allowed to use the audio device to the group pulse-access. You usually accomplish this by listing those users as secondary group members in the file /etc/group. Usually it is enough to add the user to the group in question and you can immediately begin using the server.

Testing that PulseAudio is in fact working

If you don't have the program paman installed, then install it now.

Now launch paman (which appears in your menu as the PulseAudio Manager). If your settings have been configured properly, then paman should show you right there that the User Name is pulse. You can check the Devices tab to confirm that PulseAudio is in fact seeing your sound hardware devices.

At this point, newly-started applications will know to use the system-wide PulseAudio server. The only program I have not been able to make work with this configuration is the program pacmd. Apparently pacmd ignores the default-server directive.

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

In older distributions, 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.

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.