Running pulseaudio system-wide with pacmd on Arch
While pulseaudio is, by default, run for each user session (socket-activated, or manually started with systemctl –user start pulseaudio), some scenarios can require having an always-running, system-wide pulseaudio instance. The official documentation on freedesktop.org describes how to achieve that and the drawbacks it implies.
Below are the instructions that worked for me on Arch (July 2017).
1. Create the systemd unit file
Put this in e.g. /usr/lib/systemd/system/pulseaudio.service
[Unit] Description=PulseAudio system server [Service] ExecStart=/usr/bin/pulseaudio --system --disallow-exit --log-target=journal #ExecStart=/usr/bin/pulseaudio --system --disallow-exit --disallow-module-loading --log-target=journal ExecReload=/bin/kill -HUP $MAINPID [Install] WantedBy=multi-user.target
2. Create a dbus policy file
Put this in /usr/share/dbus-1/system.d; note that a reboot is required (or you can also try systemctl restart dbus && systemctl restart polkit && systemctl restart systemd-logind) :
<?xml version="1.0"?> <!--*-nxml-*--> <!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> <busconfig> <policy group="pulse"> <allow own="org.pulseaudio.Server"/> </policy> <policy context="default"> <allow send_destination="org.pulseaudio.Server"/> <allow receive_sender="org.pulseaudio.Server"/> </policy> </busconfig>
3. Create the users and groups
Since the daemon will not be run by users anymore, it needs it’s own user and groups.
groupadd --system pulse groupadd --system pulse-access useradd --system -g pulse -G audio -d /var/run/pulse -m pulse usermod -G video,wheel,pulse-access myuser echo "default-server = /var/run/pulse/native" >> /etc/pulse/client.conf echo "autospawn = no" >> /etc/pulse/client.conf systemctl daemon-reload systemctl enable pulseaudio systemctl start pulseaudio
At this point, pulseaudio should work already (try gst-launch pulsesrc ! fakesink -v to check).
4. Enable –disallow-module-loading
The official documentation states: “If the system-wide mode is enabled it is advisable to disable module loading during runtime by passing –disallow-module-loading to the daemon, to inhibit the user from loading arbitrary modules with potentially vulnerable code into the daemon. However, this might break some modules like module-hal-detect which will load a sound driver module each time HAL signals that a new sound card became available in the system.”
I first tried to run with –disallow-module-loading, and the alsa configuration was messed up; even aplay -l or arecord -l were failing. The trick seems to be to add –disallow-module-loading only after a first successful use.
5. Disable –disallow-module-loading to use pacmd
This was the hardest to figure out: if you want pacmd to work, you cannot run pulseaudio with –disallow-module-loading (which is recommended by the official documentation), or you will get:
$ sudo PULSE_RUNTIME_PATH=/var/run/pulse -u pulse pacmd Daemon not responding.
As long as –disallow-module-loading is not in the ExecStart line of the systemd unit file, pacmd will work using:
sudo PULSE_RUNTIME_PATH=/var/run/pulse -u pulse pacmd
It is recommended, once the /etc/pulse/system.pa finalized, to re-add the –disallow-module-loading switch.
Seems to work pretty well. But ALSA clients no longer work. Seems that the ALSA clients snd_pcm_writei() calls never return.
Isn’t that because pulseaudio “steals” the alsa device from other clients ?