Social Icons

How to configure inotify to work with MiniDLNA and pickup changes in media_dir

With the advent smart computing devices like ARM processor based Raspberry Pi there has been a significant rise is people setting up their home DLNA Servers for streaming their multimedia collections like movies, videos, pictures directly to their internet enabled or DLNA enabled smart TVs. Even almost all modern Android devices are capable to receiving DLNA streams.

MiniDLNA is one of the very popular DLNA server being used by raspbian users and also by users of Arch Linux and even a large community of Ubuntu users, mainly due to to it's fairly small size and simple ease of use. However there is some issue with MiniDLNA in automatically picking up changes / additions to the media_dir (Media Directory) i.e. more often it doesn't picks up any new file if added to the folder and updates the database which appears on your DLNA renderer like TV.

It generally throws the following warning in the logs:
[2012/10/19 18:35:41] inotify.c:195: warn: WARNING: Inotify max_user_watches [8192] is low or close to the number of used watches [4] and I do not have permission to increase this limit.  Please do so manually by writing a higher value into /proc/sys/fs/inotify/max_user_watches.

While most of the solutions suggests setting up a cron job to rebuild the whole of the database at some specific time but hardly any of them address the fix to real issue or some says that the kernel or OS version doesn't supports the inotify feature. Also I don't like the idea of rebuilding the whole media library database every day or every time a new file is added, as ideally it should just add the new file in the media database  Some of you might have even tried to update /proc/sys/fs/inotify/max_user_watches but probably failed with a error "E667: Fsync failed" at the vi.

Solution:
Edit sysctl.conf (A file for defining kernel parameters)
sudo nano /etc/sysctl.conf

Find and change as below if the following line exists or add at the bottom:
fs.inotify.max_user_watches=65536

Save the file Ctrl + X and Y(es)

Now run the below command, you should be able to see the values you have set:
sudo /sbin/sysctl -p

Finally restart MiniDLNA service and things should be working:
sudo service minidlna restart

Note: Make sure you have inotify enabled and a notify interval is set as per your requirement in /etc/minidlna.conf per the following settings
inotify=yes
notify_interval=300

19 comments:

  1. This worked great for me... surprised there are no comments here yet... now I don't have to keep an "about to watch" folder on my Raspberry Pi and restart minidlna every 20 minutes. Awesome!

    ReplyDelete
    Replies
    1. Glad that it was useful to you, and hopefully to many others.

      Delete
  2. yep, works on my rpi too :) thank you sir

    ReplyDelete
  3. Worked great on my rpi as well!

    ReplyDelete
  4. i landed here again with my new banana pi.
    i forgot to say something it seems last time.
    thx!

    ReplyDelete
  5. tried the above steps and also creating a link in /var/lib/minidlna to the directory you want monitored. (sudo ln -s /media/ExtHD/video /var/lib/minidlna/videos)

    Still no luck with adding new files automatically to minidlna database :(

    ReplyDelete
  6. I have tried all the steps above on my banana pi, but unfortunatley the Auto adding new files still doesn´t work. Does anyone have some other/additional ideas?

    ReplyDelete
  7. thx from germany; worked well for me too

    ReplyDelete
  8. It's not working for me as well. I believe the inotify will work only with EXT file systems. I'm using an external NTFS hard drive.

    ReplyDelete
    Replies
    1. I'm using external NTFS as well. works like a charm.

      Delete
  9. Works like a charm! Took me 2 full days before I came across this post. Awesome! Thank you so much.

    ReplyDelete
  10. you're my hero :)

    ReplyDelete
  11. my minidlna restarts every X seconds
    X=notify_interval ... in my case is set to 300 like in this instructions...
    problem is that i cant watch any movie now ... because very 5 minutes my minidlna restarts ... if i set value on bigger number like 36000 (10h) then i can watch in peace but it do not sync new movies in folder for 10 hours... verry disturbing ... any one have solution for this?
    i'm running MiniDLNA on RPI2

    ReplyDelete
  12. Thanks for this solution. It is people like you that make learning things more enjoyable.

    ReplyDelete
  13. MiniDLNA status post fix...

    Audio files: 0
    Video files: 25
    Image files: 14

    Thanks mate!

    ReplyDelete
  14. why are you even mentioning `notify_interval`?, it has nothing to do with inotify

    ReplyDelete
  15. Perfect. Thank you very much!!!!

    ReplyDelete
  16. I'm having trouble, have done every step here and that i can find elsewhere, i still don't seem to be getting an updated library?

    ReplyDelete
  17. Chalk me up as another helped user. Thank you

    ReplyDelete