Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
systemd definition for pulseaudio in system-mode (example for archlinux). The pulseaudio developers explicitly recommend to NOT run pulseaudo system-mode!
# systemd service spec for pulseaudio running in system mode -- not recommended though!
# on arch, put it under /etc/systemd/system/pulseaudio.service
# start with: systemctl start pulseaudio.service
# enable on boot: systemctl enable pulseaudio.service
[Unit]
Description=Pulseaudio sound server
After=avahi-daemon.service network.target
[Service]
ExecStart=/usr/bin/pulseaudio --system --disallow-exit --disallow-module-loading
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
@Jille

This comment has been minimized.

Copy link

@Jille Jille commented Jul 2, 2017

You should add --daemonize=no.

@rodrigoaguilera

This comment has been minimized.

Copy link

@rodrigoaguilera rodrigoaguilera commented Dec 8, 2017

I use pulseaudio over a network and I need to wait for the interface to be up. I can't seem to be able to do it with systemd so instead I restart the pulseaudio service when it fails to start at boot

    [Service]
    Restart=always
    RestartSec=30
@ashutoshtripathi123

This comment has been minimized.

Copy link

@ashutoshtripathi123 ashutoshtripathi123 commented Apr 25, 2018

Thanks a million. This is exactly what I was looking for. The pulseaudio stopped working on our system after the introduction of systemd, and I needed the place where I can include the flag --system in systemd for pulseaudio.

@bxabi

This comment has been minimized.

Copy link

@bxabi bxabi commented Sep 12, 2018

Pulseadio configured correctly forks and drops root privileges, and runs under the user pulse.
If the service is not adapted, pulseaudio simply exits.

Type=forking
ExecStart=/usr/bin/pulseaudio --realtime --no-cpu-limit --system --disallow-exit --daemon

https://gist.github.com/bxabi/5295beadbfce8f4e697733e7244c4402#file-pulseaudio-service-L10

@janvda

This comment has been minimized.

Copy link

@janvda janvda commented Dec 12, 2020

I can't get it working on my intel-nuc running CentOs 8.
strange thing is that I don't have a problem when running the command directly from the command line as user root.

