#!/bin/bash # # Startup script for Mldonkey # # Laurent Culioli <laurent@pschit.net> # # Currently maintained by Anssi Hannula <anssi.hannula@gmail.com> # # chkconfig: 345 90 15 # description: Mldonkey is client to access multiple peer-to-peer network # processname: mlnet # config: /etc/sysconfig/mldonkey ### BEGIN INIT INFO # Provides: mlnet # Required-Start: $network # Required-Stop: $network # Should-Start: $named # Should-Stop: $named # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Starts the imspector daemon # Description: Mldonkey is client to access multiple peer-to-peer network ### END INIT INFO # Source function library. . /etc/init.d/functions # Source some options NICE="+2" LOGFILE="/var/log/mldonkey.log" . /etc/sysconfig/mldonkey RETVAL=0 # Path to the mldonkey binary. mldonkey=/usr/lib64/mldonkey/mlnet # Path to mldonkey home. mlhome=~mldonkey # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ ${NETWORKING} = "no" ] && exit 0 send_mldonkey_command() { if [ -n "$PASSWORD" ] ; then param="--auth $PASSWORD" else param="" fi mldonkey_command $param $* } start() { gprintf "Starting Mldonkey: " params="-run_as_user mldonkey" numstarted=0 if [ -n $LOGFILE ] ; then # ensure log file is present if [ ! -f $LOGFILE ] ; then touch $LOGFILE chown mldonkey:mldonkey $LOGFILE fi params="$params -log_file $LOGFILE" numstarted=$(grep -c "Core started$" $LOGFILE 2>/dev/null) fi cd $mlhome # This is a hack. If someone knows a cleaner solution, # mail me at <anssi.hannula@gmail.com> # run the demon with mldonkey user (trem) daemon --user mldonkey --check mlnet $NICE $mldonkey $params </dev/null >/dev/null 2>&1 & timeout=0 while true; do timeout=$(($timeout + 1)) sleep 1 if ! pidof $mldonkey >/dev/null; then echo_failure break fi if [ $(grep -c "Core started$" $LOGFILE 2>/dev/null | sed 's/^0$/1/') -gt $numstarted ] || [ $timeout -gt 10 ]; then echo_success touch /var/lock/subsys/mlnet break fi done echo } stop() { gprintf "Stopping Mldonkey: " #send_mldonkey_command kill killproc $mldonkey RETVAL=$? [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/mlnet echo } reload() { gprintf "Reloading Mldonkey: " killproc $mldonkey -HUP echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) stop start ;; pause) send_mldonkey_command pause all ;; resume) send_mldonkey_command resume all ;; status) status mlnet send_mldonkey_command vd ;; *) gprintf "Usage: mldonkey {start|stop|restart|reload|pause|resume|status}\n" RETVAL=1 esac exit $RETVAL