Difference between revisions of "ReadyMedia"

From ArchWiki
Jump to: navigation, search
(added link)
m (Local)
Line 62: Line 62:
  
 
dmn_strt () {
 
dmn_strt () {
  # -R will rebuild file database on start (inotify only works when monitoring)
+
   minidlna -f "$cnf" -P "$pid" > $log 2>&1 &
   minidlna -R -f "$cnf" -P "$pid" > $log 2>&1 &
+
 
}
 
}
  
dmn_stop () {
+
dmn_stop () {
   if [ "$(pidof minidlna)" ]; then
+
   if [ "$(pgrep -x minidlna)" ]; then
 
     killall -9 minidlna && sleep 2 && \
 
     killall -9 minidlna && sleep 2 && \
 
     echo " Stopped MiniDLNA daemon"
 
     echo " Stopped MiniDLNA daemon"
Line 73: Line 72:
 
     echo " MiniDLNA is not running"
 
     echo " MiniDLNA is not running"
 
   fi
 
   fi
 +
}
 +
 +
dmn_rscn () {
 +
  minidlna -R -f "$cnf" -P "$pid" > $log 2>&1 &
 +
}
 +
 +
help    () {
 +
  echo " ${0##*/} <start|stop|rescan> - start,stop,rescan the MiniDLNA daemon"
 
}
 
}
  
Line 82: Line 89:
 
   stop    ) # Stop daemon
 
   stop    ) # Stop daemon
 
             dmn_stop ;;
 
             dmn_stop ;;
 +
  rescan  ) # Rescan for new files (new file detection only works when
 +
            # minidlna is running)
 +
            dmn_stop
 +
            dmn_rscn ;;
 
   *      ) # Display usage if no parameters given
 
   *      ) # Display usage if no parameters given
             echo " ${0##*/} <start|stop> - start and stop the MiniDLNA daemon"
+
             help
 
esac</pre>}}
 
esac</pre>}}
  

Revision as of 23:03, 17 August 2012

MiniDLNA is server software with the aim of being fully compliant with DLNA/UPnP clients. The MiniDNLA daemon serves media files (music, pictures, and video) to clients on a network. Example clients include applications such as totem and xbmc, and devices such as portable media players, Smartphones, Televisions, and gaming systems (such as PS3 and Xbox 360).

MiniDLNA is a simple, lightweight alternative to MediaTomb, but has fewer features. It does not have a web interface for administration and must be configured by editing a text file.

Installation

Install minidlna from the official repositories.

Configuration

The MiniDLNA daemon can be run as either a global (config:/etc/minidlna.conf) or per-user instance (config:user-defined), these are the necessary common settings:

#network_interface=eth0         # Self-discovers if commented (at times necessary to set)
media_dir=A,/home/user/Music    # Use A, P, and V to restrict media 'type' in directory
media_dir=P,/home/user/Pictures
media_dir=V,/home/user/Videos
friendly_name=Media Server      # Optional
db_dir=/var/cache/minidlna      # Needs to be un-commented
log_dir=/var/log                # Needs to be un-commented
inotify=yes                     # 'no' for less resources, restart required for new media

Global

While not necessary, it is a good idea to also enable MiniDLNA's cache (so the database and album art cache do not need to be re-created on every restart) and logging capabilities. MiniDLNA runs as the nobody user, so any directory you include will need to be readable by this user. To do so, create the necessary directories and chown them to nobody:nobody.

# mkdir /var/{cache,log}/minidlna
# chown nobody:nobody /var/{cache,log}/minidlna

MiniDLNA includes an initscript to start it as a global daemon. Be sure to add it to rc.conf to have it loaded at boot.

Local

Create the necessary files and directories locally and edit the configuration:

# mkdir -p ~/.minidlna/cache
# cd ~/.minidlna
# cp /etc/minidlna.conf .
# $EDITOR minidlna.conf

Configure as you would globally above but these definitions need to be defined locally:

db_dir=/home/$USER/.minidlna/cache
log_dir=/home/$USER/.minidlna

This is a local daemon script to start and stop MiniDLNA as a regular user:

minidlna-daemon
#!/bin/bash
# Start and stop the MiniDLNA daemon

cnf="/home/$USER/.minidlna/minidlna.conf"
pid="/home/$USER/.minidlna/minidlna.pid"
log="/home/$USER/.minidlna/minidlna.log"

# Required program(s)
req_progs=(minidlna)
for p in ${req_progs[@]}; do
  hash "$p" 2>&- || \
  { echo >&2 " Required program \"$p\" not installed."; exit 1; }
done

dmn_strt () {
  minidlna -f "$cnf" -P "$pid" > $log 2>&1 &
}

dmn_stop () {
  if [ "$(pgrep -x minidlna)" ]; then
    killall -9 minidlna && sleep 2 && \
    echo " Stopped MiniDLNA daemon"
  else
    echo " MiniDLNA is not running"
  fi
}

dmn_rscn () {
  minidlna -R -f "$cnf" -P "$pid" > $log 2>&1 &
}

help     () {
  echo " ${0##*/} <start|stop|rescan> - start,stop,rescan the MiniDLNA daemon"
}

case $1 in
  start   ) # Start daemon
            dmn_stop
            dmn_strt || { echo " Failure in starting daemon"; exit; }
            echo " Started MiniDLNA daemon" ;;
  stop    ) # Stop daemon
            dmn_stop ;;
  rescan  ) # Rescan for new files (new file detection only works when
            # minidlna is running)
            dmn_stop
            dmn_rscn ;;
  *       ) # Display usage if no parameters given
            help
esac

Load daemon on Login

A .desktop file in ~/.config/autostart will do this:

~/.config/autostart/minidlna.desktop
[Desktop Entry]
Encoding=UTF-8
Type=Application
Name=MiniDLNA
Comment=Server to stream media over network
Exec=/home/$USER/.scripts/minidlna-daemon start
StartupNotify=false
Terminal=false
Hidden=false
X-GNOME-Autostart-enabled=true

Make the file executable:

# chmod +x ~/.config/autostart/minidlna.desktop

inotify limits

When MiniDLNA is run as a regular user it does not have the ability to change the kernel's inotify settings these settings will need to added manually. The default number of inotify watches is non-sufficient to have MiniDLNA monitor media file properly, to increase inotify watches do it through sysctl (100000 should be enough for most uses):

# sudo sysctl fs.inotify.max_user_watches=100000

To have it permanently added add to /etc/sysctl.conf

# Increase inotify max watchs per user for local minidlna
fs.inotify.max_user_watches = 100000"

Other details

Additional details that may need to be considered.

Firewall

If using a firewall the the ssdp (1900/udp) and trivnet1 (8200/tcp) ports will need to be opened. For example, this can be done with arno's iptables firewall by editing firewall.conf and opening the ports by doing:

OPEN_TCP="8200"
OPEN_UDP="1900"

DLNA device file recognition

Some devices do not probe or rescan on a consistent basis or at all. If files get add/subtracted to monitored media directories they may not be noticed until the device DLNA client is restarted.