You are not logged in.

#1 2020-08-05 15:17:47

ambrits
Member
Registered: 2020-08-05
Posts: 5

[SOLVED] MPD start too fast before NAS mount

Hi guys!
I'm a very newbie in ARCH Linux world. smile

I want to build a media player. I managed to install the basic system. I also installed and configured the MPD, but when I restart the machine, the MPD will not start and the error is that it will not see the mounted NAS drives. If I restart it manually, that's all right.
Is there any way to have the MPD start only when the drives are already plugged in?
Thanks!

Last edited by ambrits (2020-08-16 12:34:18)

Offline

#2 2020-08-05 16:55:50

ondoho
Member
Registered: 2013-04-30
Posts: 692
Website

Re: [SOLVED] MPD start too fast before NAS mount

ambrits wrote:

Is there any way to have the MPD start only when the drives are already plugged in?

Are you starting mpd as a systemd servide? There are ways to start a service only after a certain condition is met, see the wiki on systemd services.

If not with systemd, a simple delay will do, maybe in a shell script:

sleep 5;mpd

or, more elegantly:

until mount|grep NAS (insert actual identifier here); do sleep 1; done; mpd

Offline

#3 2020-08-06 06:09:52

ambrits
Member
Registered: 2020-08-05
Posts: 5

Re: [SOLVED] MPD start too fast before NAS mount

ondoho wrote:
ambrits wrote:

Is there any way to have the MPD start only when the drives are already plugged in?

Are you starting mpd as a systemd servide?

Yes. This is the service file. I modified the bold part, but nothing changed.

[Unit]
Description=Music Player Daemon
Documentation=man:mpd(1) man:mpd.conf(5)
Requires=mnt-MPDDB.automount
After=mnt-MPDDB.automount network.target sound.target  mnt-MPDDB.mount

[Service]
User=mpd
Type=notify
ExecStart=/usr/bin/mpd --no-daemon
#ExecStart=/usr/bin/mpdstart

# Enable this setting to ask systemd to watch over MPD, see
# systemd.service(5).  This is disabled by default because it causes
# periodic wakeups which are unnecessary if MPD is not playing.
WatchdogSec=120

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

# disallow writing to /usr, /bin, /sbin, ...
ProtectSystem=yes

# more paranoid security settings
NoNewPrivileges=yes
ProtectKernelTunables=yes
ProtectControlGroups=yes
ProtectKernelModules=yes
# AF_NETLINK is required by libsmbclient, or it will exit() .. *sigh*
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX AF_NETLINK
RestrictNamespaces=yes

Offline

#4 2020-08-12 17:43:38

ondoho
Member
Registered: 2013-04-30
Posts: 692
Website

Re: [SOLVED] MPD start too fast before NAS mount

I'm not sure if "Requires" and "After" don't cancek each other out here; I believe "After" is the one that actually waits 'til the device is mounted. Better check the ArchWiki...
Have you checked whether these systemd units complete succesfully?
Why is there so much other stuff in "After"? Shouldn't 1 be enough?

Offline

#5 2020-08-16 06:32:20

ambrits
Member
Registered: 2020-08-05
Posts: 5

Re: [SOLVED] MPD start too fast before NAS mount

ondoho wrote:

I'm not sure if "Requires" and "After" don't cancek each other out here; I believe "After" is the one that actually waits 'til the device is mounted. Better check the ArchWiki...
Have you checked whether these systemd units complete succesfully?
Why is there so much other stuff in "After"? Shouldn't 1 be enough?

Since it didn't work in any way, I tried to make it work somehow. But nothing helped. After all, it improved by setting the IP address to static.

Offline

#6 2020-08-16 10:45:58

ondoho
Member
Registered: 2013-04-30
Posts: 692
Website

Re: [SOLVED] MPD start too fast before NAS mount

ambrits wrote:

After all, it improved by setting the IP address to static.

Meaning the problem was in a completely different place than where we were looking.
You might want to elaborate how you mount the NAS with a static IP (frankly I have no idea how one would do it with a dynamic IP) and then mark this thread SOLVED by editing the first post.

Offline

#7 2020-08-16 12:31:47

ambrits
Member
Registered: 2020-08-05
Posts: 5

Re: [SOLVED] MPD start too fast before NAS mount

ondoho wrote:
ambrits wrote:

After all, it improved by setting the IP address to static.

Meaning the problem was in a completely different place than where we were looking.
You might want to elaborate how you mount the NAS with a static IP (frankly I have no idea how one would do it with a dynamic IP) and then mark this thread SOLVED by editing the first post.

not the NAS, but ARCH Linux got a static IP address

Offline

#8 2020-08-17 20:08:00

luscinius
Member
Registered: 2008-12-25
Posts: 18

Re: [SOLVED] MPD start too fast before NAS mount

ambrits wrote:

not the NAS, but ARCH Linux got a static IP address

I think with the static IP the network just comes up faster (it does not need to wait to get an IP address from the DHCP server), and now it is fast enough to start before MPD. Still it is a race condition.

Systemd documentation suggests using network-online.target instead of network.target: https://www.freedesktop.org/wiki/Softwa … orkTarget/ - maybe this is what you need to do.

You can also try using autofs instead of the systemd mount.

Last edited by luscinius (2020-08-17 20:08:31)

Offline

#9 2020-08-18 06:50:53

ambrits
Member
Registered: 2020-08-05
Posts: 5

Re: [SOLVED] MPD start too fast before NAS mount

luscinius wrote:
ambrits wrote:

not the NAS, but ARCH Linux got a static IP address

I think with the static IP the network just comes up faster (it does not need to wait to get an IP address from the DHCP server), and now it is fast enough to start before MPD. Still it is a race condition.

Systemd documentation suggests using network-online.target instead of network.target: https://www.freedesktop.org/wiki/Softwa … orkTarget/ - maybe this is what you need to do.

You can also try using autofs instead of the systemd mount.

Yes, I tried these too, but it didn't work. The error during MPD startup was that it could not find the attached folders. Although it was set, it did not wait for the attachment. It has been working since static IP was turned on.

Offline

Board footer

Powered by FluxBB