MiniDLNA - A simple UPnP media server


Logs are full of HTTP Connection closed unexpectedly

Log entries are like :
[2018/08/19 21:56:58] upnphttp.c:1061: warn: HTTP Connection closed unexpectedly
To get rid of these :
  1. In /etc/minidlna.conf, change the line :
    into :
    i.e. : http has the default log level warn (like everybody else), changed into error.
  2. Restart MiniDLNA :
    systemctl restart minidlna

Inotify max_user_watches [8192] is low


Full error message :

inotify.c:199: warn: WARNING: Inotify max_user_watches [8192] is low or close to the number of used watches [991] 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.

The reported numbers of configured / used watches are seldom close to each other, and there should be no need to report an alert for that...


Some interesting articles about :


Step 1 : serve less files

After investigating, it turned out that MiniDLNA was serving a giant directory full of photos I never browse from my TV. So I started by commenting some of the media_dir lines of /etc/minidlna.conf

Step 2 : increase the number of watches (sources : 1, 2)

echo fs.inotify.max_user_watches=65536 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p


Shortly after a number of updates, MiniDLNA stops serving files as it used to. My LG TV says :
Ce type de fichier n'est pas pris en charge.
Voulez-vous lire le fichier suivant ?
English version :
Unsupported file type.
Do you want to read the next file ?


/path/to/log/directory/minidlna.log reports errors like :
upnphttp.c:1366: error: Rejecting wide link /symlink/to/some/video -> /path/to/this/video

For security reasons, by default, MiniDLNA is taught not to follow symlinks.


Allow following symlinks with wide_links=yes, as root (source) :

echo 'wide_links=yes' >> /etc/minidlna.conf && kill -15 $(pidof minidlnad) && minidlnad -R

Alternate solution

Leave the configuration as-is and swap who's the "real" directory / who's the symlink and voilà !

minidlna.c:293: fatal: ERROR: Failed to open sqlite database! Exiting...


/path/to/log/directory/minidlna.log is full of :
[2016/09/12 22:18:52] minidlna.c:293: fatal: ERROR: Failed to open sqlite database! Exiting...


If I try :

chown -R bob:users /path/to/db/directory

And restart MiniDLNA, I get :
[2016/09/12 22:20:03] minidlna.c:1004: warn: Starting MiniDLNA version 1.1.2.
[2016/09/12 22:20:03] minidlna.c:354: warn: Creating new database at /path/to/db/directory/files.db


This error is only due to wrong permissions on /path/to/db/directory

MiniDLNA doesn't update its database


Files come and go in the shared directories, but this is not visible on the client side of MiniDLNA .


  1. Is the database even there ? (Both commands are equivalent, I just like being creative with sed and awk )
    • ls -lh $(sed -rn '/^db_dir=/ s/db_dir=// p' /etc/minidlna.conf)/*db
    • ls -lh $(awk -F '=' '/^db_dir=/ {print $2}' /etc/minidlna.conf)/*db
  2. Have a look at the logs :
    • less $(sed -rn '/^log_dir=/ s/log_dir=// p' /etc/minidlna.conf)/*log
    • less $(awk -F '=' '/^log_dir=/ {print $2}' /etc/minidlna.conf)/*log
    • You can also :
      • visit the log directory :
        cd $(sed -rn '/^log_dir=/ s/log_dir=// p' /etc/minidlna.conf) && { pwd; ls -lh *log*; }
      • read the interesting log entries only (you can also get rid of those useless warnings forever) :
        grep -v 'HTTP Connection closed unexpectedly' $(awk -F '=' '/^log_dir=/ {print $2}' /etc/minidlna.conf)/*log | less
      • purge those useless and repeated log entries :
        sed -ri '/HTTP Connection closed unexpectedly/ d' $(sed -rn '/^log_dir=/ s/log_dir=// p' /etc/minidlna.conf)/*log{,.?}
  3. You may also flush the logs and restart MiniDLNA (as root) to have a better understanding of what's going on :
    > $(awk -F '=' '/^log_dir=/ {print $2}' /etc/minidlna.conf)/*log && systemctl restart minidlna


For those who don't want / need to investigate, jump to a solution that works (at your own risks).

Several problems for me :

Problem 1 : Inotify max_user_watches [8192] is low

Even though this error message is very likely to be found in the logs, it looks rather unrelated to the current issue : the database not being updated. Moreover, the reported numbers of configured / used watches are seldom even close to each other, so better not spending too much time on this.

See the Inotify max_user_watches [8192] is low dedicated article.

Problem 2 : minidlna.c:352: fatal: Failed to clean old file cache! Exiting...

For some reason, the art_cache directory (found in the db_dir directory and belonging to a non-root user) had some files owned by root (which couldn't be removed, of course). Check this, as whatever user you like :
  • find $(sed -rn '/^db_dir=/ s/db_dir=// p' /etc/minidlna.conf)/art_cache ! -user $(ps -aux | awk '/\/usr\/sbin\/minidlnad/ {print $1}')
  • find $(awk -F '=' '/^db_dir=/ {print $2}' /etc/minidlna.conf)/art_cache ! -user $(ps -aux | awk '/\/usr\/sbin\/minidlnad/ {print $1}')
And make the required cleaning afterwards.

Other cause / solution (source) :

For some unknown reason, whether or not any of the errors above was found / fixed, MiniDLNA stopped updating its database. The solution is to do one of these, as root :
  • force a full rescan of the media files :
    /usr/sbin/minidlnad -R
  • or delete the MiniDLNA database file and rebuild it (with a full scan of the media files which may take a while and eat your CPU) :
    rm -i $(awk -F '=' '/^db_dir=/ {print $2}' /etc/minidlna.conf)/*db && systemctl restart minidlna

How to setup a DLNA server on Debian ?

This is a 2-step procedure. Don't forget the step 2 or it won't work AT ALL !!!

Step 1/2 : install + initial configuration

  1. apt install minidlna
  2. Edit /etc/minidlna.conf
    • These settings seem to be the bare minimum.
    • media_dir defaults to /var/lib/minidlna
    • if /path/to/whatever implies following a symlink, you'd better read this
  3. You can also define a custom directory for the MiniDLNA database and album art cache (defaults to /var/cache/minidlna) :
  4. Same goes on for logs (defaults to /var/log) :
  5. Rotate logs :
    • Wheezy users (and possibly other distros) : don't forget to logrotate those logs or they'll grow until something bad happens.
    • since Jessie MiniDLNA release : log rotation is built-in, just make sure it's properly configured : cat /etc/logrotate.d/minidlna
  6. The following steps depend on the way you handle daemons :
    Step systemd-style Upstart-style
    reload settings, as root systemctl restart minidlna.service service minidlna force-reload
    check status systemctl status minidlna.service service minidlna status
    view logs journalctl -u minidlna.service visit the log directory defined in the configuration file

Step 2/2 : user rights

When installed from repositories (as described above), MiniDLNA is executed as the minidlna user from the minidlna group. This means minidlna requires permissions to access the media files. One quick'n'dirty solution would be to massively chmod files and directories. Another (IMHO, better) solution is to :
  1. Edit /etc/default/minidlna
  2. Change these 2 directives :
    # User and group the daemon should run as
  3. chown -R bob:users /the/directory/you/configured/as/media_dir
  4. Reload settings