From 5c52670421d94e72f011340bbde9300184a9dba8 Mon Sep 17 00:00:00 2001 From: Jonas Holmberg Date: Mon, 17 Aug 2020 10:48:55 +0200 Subject: [PATCH] systemd: Add system service and socket Add system service and socket in addition to the user service and socket. The system service is started as pipewire user and group and clients need to be in the pipewire group to be able to connect. --- meson_options.txt | 8 ++++++ src/daemon/systemd/meson.build | 7 ++++- src/daemon/systemd/system/meson.build | 12 +++++++++ src/daemon/systemd/system/pipewire.service.in | 27 +++++++++++++++++++ src/daemon/systemd/system/pipewire.socket | 13 +++++++++ 5 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 src/daemon/systemd/system/meson.build create mode 100644 src/daemon/systemd/system/pipewire.service.in create mode 100644 src/daemon/systemd/system/pipewire.socket diff --git a/meson_options.txt b/meson_options.txt index f03033c3e..4b6723f2b 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -26,6 +26,14 @@ option('systemd', description: 'Enable systemd integration', type: 'boolean', value: true) +option('systemd-system-service', + description: 'Install systemd system service file', + type: 'boolean', + value: false) +option('systemd-user-service', + description: 'Install systemd user service file', + type: 'boolean', + value: true) option('pipewire-alsa', description: 'Enable pipewire-alsa integration', type: 'boolean', diff --git a/src/daemon/systemd/meson.build b/src/daemon/systemd/meson.build index 45f23466c..8051b0f5b 100644 --- a/src/daemon/systemd/meson.build +++ b/src/daemon/systemd/meson.build @@ -1 +1,6 @@ -subdir('user') +if get_option('systemd-system-service') + subdir('system') +endif +if get_option('systemd-user-service') + subdir('user') +endif diff --git a/src/daemon/systemd/system/meson.build b/src/daemon/systemd/system/meson.build new file mode 100644 index 000000000..7bd4f946d --- /dev/null +++ b/src/daemon/systemd/system/meson.build @@ -0,0 +1,12 @@ +systemd_system_services_dir = systemd.get_pkgconfig_variable('systemdsystemunitdir', define_variable : [ 'prefix', prefix]) + +install_data(sources : 'pipewire.socket', + install_dir : systemd_system_services_dir) + +systemd_config = configuration_data() +systemd_config.set('PW_BINARY', join_paths(pipewire_bindir, 'pipewire')) + +configure_file(input : 'pipewire.service.in', + output : 'pipewire.service', + configuration : systemd_config, + install_dir : systemd_system_services_dir) diff --git a/src/daemon/systemd/system/pipewire.service.in b/src/daemon/systemd/system/pipewire.service.in new file mode 100644 index 000000000..543dc7a60 --- /dev/null +++ b/src/daemon/systemd/system/pipewire.service.in @@ -0,0 +1,27 @@ +[Unit] +Description=Multimedia Service + +# We require pipewire.socket to be active before starting the daemon, because +# while it is possible to use the service without the socket, it is not clear +# why it would be desirable. +# +# Installing pipewire and doing `systemctl start pipewire` will not get the +# socket started, which might be confusing and problematic if the server is to +# be restarted later on, as the client autospawn feature might kick in. Also, a +# start of the socket unit will fail, adding to the confusion. +# +# After=pipewire.socket is not needed, as it is already implicit in the +# socket-service relationship, see systemd.socket(5). +Requires=pipewire.socket + +[Service] +Type=simple +ExecStart=@PW_BINARY@ +Restart=on-failure +RuntimeDirectory=pipewire +User=pipewire +Environment=PIPEWIRE_RUNTIME_DIR=%t/pipewire + +[Install] +Also=pipewire.socket +WantedBy=default.target diff --git a/src/daemon/systemd/system/pipewire.socket b/src/daemon/systemd/system/pipewire.socket new file mode 100644 index 000000000..7c9556c83 --- /dev/null +++ b/src/daemon/systemd/system/pipewire.socket @@ -0,0 +1,13 @@ +[Unit] +Description=Multimedia System + +[Socket] +Priority=6 +Backlog=5 +ListenStream=%t/pipewire/pipewire-0 +SocketUser=pipewire +SocketGroup=pipewire +SocketMode=0660 + +[Install] +WantedBy=sockets.target