How to make PulseAudio run once at boot for all your users
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 respawn description "PulseAudio system server" pre-start script for a in `seq 60` ; do sleep 1 killall -0 hald && killall -0 dbus-daemon && break done 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"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<policy user="root">
<allow own="org.pulseaudio.Server"/>
<allow send_destination="org.bluez"/>
<allow send_interface="org.bluez.Manager"/>
</policy>
<policy user="pulse">
<allow own="org.pulseaudio.Server"/>
<allow send_destination="org.bluez"/>
<allow send_interface="org.bluez.Manager"/>
</policy>
<policy context="default">
<deny own="org.pulseaudio.Server"/>
<deny send_destination="org.bluez"/>
<deny send_interface="org.bluez.Manager"/>
</policy>
</busconfig>
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).


Doesn't work
First of all there was no audio before logging in. Second, the audio was jerky and grainy (as if I had sand on my speakers) during the first few minutes of play. Third and worst of all, after some short time (never more than 8 minutes) the daemon would die and terminate all audio streams currently running; yes, it is immediately restarted, but then I have to restart all programs which were playing audio before - such as Xine.
So I just undid all of your changes (except that the users remained in the group pulse-access), and those problems have disappeared from PA.