Entradas etiquetadas como ‘DLink DNS-323’

Escrito por Iván Alonso el Domingo 17 de Enero de 2010

Encontré un script de ejecución para MLDonkey mejor que el incluye el sistema de fonz por defecto, en el blog Writings on the wall. No me funcionaba tal y como estaba escrito, así que tuve que cambiar un par de cosas y ahora parece que hace lo que debe.

Ahora, puede especificarse en el arranque si quieres que la máquina se pare cuando terminen de descargarse todos los archivos de MLDonkey, o si sólo quieres que sea el propio MLDonkey el que se cierre, gracias a una tarea en el crontab que comprueba periódicamente el estado del servidor.

El script es el siguiente, sólo teniendo que cambiar la contraseña de tu usuario administrador de MLDonkey (para poder conectarte al servidor de descargas y poder pedirle su estado actual):

#!/bin/sh
 
# Found in:
# http://bfg100k.blogspot.com/2008/02/enhanced-mldonkey-script-for-your-dns.html
# Some things changed by Ivan Alonso (www.neverbyte.net)
#  - Changed the pattern searched in the mldonkey downloads status
#  - Changed FUNSH variable with SHELL
#  - Some minor changes in the echo messages
#  - Some paths changed to fit with the default installation paths
#    (fonz fun plug and shadowandy mldonkey versions)
 
###################################################################
# author: Sidney Chong (bfg100k[at]gmail[dot]com)                 #
# version: 0.2                                                    #
# date: 18/02/2008                                                #
#                                                                 #
# Version History                                                 #
# ---------------                                                 #
# v0.1 - expanded ShadowAndy(http://www.shadowandy.net) script    #
#        to be more robust on startup as well as added functions  #
#        to check status, stop, restart and auto-stop when        #
#        downloads are completed.                                 #
# v0.2 - added option to shutdown the DNS-323 when downloads are  #
#        completed. By default, the script only stops the         #
#        mldonkey process when there are no more active downloads.#
#                                                                 #
###################################################################
 
if [ -z ${SHELL} ]; then
  #setup the ENV variables if not found
  #this can happen when running from crontab
  echo "Environment variables not found, including fun_plug defaults."
  . /mnt/HD_a2/ffp/etc/profile
fi
 
export MLDONKEY_DIR="/mnt/HD_a2/mldonkey"
export TMPDIR="/mnt/HD_a2/mldonkey/temp"
 
MLNETBINDIR="/mnt/HD_a2/ffp/bin"
MLNETLOG="/mnt/HD_a2/mldonkey/mlnet.log"
TMP_CRONTAB="/mnt/HD_a2/ffp/var/log/crontab.tmp"
TMP_DL_STATUS="/mnt/HD_a2/ffp/var/log/dl.status.tmp"
ADMIN_PSWD="PUT HERE YOUR MLDONKEY ADMIN PASSWD"
 
