eworm-de / mpd-notification

Notify about tracks played by mpd
GNU General Public License v3.0
86 stars 23 forks source link

Fail to start after mpd on boot #11

Closed petronny closed 8 years ago

petronny commented 8 years ago

Hi, I'm using Archlinux and have installed mpd and mpd-notification-git. Then I want them both to run automatically on boot.

systemctl --user enable mpd
systemctl --user enable mpd-notification

But these command doesn't work. Here is the log of mpd-notification:

20:37:48 systemd[424]: Started MPD Notification.
20:37:48 mpd-notification[433]: /usr/bin/mpd-notification: Connection refused
20:37:48 systemd[424]: mpd-notification.service: Main process exited, code=exited, status=1/FAILURE
20:37:48 systemd[424]: mpd-notification.service: Unit entered failed state.
20:37:48 systemd[424]: mpd-notification.service: Failed with result 'exit-code'.

And the log of mpd:

20:37:48 systemd[424]: Started Music Player Daemon.
20:37:49 mpd[432]: May 12 20:37 : server_socket: bind to '0.0.0.0:6600' failed: Address already in use (continuing anyway, because binding to '[::]:6600' succeeded)

Then referring to Archlinux Wiki, I add both Requires=mpd.service and After=mpd.service to the [Unit] section of mpd-notification.service. But mpd-notification still start before mpd opening its port. Maybe we need a script to delay a few seconds.

eworm-de commented 8 years ago

Just pushed 11b436d32299c71cc0828faff66c66a921842a05 to branch systemd. Not sure if it changes anything for you, though. Want to give it a try?

When did this start to break? Did it work reliable before?

petronny commented 8 years ago

Thank you but I still get Connection refused after updated to 11b436d . My workaround is create a script to delay 3 seconds, then run mpd-notification.

#!/bin/sh
sleep 3
/usr/bin/mpd-notification
After=mpd.service
...
ExecStart=/somewhere/to/the/script.sh

Of course it is a little ugly... How about creating a loop to connect to the server every period time in mpd-notification.c?

eworm-de commented 8 years ago

Forced sleep times and connecting in loop are really ugly workarounds. Usually systemd should get this right, otherwise the software (mpd in this case) is broken.

Let's try something different. Could you please edit /usr/lib/systemd/user/mpd.service and add a line

Type=forking

and change the ExecStart= line to

ExecStart=/usr/bin/mpd

The complete file should look something like this:

[Unit]
Description=Music Player Daemon
After=network.target sound.target

[Service]
Type=forking
ExecStart=/usr/bin/mpd

# allow MPD to use real-time priority 50
LimitRTPRIO=50
LimitRTTIME=infinity

[Install]
WantedBy=default.target
eworm-de commented 8 years ago

Or you could try with

Type=notify

as committed upstream: systemd: set Type=notify

eworm-de commented 8 years ago

Ah, this will not (yet) work... It needs another commit at compile time: Main: notify systemd when MPD is ready

eworm-de commented 8 years ago

Ok, let's use a workaround until real fixes linked above make its way into a release. Can you try branch systemd with 67c75e3155104e7208171be8c5bac5d01fcb063f?

eworm-de commented 8 years ago

Closed with 67c75e3155104e7208171be8c5bac5d01fcb063f.

eworm-de commented 7 years ago

I reverted this in master, should just work with mpd version 0.20 now. Can you give it a try?