Skip to main content
Topic: mpd music daemon error when started as a user service (Read 925 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

mpd music daemon error when started as a user service

Hello.

I am trying to start the mpd music daemon from runit as a user service, but it seems there is some error in the configuration.

Let me elaborate a bit more .....

First of all, this is the kernel I am running:

Code: [Select]
❯ uname -r
6.1.10-artix1-1

I start the pipewire service also from runit as a user service, and the pipewire-pulse service and wireplumber service are started based on the configuration I have for the pipewire service.

Pipewire services are started successfully, and I can listen successfully to the audio coming from apps like browers, for instance.

The mpd daemon is also started successfully, but there is no audio coming from it, using different clients like mpc and ncmpcpp.

Code: [Select]
❯ sv status mpd
run: mpd: (pid 21306) 1024s; run: log: (pid 19258) 1481s

This how I am starting the daemon:

Code: [Select]
#!/bin/sh

# Wait for the PipeWire Pulse daemon to start.
/usr/bin/pgrep pipewire-pulse >/dev/null || exit 1

[ -r ./conf ] && . ./conf

exec mpd --no-daemon --stderr /home/localuser/.config/mpd/mpd.conf 2>&1

and this is how my pstree looks like after starting the mpd daemon via runit:


Code: [Select]
❯ pstree
runit─┬─at-spi-bus-laun─┬─dbus-daemon
      │                 └─2*[{at-spi-bus-laun}]
      ├─at-spi2-registr───2*[{at-spi2-registr}]
      ├─autostart.sh─┬─dwmblocks
      │              ├─nm-applet───4*[{nm-applet}]
      │              └─picom───2*[{picom}]
      ├─chrome_crashpad───{chrome_crashpad}
      ├─chrome_crashpad
      ├─2*[dbus-daemon]
      ├─2*[dbus-launch]
      ├─dunst───2*[{dunst}]
      ├─pipewire-pulse───{pipewire-pulse}
      ├─runsvdir─┬─6*[runsv───agetty]
      │          ├─runsv─┬─dbus-daemon
      │          │       └─svlogd
      │          ├─runsv───elogind
      │          ├─runsv─┬─runsvdir─┬─runsv─┬─cat
      │          │       │          │       └─emacs
      │          │       │          ├─runsv─┬─cat
      │          │       │          │       └─dbus-run-sessio─┬─dbus-daemon
      │          │       │          │                         └─pipewire───{pipewire}
      │          │       │          └─runsv─┬─mpd───12*[{mpd}]
      │          │       │                  └─svlogd
      │          │       └─svlogd
      │          ├─runsv───udevd
      │          ├─runsv───sddm─┬─Xorg───9*[{Xorg}]
      │          │              ├─sddm-helper───dwm─┬─2*[alacritty─┬─zsh]
      │          │              │                   │              └─9*[{alacritty}]]
      │          │              │                   ├─alacritty─┬─zsh───less
      │          │              │                   │           └─9*[{alacritty}]
      │          │              │                   ├─alacritty─┬─ncmpcpp
      │          │              │                   │           └─9*[{alacritty}]
      │          │              │                   ├─alacritty─┬─zsh───pstree
      │          │              │                   │           └─9*[{alacritty}]
      │          │              │                   └─chromium─┬─chromium───chromium───12*[{chromium}]
      │          │              │                              ├─chromium───chromium─┬─chromium───4*[{c+
      │          │              │                              │                     ├─19*[chromium───1+
      │          │              │                              │                     ├─chromium───17*[{+
      │          │              │                              │                     ├─chromium───14*[{+
      │          │              │                              │                     ├─chromium───3*[{c+
      │          │              │                              │                     ├─chromium───19*[{+
      │          │              │                              │                     ├─chromium───6*[{c+
      │          │              │                              │                     └─chromium───8*[{c+
      │          │              │                              ├─chromium───9*[{chromium}]
      │          │              │                              ├─chromium───6*[{chromium}]
      │          │              │                              └─21*[{chromium}]
      │          │              └─{sddm}
      │          └─runsv───NetworkManager───2*[{NetworkManager}]
      ├─wireplumber───4*[{wireplumber}]
      ├─wpa_supplicant
      ├─4*[zsh───gitstatusd-linu───16*[{gitstatusd-linu}]]
      ├─8*[zsh]
      └─zsh───sleep  


The log for the mpd daemon shows the following error:

Code: [Select]
2023-02-15_11:38:07.28695 exception: Failed to open "PipeWire Audio Server" (pipewire); Failed to connect stream: Host is down
2023-02-15_11:38:07.28700 output: opened "my_fifo" (fifo) audio_format=44100:16:2
2023-02-15_11:38:07.28703 output: converting in=44100:24:2 -> f=44100:24:2 -> out=44100:16:2

For the connection of clients to the mpd server, I use a UNIX socket, and clients seem to be able to connect to it without any problem:

Code: [Select]
❯ mpc --host /home/localuser/.local/state/mpd/socket toggle
Billy Idol - Billy Idol - Mony Mony
[playing] #13/367   0:12/5:02 (3%)
volume:100%   repeat: off   random: off   single: off   consume: off     


So, it seems the problem is that the mpd daemon cannot find the pipewire server.

If I run the mpd daemon as a regular process, either from the command line or at start up, everything works correctly.

Any ideas on how to make the mpd daemon run as a runit user service?

Thanks a lot.

Re: mpd music daemon error when started as a user service

Reply #1
I didn't have any luck going directly to pipewire for my setup, so I used pipewire-pulse and used the pulse output in mpd.conf.

Out of curiosity what does your mpd.conf look like?  I'd like to see what a straight to pipewire config looks like.  And when you start mpd as a regular process is it for sure reading the same .conf file as when started as service?

Also what user are your services running as (pipewire and mpd)?  Be good to verify that your pipewire userservice is functioning properly.

I did mess around with this for a while but in the end I switched to dinit and did it that way.  I ended up using dinit user services for all pipewire related processes but used a system service for mpd, with mpd running as the mpd user from within mpd.conf.

Re: mpd music daemon error when started as a user service

Reply #2
Quote
I didn't have any luck going directly to pipewire for my setup, so I used pipewire-pulse and used the pulse output in mpd.conf.

Using pulse output in mpd.conf has not worked for me, either.
For that, I have enabled this configuration excerpt in mpd.conf:

Code: [Select]
audio_output {
type "pulse"
name "pulse audio"
}


Quote
Out of curiosity what does your mpd.conf look like?  I'd like to see what a straight to pipewire config looks like. 


It is very simple:

Code: [Select]
audio_output {
  type "pipewire"
  name "PipeWire Audio Server"
}

Quote
And when you start mpd as a regular process is it for sure reading the same .conf file as when started as service?

Yes, I am pretty sure .... in both cases it uses the paths to the different items I have configured in my mpd.conf file (socket file, database file, fifo, playlists dir, state file and sticker.sql)

Quote
Also what user are your services running as (pipewire and mpd)? 

Both are running as my user, and also both when I run mpd as a runit user service or as regular process started from the command line.

Quote
Be good to verify that your pipewire userservice is functioning properly.

Well, yeah, that is what I mentioned .... audio works perfectly when I use other programs (browsers, etc).


Quote
I did mess around with this for a while but in the end I switched to dinit and did it that way.  I ended up using dinit user services for all pipewire related processes but used a system service for mpd, with mpd running as the mpd user from within mpd.conf.

I have not tried to run mpd as a system service, although that is not something I would like to have, to be honest.
Given there is a user-specific mpd.conf file means it should be started as a user service, not as a system service.

Re: mpd music daemon error when started as a user service

Reply #3
Maybe I'm wrong here but it looks like (based on pstree) that your wireplumber and pipewire-pulse services are running at the system level while pipewire and mpd are running at user level?  Maybe I'm misinterpreting the tree.  I would think that would cause more obvious issues than just mpd not working properly so I must be wrong there.

Not sure exactly what the issue is here but this was my solution:

Put this in /etc/pipewire/pipewire-pulse.conf.d/tcp.conf, copied then edited from /usr/share/pipewire-pulse.conf:
Code: [Select]
pulse.properties = {
    # the addresses this server listens on
    server.address = [
        "unix:native"
        #"unix:/tmp/something"              # absolute paths may be used
        #"tcp:4713"                         # IPv4 and IPv6 on all addresses
        #"tcp:[::]:9999"                    # IPv6 on all addresses
        "tcp:127.0.0.1:8888"               # IPv4 on a single address                  #uncommenting this
        #
        #{ address = "tcp:4713"             # address
        #  max-clients = 64                 # maximum number of clients
        #  listen-backlog = 32              # backlog in the server listen queue
        #  client.access = "restricted"     # permissions for clients
        #}
    ]
    #pulse.min.req          = 256/48000     # 5ms
    #pulse.default.req      = 960/48000     # 20 milliseconds
    #pulse.min.frag         = 256/48000     # 5ms
    #pulse.default.frag     = 96000/48000   # 2 seconds
    #pulse.default.tlength  = 96000/48000   # 2 seconds
    #pulse.min.quantum      = 256/48000     # 5ms
    #pulse.idle.timeout     = 0             # don't pause after underruns
    #pulse.default.format   = F32
    #pulse.default.position = [ FL FR ]
    # These overrides are only applied when running in a vm.
    vm.overrides = {
        pulse.min.quantum = 1024/48000      # 22ms
    }
}

Then in your mpd.conf in the pulseaudio output section add:
Code: [Select]
      server          "127.0.0.1:8888"

But this solution, as far as I know, is for when mpd is running as a different user than pipewire-pulse and shouldn't be necessary when running as the same user?

Also from what I remember when I was trying this with runit, just running "sv status mpd" would check your system service svdir for mpd, where you would have to do something like "sv status ~/svdir/mpd" to check specifically where your user services are.

The only other thing I see and this is likely not related at all to your issue but in your service definition for mpd the way you're checking for pipewire-pulse is different from how runit says to do it, which is using "sv check" rather than pgrep.

Re: mpd music daemon error when started as a user service

Reply #4
Quote
Maybe I'm wrong here but it looks like (based on pstree) that your wireplumber and pipewire-pulse services are running at the system level while pipewire and mpd are running at user level?  Maybe I'm misinterpreting the tree.  I would think that would cause more obvious issues than just mpd not working properly so I must be wrong there.

Not exactly. Both wireplumber and pipewire-pulse services are running at the user level. The thing is that they are started by my pipewire service (due to it is configured that way). So, the only supervised process is pipewire, and not the ones pipewire itself forks.

I will try putting those two processes under runit umbrella, but I think I already tried and it did not work......

Thanks for sharing your configuration. I see you use and IP address and port to communicate pipewire-pulse with mpd server.
It should not be necessary, since I guess those two guys can use Dbus to communicate each other as long as they are running in the same host and under the same user. Anyway, I will also try that, just in case. A Unix socket should also work, I presume ....

Quote
The only other thing I see and this is likely not related at all to your issue but in your service definition for mpd the way you're checking for pipewire-pulse is different from how runit says to do it, which is using "sv check" rather than pgrep.

I cannot use "sv check" for the reason I mentioned before .... both pipewire-pulse and wireplumber are started by pipewire service itself, not by runit. That means they are not supervised, and you cannot use runit commands to check their status.

Thanks.

Quote
Also from what I remember when I was trying this with runit, just running "sv status mpd" would check your system service svdir for mpd, where you would have to do something like "sv status ~/svdir/mpd" to check specifically where your user services are.

Not exactly.
For user services, you can just do:

Quote
$ sv status mpd

And for system services, you do from the regular user account:

Quote
$ sudo sv status mpd

In fact, you can see it works well in the code excerpt I posted before. All those excerpts were obtained using my regular user account.


Re: mpd music daemon error when started as a user service

Reply #5
Ahh right right sudo sv or sv that makes sense.  Sorry just going off memory :P

Re: mpd music daemon error when started as a user service

Reply #6
No worries at all.

For now, I am just running mpd as a regular unsupervised process, initiated from one of my startup scripts.

It is somewhat clear that my problem is somehow related to permissions (lack of), but cannot figure it out exactly....


 

Re: mpd music daemon error when started as a user service

Reply #7
Ok, I have fixed it.

Things that I have done:

- Run the three services (pipewire, wireplumber and pipewire-pulse) as user services with runit
- Comment out the session manager section in my personal pipewire.config file:
    # { name = libpipewire-module-session-manager }
- run both pipewire and wireplumber inside a dbus session, not only pipewire
- run mpd using the --systemd flag. I guess this avoids some checks on pids and the like to be done by mpd server


Quote
runit─┬─at-spi-bus-laun─┬─dbus-daemon
      │                 └─2*[{at-spi-bus-laun}]
      ├─at-spi2-registr───2*[{at-spi2-registr}]
      ├─autostart.sh─┬─dwmblocks
      │              ├─nm-applet───4*[{nm-applet}]
      │              └─picom───2*[{picom}]
      ├─chrome_crashpad───{chrome_crashpad}
      ├─chrome_crashpad
      ├─2*[dbus-daemon]
      ├─2*[dbus-launch]
      ├─dunst───2*[{dunst}]
      ├─runsvdir─┬─6*[runsv───agetty]
      │          ├─runsv─┬─dbus-daemon
      │          │       └─svlogd
      │          ├─runsv───elogind
      │          ├─runsv─┬─runsvdir─┬─runsv─┬─emacs
      │          │       │          │       └─svlogd
      │          │       │          ├─runsv─┬─cat
      │          │       │          │       └─dbus-run-sessio─┬─dbus-daemon
      │          │       │          │                         └─pipewire───{pipewir+
      │          │       │          ├─runsv─┬─cat
      │          │       │          │       └─dbus-run-sessio─┬─dbus-daemon
      │          │       │          │                         └─wireplumber───4*[{w+
      │          │       │          ├─runsv─┬─cat
      │          │       │          │       └─mpd───8*[{mpd}]
      │          │       │          └─runsv─┬─cat
      │          │       │                  └─pipewire-pulse───{pipewire-pulse}
      │          │       └─svlogd
      │          ├─runsv───udevd
      │          ├─runsv───sddm─┬─Xorg───9*[{Xorg}]
      │          │              ├─sddm-helper───dwm─┬─alacritty─┬─zsh─┬─emacs
      │          │              │                   │           │     └─pstree
      │          │              │                   │           └─9*[{alacritty}]
      │          │              │                   └─chromium─┬─chromium───chromiu+
      │          │              │                              ├─chromium───chromiu+
      │          │              │                              ├─chromium───7*[{chr+
      │          │              │                              ├─chromium───6*[{chr+
      │          │              │                              └─20*[{chromium}]
      │          │              └─{sddm}
      │          └─runsv───NetworkManager───2*[{NetworkManager}]
      ├─wpa_supplicant
      ├─zsh───gitstatusd-linu───16*[{gitstatusd-linu}]
      └─2*[zsh]



Hope this can help others.