Solved: Delay minidlna daemon to load after mount

I have external USB HDD (ext4 FS on a rotating disk) attached to my OpenWrt 21.02.2 device.

When minidlnad loads it does not see the mount points.

Fri Jun  3 11:45:02 2022 daemon.info minidlnad[1885]: [2022/06/03 11:45:02] minidlna.c:671: error: Media directory "A,/mnt/sda3/audio" not accessible [No such file or directory]
Fri Jun  3 11:45:02 2022 daemon.info minidlnad[1885]: [2022/06/03 11:45:02] minidlna.c:671: error: Media directory "V,/mnt/sda3/videos" not accessible [No such file or directory]
Fri Jun  3 11:45:02 2022 daemon.info minidlnad[1885]: [2022/06/03 11:45:02] minidlna.c:671: error: Media directory "P,/mnt/sda3/photos" not accessible [No such file or directory]
Fri Jun  3 11:45:03 2022 kern.info kernel: [   21.572858]  sda: sda1 sda2 sda3 sda4
Fri Jun  3 11:45:03 2022 kern.notice kernel: [   21.582665] sd 0:0:0:0: [sda] Attached SCSI disk
Fri Jun  3 11:45:04 2022 daemon.info samba4-server: io_uring module found, enabling VFS io_uring. (also needs Kernel 5.4+ Support)
Fri Jun  3 11:45:04 2022 daemon.info samba4-server: io_uring module found, enabling VFS io_uring. (also needs Kernel 5.4+ Support)
Fri Jun  3 11:45:05 2022 kern.info kernel: [   22.807455] EXT4-fs (sda3): recovery complete
Fri Jun  3 11:45:05 2022 kern.info kernel: [   22.835553] EXT4-fs (sda3): mounted filesystem with ordered data mode. Opts:
Fri Jun  3 11:45:05 2022 kern.info kernel: [   23.010312] Adding 1552380k swap on /dev/sda4.  Priority:-2 extents:1 across:1552

I see in the system logs that minidlna fails, then hdd is recognized and mounted. I do have check fs on boot option enabled. If I reload minidlna it is able to see and serve the files. How do I delay the minidlna daemon being loaded after hdd is mounted. I have manually checked the HDD with e2fsck. There are no errors. BTW Samba4 does not seem to have this issue and has been working fine.

Disable the minidlna service, and add a start, to your local start up script.

Perhaps preceeded by a sleep.

I disabled minidlna and I tried putting following in /etc/rc.local. It does not work. minidlna does not start.

sleep 20
service minidlna start
exit 0

Right after reboot in ssh terminal ....

# service minidlna status
inactive
# service minidlna start
# service minidlna status
running

Where can I change the start priority of the init script? minidlna is at 81 and samba4 is at 98. Samba4 does work.

It's in the minidlna file in /etc/init.d dir,
or rename the S81minidlna softlink to S99minidlna, to make it start last.

Could also try /etc/init.d/minidlna start in the local startup, instead of service.

I did use this and service does start but it is still starting before the drive is mounted. So it cannot see any files. Once booted, I restart the service on a command line, and it can serve the files. Although I do not like systemd, but, is there something analogous that can use "requires" drive mounted? Can a shell script ...say... "loop until drive mounted" then start minidlna? Can I put it in rc.local? I am surprised nobody has seen this issue. And, Samba4 does not have any problems, it does load after the drive is mounted.

I not going to solve this trying problem, but is there any chance you have a SSD drive you could test with media on it to see if ruling out a "rotating disk" delay issue might be pointed out as the culprit?

Yes, I used to have this problem and would remove the mount point from Luci>System>Mount Points and then place the mount command in rc.local followed by the short sleep and /etc/init.d/minidlna start command that @frollic mentioned (keeping minidlna disabled in startup).

Put a semaphore file on the disk, loop until it exists, then start the minidlna.

1 Like

@frollic I was thinking the same. So, here is my solution that works. I did not remove the mount point as @mike suggested because samba also needs it.

Please let me know if anything is wrong or can be improved.

  1. On the root of the hard drive I have a file called mydisk.
touch mydisk
  1. In initscrips I disabled autostart for minidlna.
  2. /etc/rc.local I call my script /root/minidlna.sh
# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.
/root/minidlna.sh
exit 0
  1. I created a shell script in /root called minidlna.sh

Here are the contents of that script.

#! /bin/sh
file='/mnt/sda3/mydisk'
while [ ! -f $file ]
do {            
        sleep 10
}
done
/etc/init.d/minidlna start

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.