#!/bin/bash
#
# Autoapagado de la UPV. Vicerrectorado de TIC. Febrero 2010. 
# Author: Guillermo Garcia: guillermogn@upv.es
# Soporte en http://www.upv.es/doc/encendido_remoto y en http://www.asic.upv.es
# Version 1.0.1
# 
# chkconfig: 345 11 89
#
# description:  Programa de Autoapagado de la UPV
# processname:  autoapagadoupv
# config: /etc/autoapagadoUPV.conf
#
# Este archivo no debe modificarse NUNCA a mano

# source function library
if [ -f /etc/init.d/functions ] ; then
        . /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
        . /etc/rc.d/init.d/functions
else
        exit 0
fi

lockfile=/var/lock/subsys/autoapagadoupv

RETVAL=0

start() {
        echo -n $"Activando el servicio de Autoapagado de la UPV ... "
        daemon autoapagadoupv
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch "$lockfile"
        return $RETVAL
}

stop() {
        echo -n $"Parando el servicio de Autoapagado de la UPV ... "
        killproc autoapagadoupv
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f "$lockfile"
        return $RETVAL
}

restart() {
        stop
        start
}

case "$1" in
  start)
        start
        ;;
  stop) 
        stop
        ;;
  restart)
        restart
        ;;
  status)
        if [ -f $lockfile ]; then
                echo $"Servicio de AutoapagadoUPV Funcionando."
                RETVAL=0
        else
                echo $"Servicio de AutoapagadoUPV Parado."
                RETVAL=3
        fi
        ;;
  *)
        echo $"Usage: $0 {start|stop|status|restart}"
        exit 1
esac

exit $RETVAL