[root@nuc-jan system]# systemctl start pulseaudio
[root@nuc-jan system]# systemctl status pulseaudio
  pulseaudio.service - Pulseaudio sound server
   Loaded: loaded (/etc/systemd/system/pulseaudio.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Sat 2020-12-12 09:53:25 CET; 9s ago
  Process: 2323785 ExecStart=/usr/bin/pulseaudio -vvvv --system --disallow-exit --disallow-module-loading (code=exited, status=1/FAILURE)
 Main PID: 2323785 (code=exited, status=1/FAILURE)

Dec 12 09:53:25 nuc-jan.borsbeek systemd[1]: Started Pulseaudio sound server.
Dec 12 09:53:25 nuc-jan.borsbeek pulseaudio[2323785]: N: [pulseaudio] main.c: Running in system mode, forcibly disabling SHM mode.
Dec 12 09:53:25 nuc-jan.borsbeek pulseaudio[2323785]: N: [pulseaudio] main.c: Running in system mode, forcibly disabling exit idle time.
Dec 12 09:53:25 nuc-jan.borsbeek pulseaudio[2323785]: D: [pulseaudio] core-rtclock.c: Timer slack is set to 50 us.
Dec 12 09:53:25 nuc-jan.borsbeek pulseaudio[2323785]: D: [pulseaudio] core-util.c: setpriority() worked.
Dec 12 09:53:25 nuc-jan.borsbeek pulseaudio[2323785]: I: [pulseaudio] core-util.c: Successfully gained nice level -11.
Dec 12 09:53:25 nuc-jan.borsbeek pulseaudio[2323785]: I: [pulseaudio] main.c: Found user 'pulse' (UID 171) and group 'pulse' (GID 171).
Dec 12 09:53:25 nuc-jan.borsbeek pulseaudio[2323785]: E: [pulseaudio] main.c: Failed to create '/var/lib/pulse': Permission denied
Dec 12 09:53:25 nuc-jan.borsbeek systemd[1]: pulseaudio.service: Main process exited, code=exited, status=1/FAILURE
Dec 12 09:53:25 nuc-jan.borsbeek systemd[1]: pulseaudio.service: Failed with result 'exit-code'.
[root@nuc-jan system]#

Root cause (?):
pulseaudio executed with option --system will change its user from root to pulse : this change is failing when starting pulseaudio as systemd service (it works when starting from command line).

FYI this is what is written by pulseaudio in the log file when started by systemctl start pulseaudio:

N: [pulseaudio] main.c: Running in system mode, forcibly disabling SHM mode.
N: [pulseaudio] main.c: Running in system mode, forcibly disabling exit idle time.
D: [pulseaudio] core-rtclock.c: Timer slack is set to 50 us.
D: [pulseaudio] core-util.c: setpriority() worked.
I: [pulseaudio] core-util.c: Successfully gained nice level -11.
I: [pulseaudio] main.c: Found user 'pulse' (UID 171) and group 'pulse' (GID 171).
E: [pulseaudio] main.c: Failed to create '/var/lib/pulse': Permission denied

This is what is logged by pulseaudio when starting from command line as user root:

N: [pulseaudio] main.c: Running in system mode, forcibly disabling SHM mode.
N: [pulseaudio] main.c: Running in system mode, forcibly disabling exit idle time.
D: [pulseaudio] core-rtclock.c: Timer slack is set to 50 us.
D: [pulseaudio] core-util.c: setpriority() worked.
I: [pulseaudio] core-util.c: Successfully gained nice level -11.
I: [pulseaudio] main.c: Found user 'pulse' (UID 171) and group 'pulse' (GID 171).
I: [pulseaudio] main.c: Successfully changed user to "pulse".
I: [pulseaudio] main.c: This is PulseAudio 13.99.1-rebootstrapped
D: [pulseaudio] main.c: Compilation host: x86_64-redhat-linux-gnu
D: [pulseaudio] main.c: Compilation CFLAGS: -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -W -Wextra -Wno-long-long -Wno-overlength-strings -Wunsafe-loop-optimizations -Wundef -Wformat=2 -Wlogical-op -Wsign-compare -Wformat-security -Wmissing-include-dirs -Wformat-nonliteral -Wpointer-arith -Winit-self -Wdeclaration-after-statement -Wfloat-equal -Wmissing-prototypes -Wredundant-decls -Wmissing-declarations -Wmissing-noreturn -Wshadow -Wendif-labels -Wcast-align -Wstrict-aliasing -Wwrite-strings -Wno-unused-parameter -fno-common -fdiagnostics-show-option -fdiagnostics-color=auto
D: [pulseaudio] main.c: Running on host: Linux x86_64 4.18.0-240.1.1.el8_3.x86_64 #1 SMP Thu Nov 19 17:20:08 UTC 2020
D: [pulseaudio] main.c: Found 4 CPUs.
I: [pulseaudio] main.c: Page size is 4096 bytes
D: [pulseaudio] main.c: Compiled with Valgrind support: no
D: [pulseaudio] main.c: Running in valgrind mode: no
D: [pulseaudio] main.c: Running in VM: no
D: [pulseaudio] main.c: Running from build tree: no
D: [pulseaudio] main.c: Optimized build: yes
D: [pulseaudio] main.c: FASTPATH defined, only fast path asserts disabled.
I: [pulseaudio] main.c: Machine ID is cf39e64c11dd4d93b45e5727a01fd5e2.
I: [pulseaudio] main.c: Session ID is 15.
I: [pulseaudio] main.c: Using runtime directory /var/run/pulse.
I: [pulseaudio] main.c: Using state directory /var/lib/pulse.
I: [pulseaudio] main.c: Using modules directory /usr/lib64/pulse-13.99/modules.
I: [pulseaudio] main.c: Running in system mode: yes
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment