#!/bin/bash
#
# Startup script for Mldonkey
#
# Laurent Culioli <laurent@pschit.net>
#
# chkconfig: - 90 15
# description: Mldonkey is client to access multiple peer-to-peer network
# processname: mldonkey
# config: /etc/sysconfig/mldonkey

# Source function library.
. /etc/init.d/functions

# Source some options 
. /etc/sysconfig/mldonkey

[ -z $LOGFILE ] && LOGFILE="/dev/null"

RETVAL=0

# Path to the mldonkey binarie.
fullpath=/usr/bin/mlnet

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

start() {
       echo -n $"Starting Mldonkey (mlnet): "
       cd $DIRECTORY
       daemon --user mldonkey --check mldonkey $NICE "$fullpath  > $LOGFILE 2>&1 &"
       RETVAL=$?
       [ $RETVAL -eq 0 ] && touch /var/lock/subsys/mldonkey
       echo
}
stop() {
       echo -n $"Stopping Mldonkey (mlnet): "
       killproc $fullpath
       rm -fr /var/lock/subsys/mldonkey
       echo
}


# See how we were called.
case "$1" in
        start)
                start
		;;
        stop)
                stop
                ;;
        restart|reload)
                stop
                start
                ;;
        condrestart)
                if status mldonkey >/dev/null; then
                    stop
                    start
                else
                    echo $"Mldonkey (mlnet) is stopped"
                fi
                ;;
        status)
	        status mldonkey
		;;
        *)
                echo $"Usage: $0 {start|stop|restart|reload|condrestart|status}"
                RETVAL=1
esac
exit $RETVAL