mlnet_start() {
  echo "Starting mlnet startup sequence... "
  #check if mlnet is already running. if yes, do nothing
  if [ `mlnet_status` = "running" ]; then
    echo "INFO: mldonkey already running! Nothing to do."
    return
  fi
  #check for inproper clean up from the past
  if [ -e ${MLDONKEY_DIR}/mlnet.pid ]; then
    rm ${MLDONKEY_DIR}/mlnet.pid
  fi
 
  if [ -d "${MLDONKEY_DIR}" ]; then
    echo "mldonkey directory found."
  else
    echo "mldonkey directory (${MLDONKEY_DIR}) not found. Creating one..."
    mkdir ${MLDONKEY_DIR}
    #change ownership of the folder to the user account we will use to run mlnet
    #chown 504:703 ${MLDONKEY_DIR}
  fi
  #chmod 664 ${MLDONKEY_DIR}/*
  ${MLNETBINDIR}/mlnet > ${MLNETLOG} 2>&1 &
  #${MLNETBINDIR}/mlnet -run_as_useruid 504 > ${MLNETLOG} 2>&1 &
  if [ -d "${MLDONKEY_DIR}/incoming" ]; then
    chmod 777 ${MLDONKEY_DIR}/incoming/
    chmod 777 ${MLDONKEY_DIR}/incoming/*
  fi
  _mlnet_setup_softstop stop_when_done
  echo "mlnet startup sequence completed."
  echo "Check ${MLNETLOG} for more details."
}
 
mlnet_stop() {
  echo "Stopping mlnet... "
  if [ `mlnet_status` = "running" ]; then
    echo -n "Killing mlnet process... "
    if [ -e ${MLDONKEY_DIR}/mlnet.pid ]; then
      cat ${MLDONKEY_DIR}/mlnet.pidxargs kill
    else
      pidof mlnet  xargs kill
    fi
    echo "done. All mlnet processes killed."
  else
    echo "INFO: mlnet not running! Nothing to kill."
  fi
  _mlnet_setup_softstop
  echo "mlnet stop sequence completed."
}
 
# this routine checks to see if mlnet is still alive
# and if there are any downloads active.
# if no downloads are active, it attempts to stop mlnet.
# if "off_when_done" option is specified, it will attempt to
# shutdown the DNS-323 as well.
_mlnet_softstop() {
  echo -n "`date`: Checking downloads... "
  #touch ${TMP_DL_STATUS}
  wget -O ${TMP_DL_STATUS} -q "http://admin:${ADMIN_PSWD}@127.0.0.1:4080/submit?q=vd"
  if grep -q '<td class="dl al np">R</td>' ${TMP_DL_STATUS}
  then
    echo "downloads are still active!"
  else
    echo "no active downloads found!"
    mlnet_stop
    if [ "${1}" = "off_when_done" ]; then
      echo "attempting to shutdown the DNS-323 now. Bye Bye!"
      touch /tmp/shutdown
    fi
  fi
  rm ${TMP_DL_STATUS}
}
 
# this routine sets up softstop as a cron job that runs every half hour
# to ADD the cron job, pass "add" into the routine,
# to ADD the cron job with shutdown option, pass "off_when_done",
# any other values (or no value) means REMOVE by default
_mlnet_setup_softstop() {
  echo "Setting up softstop on crontab... "
  crontab -l > ${TMP_CRONTAB}
  sed -i -e '/mlnet.sh softstop/d' ${TMP_CRONTAB}
  TMP_NAME=""
  case "$1" in
    stop_when_done)
      TMP_NAME="softstop"
      echo "INFO: This job will stop mldonkey when all downloads are completed."
    ;;
    off_when_done)
      TMP_NAME="softstop_off"
      echo "INFO: This job will attempt to shutdown the DNS-323 when all downloads are completed."
    ;;
    *)
      echo -n "Removing job from crontab... "
    ;;
  esac
  if [ "${TMP_NAME}" != "" ]; then
    # sanity check - do not allow adding any job if mlnet is not already running
    if [ `mlnet_status` = "running" ]; then
      echo -n "Adding cron job to run every half hour... "
      echo -e "0,30 * * * * /mnt/HD_a2/ffp/start/mlnet.sh ${TMP_NAME} >> /mnt/HD_a2/mldonkey/mlnet.log 2>&1" >> ${TMP_CRONTAB}
      sed -i -e '/^\s*$/d' ${TMP_CRONTAB}
    else
      echo "ERROR: mlnet is not running. NOT adding job to crontab."
    fi
  fi
  crontab ${TMP_CRONTAB}
  rm ${TMP_CRONTAB}
  echo "done."
}
 
mlnet_restart() {
  mlnet_stop
  echo "Waiting 10 secs before starting daemon..."
  sleep 10
  mlnet_start
}
 
mlnet_status() {
  if [ -n "$(pidof mlnet)" ]; then
    echo "running"
  else
    echo "stopped"
fi
}
 
case "$1" in
  stop)
    mlnet_stop
    ;;
  softstop)
    _mlnet_softstop
    ;;
  softstop_off)
    _mlnet_softstop off_when_done
    ;;
  set_off_when_done)
    _mlnet_setup_softstop off_when_done
    ;;
  set_stop_when_done)
    _mlnet_setup_softstop stop_when_done
    ;;
  restart)
    mlnet_restart
    ;;
  status)
    mlnet_status
    ;;
  start'')
    mlnet_start
    ;;
  *)
    echo "Usage: $0 start | stop | restart | status | set_off_when_done | set_stop_when_done"
    ;;
esac
Escrito por Iván Alonso el Jueves 1 de Octubre de 2009

Hoy vamos a hacer dos personalizaciones más a nuestro nuevo NAS, tras lo que aprendimos en los últimos posts [primeros pasos y personalizando]. Primero configuraremos el ventilador para que funcione a distintas velocidades dependiendo de la temperatura (viene configurado por defecto para funcionar siempre al 100%) y después activaremos el puerto USB que incluye el aparato para poder conectar otros discos externos y aumentar así la capacidad haciendo que pueda servir más contenidos a la red local (es un puerto USB que por defecto viene capado para poder utilizarse únicamente como puerto para impresoras).

(más…)

Escrito por Iván Alonso el Miércoles 30 de Septiembre de 2009

En el anterior post vimos cómo instalar el pack de aplicaciones diseñado por fonz, y dejamos el sistema funcionando con un servidor telnet para facilitarnos la tarea de realizar futuras modificaciones. Aunque era algo sospechoso el hecho de que nos dejara conectarnos mediante telnet sin pedirnos ningún tipo de usuario ni contraseña.

(más…)

Escrito por Iván Alonso el Lunes 28 de Septiembre de 2009

Tras ver unas cuantas características de las maravillas que se pueden hacer con este aparato, me he hecho con uno, un par de discos SATA, y… a ver qué conseguimos.

DNS-323_package

(más…)