Montando um Media Server com o MediaTomb
Esse artigo descreve os passos necessários para instalação do MediaTomb, um poderoso servidor de mídia baseado no protocolo UPnP.
Parte 3: Configuração para execução automática
a. Edite do arquivo /etc/default/mediatomb conforme abaixo:
b. Crie o script de inicialização:
# vi /etc/init.d/mediatomb
c. Copie o conteúdo abaixo e cole no novo arquivo /etc/init.d/mediatomb:
c. Torne-o executável:
# chmod 755 /etc/init.d/mediatomb
d. Teste-o:
# /etc/init.d/mediatomb start
* Starting upnp media server mediatomb [ OK ]
e. Verifique no log se o mesmo está sendo executado:
# tail -f -n 20 /var/log/mediatomb.log
f. Crie um link para o script de inicialização:
# update-rc.d mediatomb defaults 95
# Set whether the daemon should be started. Set this value to anything
# but 'yes' to enable the daemon
NO_START="no"
# Additional options that are passed to the daemon.
# Vai fazer o bind na porta 50500
OPTIONS="-p 50500"
# The network interface for MediaTomb to bind to and for which the multicast
# routing entry should be added; "" if the route shouldn't be added at all.
# For example: INTERFACE="eth0"
INTERFACE="eth0"
# The route command and arguments to be used if INTERFACE is defined.
# These variables should normally be left unmodified.
ROUTE_ADD="/sbin/route add -net 239.0.0.0 netmask 255.0.0.0"
ROUTE_DEL="/sbin/route del -net 239.0.0.0 netmask 255.0.0.0"
# The user and group that MediaTomb should be run as.
USER="mediatomb"
GROUP="mediatomb"
# but 'yes' to enable the daemon
NO_START="no"
# Additional options that are passed to the daemon.
# Vai fazer o bind na porta 50500
OPTIONS="-p 50500"
# The network interface for MediaTomb to bind to and for which the multicast
# routing entry should be added; "" if the route shouldn't be added at all.
# For example: INTERFACE="eth0"
INTERFACE="eth0"
# The route command and arguments to be used if INTERFACE is defined.
# These variables should normally be left unmodified.
ROUTE_ADD="/sbin/route add -net 239.0.0.0 netmask 255.0.0.0"
ROUTE_DEL="/sbin/route del -net 239.0.0.0 netmask 255.0.0.0"
# The user and group that MediaTomb should be run as.
USER="mediatomb"
GROUP="mediatomb"
b. Crie o script de inicialização:
# vi /etc/init.d/mediatomb
c. Copie o conteúdo abaixo e cole no novo arquivo /etc/init.d/mediatomb:
#! /bin/sh
#
# MediaTomb initscript
#
# Original Author: Tor Krill <tor@excito.com>.
# Modified by: Leonhard Wimmer <leo@mediatomb.cc>
# Modified again by Andres Mejia <mcitadel@gmail.com> to
# base it off of /etc/init.d/skeleton
# Modified again by Flexion.Org <flexiondotorg@gmail.com> to
# reference /usr/local/ and ~/ for a simple from source build
#
#
### BEGIN INIT INFO
# Provides: mediatomb
# Required-Start: $all
# Required-Stop: $all
# Should-Start: $all
# Should-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: upnp media server
### END INIT INFO
# Do NOT "set -e"
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/bin
DESC="upnp media server"
NAME=mediatomb
DAEMON=/usr/local/bin/$NAME
PIDFILE=/var/run/$NAME.pid
LOGFILE=/var/log/$NAME.log
SCRIPTNAME=/etc/init.d/$NAME
DEFAULT=/etc/default/$NAME
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
# Read configuration variable file if it is present
[ -r $DEFAULT ] && . $DEFAULT
# Load the VERBOSE setting and other rcS variables
[ -f /etc/default/rcS ] && . /etc/default/rcS
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
# Start the daemon if NO_START is disabled in DEFAULT
if [ "$NO_START" = "yes" ]; then
test "$1" = "start" && \
{
log_warning_msg "$NAME: Not starting $DESC."
log_warning_msg "$NAME: Disabled in $DEFAULT."
}
exit 0
fi
# Run as root if USER not specified
if [ ! $USER ]; then
USER=root
fi
# Check for an invalid user or one without a home directory
eval USERHOME=~$USER
if [ "${USERHOME#/}" = "${USERHOME}" ]; then
log_failure_msg "$NAME: The user '$USER' specified in $DEFAULT is invalid."
exit 1
fi
if [ "$INTERFACE" != "" ] ; then
INTERFACE_ARG="-e $INTERFACE"
else
INTERFACE_ARG=""
fi
DAEMON_ARGS="-c /home/$USER/.mediatomb/config.xml -d -u $USER -g $GROUP -P $PIDFILE -l $LOGFILE $INTERFACE_ARG $OPTIONS"
#
# Function that starts the daemon/service.
#
do_start() {
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
touch $PIDFILE
chown $USER:$GROUP $PIDFILE
touch $LOGFILE
chown $USER:$GROUP $LOGFILE
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON \
--test > /dev/null \
|| return 1
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
$DAEMON_ARGS \
|| return 2
}
#
# Function that stops the daemon/service.
#
do_stop() {
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
rm -f $PIDFILE
return "$RETVAL"
}
#
# Function that sends a SIGHUP to the daemon/service.
#
do_reload() {
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
return 0
}
case "$1" in
start)
if [ -n "$INTERFACE" ]; then
# try to add the multicast route
if [ "$VERBOSE" != no ]; then
{
log_action_begin_msg \
"$NAME: Trying to add the multicast route"
$ROUTE_ADD $INTERFACE \
&& log_action_end_msg 0
} || {
true && \
log_warning_msg "Failed to add multicast route. skipping."
}
else
$ROUTE_ADD $INTERFACE >/dev/null 2>&1 || true
fi
fi
log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_warning_msg "$DESC" "'$NAME'" "was already started" ;;
2) log_end_msg 1 ;;
esac
;;
stop)
log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0)
log_end_msg 0
if [ -n "$INTERFACE" ]; then
# try to add the multicast route
if [ "$VERBOSE" != no ]; then
{
log_action_begin_msg \
"$NAME: Trying to delete the multicast route"
$ROUTE_DEL $INTERFACE \
&& log_action_end_msg 0
} || {
true && \
log_warning_msg \
"Failed to delete multicast route. skipping."
}
else
$ROUTE_DEL $INTERFACE >/dev/null 2>&1 || true
fi
fi
;;
1) log_warning_msg "$DESC" "'$NAME'" "was already stopped" ;;
2) log_end_msg 1 ;;
esac
;;
reload|force-reload)
log_daemon_msg "Reloading $DESC" "$NAME"
do_reload
log_end_msg $?
;;
restart)
#
# If the "reload" option is implemented, move the "force-reload"
# option to the "reload" entry above. If not, "force-reload" is
# just the same as "restart".
#
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
sleep 1
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3
;;
esac
:
#
# MediaTomb initscript
#
# Original Author: Tor Krill <tor@excito.com>.
# Modified by: Leonhard Wimmer <leo@mediatomb.cc>
# Modified again by Andres Mejia <mcitadel@gmail.com> to
# base it off of /etc/init.d/skeleton
# Modified again by Flexion.Org <flexiondotorg@gmail.com> to
# reference /usr/local/ and ~/ for a simple from source build
#
#
### BEGIN INIT INFO
# Provides: mediatomb
# Required-Start: $all
# Required-Stop: $all
# Should-Start: $all
# Should-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: upnp media server
### END INIT INFO
# Do NOT "set -e"
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/bin
DESC="upnp media server"
NAME=mediatomb
DAEMON=/usr/local/bin/$NAME
PIDFILE=/var/run/$NAME.pid
LOGFILE=/var/log/$NAME.log
SCRIPTNAME=/etc/init.d/$NAME
DEFAULT=/etc/default/$NAME
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
# Read configuration variable file if it is present
[ -r $DEFAULT ] && . $DEFAULT
# Load the VERBOSE setting and other rcS variables
[ -f /etc/default/rcS ] && . /etc/default/rcS
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
# Start the daemon if NO_START is disabled in DEFAULT
if [ "$NO_START" = "yes" ]; then
test "$1" = "start" && \
{
log_warning_msg "$NAME: Not starting $DESC."
log_warning_msg "$NAME: Disabled in $DEFAULT."
}
exit 0
fi
# Run as root if USER not specified
if [ ! $USER ]; then
USER=root
fi
# Check for an invalid user or one without a home directory
eval USERHOME=~$USER
if [ "${USERHOME#/}" = "${USERHOME}" ]; then
log_failure_msg "$NAME: The user '$USER' specified in $DEFAULT is invalid."
exit 1
fi
if [ "$INTERFACE" != "" ] ; then
INTERFACE_ARG="-e $INTERFACE"
else
INTERFACE_ARG=""
fi
DAEMON_ARGS="-c /home/$USER/.mediatomb/config.xml -d -u $USER -g $GROUP -P $PIDFILE -l $LOGFILE $INTERFACE_ARG $OPTIONS"
#
# Function that starts the daemon/service.
#
do_start() {
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
touch $PIDFILE
chown $USER:$GROUP $PIDFILE
touch $LOGFILE
chown $USER:$GROUP $LOGFILE
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON \
--test > /dev/null \
|| return 1
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
$DAEMON_ARGS \
|| return 2
}
#
# Function that stops the daemon/service.
#
do_stop() {
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
rm -f $PIDFILE
return "$RETVAL"
}
#
# Function that sends a SIGHUP to the daemon/service.
#
do_reload() {
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
return 0
}
case "$1" in
start)
if [ -n "$INTERFACE" ]; then
# try to add the multicast route
if [ "$VERBOSE" != no ]; then
{
log_action_begin_msg \
"$NAME: Trying to add the multicast route"
$ROUTE_ADD $INTERFACE \
&& log_action_end_msg 0
} || {
true && \
log_warning_msg "Failed to add multicast route. skipping."
}
else
$ROUTE_ADD $INTERFACE >/dev/null 2>&1 || true
fi
fi
log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_warning_msg "$DESC" "'$NAME'" "was already started" ;;
2) log_end_msg 1 ;;
esac
;;
stop)
log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0)
log_end_msg 0
if [ -n "$INTERFACE" ]; then
# try to add the multicast route
if [ "$VERBOSE" != no ]; then
{
log_action_begin_msg \
"$NAME: Trying to delete the multicast route"
$ROUTE_DEL $INTERFACE \
&& log_action_end_msg 0
} || {
true && \
log_warning_msg \
"Failed to delete multicast route. skipping."
}
else
$ROUTE_DEL $INTERFACE >/dev/null 2>&1 || true
fi
fi
;;
1) log_warning_msg "$DESC" "'$NAME'" "was already stopped" ;;
2) log_end_msg 1 ;;
esac
;;
reload|force-reload)
log_daemon_msg "Reloading $DESC" "$NAME"
do_reload
log_end_msg $?
;;
restart)
#
# If the "reload" option is implemented, move the "force-reload"
# option to the "reload" entry above. If not, "force-reload" is
# just the same as "restart".
#
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
sleep 1
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3
;;
esac
:
c. Torne-o executável:
# chmod 755 /etc/init.d/mediatomb
d. Teste-o:
# /etc/init.d/mediatomb start
* Starting upnp media server mediatomb [ OK ]
e. Verifique no log se o mesmo está sendo executado:
# tail -f -n 20 /var/log/mediatomb.log
f. Crie um link para o script de inicialização:
# update-rc.d mediatomb defaults 95
Mas o artigo perde-se em configurações que deviam estar em anexos, para se poder ler melhor o artigo, e fiquei sem perceber para que é que serve , e quem lê .
Estava aqui a ver, na internet, que se pode instalar o mediathumb em discos multimédia como emetec R100, que deve ser bastante interessante (eu tenho um) mas não percebo qual a sua função e para que serve a PS3?
De qualquer modo , agradeço imenso a sua contribuição, e não desanime com as criticas :)