Skip to main content
Topic: Pipewire services (Read 2322 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Pipewire services

I'd like to try to use pipewire, pipewire-pulse and wireplumber services.
Then you could use them as root or change the owner of the processes, maybe ?

Code: [Select]
#!/sbin/openrc-run
# Copyright 2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

PIPEWIRE_RUNTIME_DIR="/tmp/pipewire"
name="pipewire daemon"
description="Low-latency audio/video router and processor"
command=/usr/bin/pipewire
command_args="${pipewire_args}"

depend() {
        use alsasound
}

start_pre() {
    if [[ ! -e ${PIPEWIRE_RUNTIME_DIR} ]]; then
                mkdir ${PIPEWIRE_RUNTIME_DIR}
        fi
        export PIPEWIRE_RUNTIME_DIR
}


With that:
Code: [Select]
rc-service pipewire start
pipewire          | * Caching service dependencies ...                                                                                                       [ ok ]
pipewire          | * Starting pipewire daemon ...
pipewire          |[E][03712.099859] spa.dbus     | [          dbus.c:  349 impl_connection_get()] Failed to connect to session bus: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
pipewire          |[E][03712.099913] mod.portal   | [ module-portal.c:  346 pipewire__module_init()] Failed to connect to session bus: Input/output error
pipewire          |[W][03712.100570] pw.context   | [       context.c: 1391 pw_context_register_export_type()] context 0x557be6509d00: duplicate export type PipeWire:Interface:Metadata
pipewire          |[E][03712.100581] pw.conf      | [          conf.c:  594 load_module()] 0x557be6509d00: could not load mandatory module "libpipewire-module-metadata": File exists
pipewire          |[E][03712.100868] default      | [      pipewire.c:  125 main()] failed to create context: File exists
pipewire          | * start-stop-daemon: failed to start `/usr/bin/pipewire'
pipewire          | * Failed to start pipewire daemon                                                                                                        [ !! ]
pipewire          | * ERROR: pipewire failed to start

How can I fix pipewire service so that I can eventually use the others?

Re: Pipewire services

Reply #1
Me and another guy (forgot his name) tried this before, Pipewire needs the local user's dbus address which for now cannot be easily obtainable by root even when you run pipewire from root with sudo -u/su -s and even if you prefix it with dbus-launch. Of course be free to hack it for your personal use, i've got it to start but was unstable.

The preferred method for starting pipewire right now is through the DE's session manager, through xinitrc, through the wrapper program of Gentoo, or through s6 or Dinit user services (OpenRC only launches stuff as root)

Re: Pipewire services

Reply #2
How did you get it to work?

Re: Pipewire services

Reply #3
Along the lines of:

Quote
su -s /bin/sh -c "env XDG_RUNTIME_DIR=/run/user/[uid, usually 1000] dbus-launch pipewire" [name of user] [name of his group, usually the same]; if you have stock pipewire.conf repeat the command 2 more times for pipewire-pulse and wireplumber, and at the end make sure to background them otherwise the service would hang (don't use PID's, only put "pkill pipewire" as a stop command if needed)

But again, if you really really want pipewire as a service, just use s6 or Dinit as a init, then you have proper user services and this hack will not be needed.

If you use the LXQt desktop it also has user-facing service management independent of init (I use OpenRC too on the main pc). That's how I start pipewire right now. https://lxqt-project.org/blog/2022/09/20/about-modules-in-lxqt/

Re: Pipewire services

Reply #4
I'd like to test it.
I am using bspwm while I am trying to use wayland WMs, a pain thanks to nvdia.
So I log out a lot and sometimes I need to restart PW and others.

What it's working fine for me it is to use this in ~/.config/bspwm/bspwmrc:
Code: [Select]
pkill pipewire &
pkill pipewire-pulse &
pkill wireplumber &
#other things to leave some time
#just "pipewire &" should be fine
pgrep -x pipewire > /dev/null || { pipewire & }
pgrep -x pipewire-pulse > /dev/null || { pipewire-pulse & }
pgrep -x wireplumber > /dev/null || { wireplumber & }

Can you share the service file?
It is stuck at starting, I have "command_background=yes".

Re: Pipewire services

Reply #5
Why not start pipewire at session start, and set its config file to start wireplumber and pipewire-pulse ?

artist

Re: Pipewire services

Reply #6
Why not start pipewire at session start, and set its config file to start wireplumber and pipewire-pulse ?

artist
I'd like to try to make an openrc service.
Does anyone have the Gentoo wrapper?

If you never log out that could be good but I find better to also kill it at session start (see previous post).
Otherwise sometimes you will have to manually do that, if you log out often.

Re: Pipewire services

Reply #7
Otherwise sometimes you will have to manually do that, if you log out often.
Sometimes I've had to remove (and insert) audio modules to get pipewire back after a pipewire crash.
It's flaky. It loves leaving zombie processes behind.
Maybe what you want to do (root started openrc service running as a particular user) is achievable but don't expect it to work reliably between pipewire and/or kernel audio module versions.

From Gentoo
Quote
Warning
As of mid 2022, PipeWire is still in active development. Some things may still not be fully integrated, tested, or implemented, and there may be large changes. It can work well for some, though the experience is not guaranteed to be perfect, free of issues, or bugs.
Take a look at their wiki. Good stuff relating to openrc + pipewire. https://wiki.gentoo.org/wiki/PipeWire

The wrapper I think you are asking about ?
https://gitweb.gentoo.org/repo/gentoo.git/tree/media-video/pipewire/files/gentoo-pipewire-launcher.in
Take note that the script states user dbus must be running before pipewire. On my system that used to a prerequisite for a working pipewire but doesn't seem to be atm ? IDK ?


Re: Pipewire services

Reply #8
Quote
Code: [Select]
pkill pipewire &
pkill pipewire-pulse &
pkill wireplumber &
#other things to leave some time

Just remove & from your pkill invocations. Then you can launch pipewire confident that it was actually stopped, as the script will only continue once pkill's done its job.

That's essentially what the Gentoo wrapper does. And no, it's not designed to be started by OpenRC.

Quote
If you never log out that could be good but I find better to also kill it at session start (see previous post).
Otherwise sometimes you will have to manually do that, if you log out often.

Look into Slackware's daemon program.

The --bind option makes it kill the process on logout for you.




Honestly, just give up on using OpenRC, it won't solve your problem and will just bring new ones. Follow @Hitman and @Artist's advice.

Re: Pipewire services

Reply #9
I am now using dinit, with an adapted version of the Gentoo wrapper.
I will test user services, I am new to dinit and to Artix too I will try some other init maybe.

I wanted to experiment openrc user services besides starting PW.
That wrapper is pretty useful at least for runit and openrc.
I think it should be packaged.

Thank you all.

Re: Pipewire services

Reply #10
I used this https://github.com/Xynonners/dinit-userservd to get pipewire, pipewire-pulse, and wireplumber managed by dinit, so far no issues.  Pretty easy to set up I think from what I remember, just enable his dinit-userservd and then follow the link to the actual user-service files (there's only pipewire related ones in this repository) https://github.com/Xynonners/dinit-userservd-services.

Not sure if this solution will help with your logging in / logging out issues but for my less finicky setup it's rock solid.