Creiamo ad esempio /usr/local/etc/rc.d/mldonkey.sh come segue:
#!/bin/sh
#
# MLDonkey start/stop script - (c) 2005 Maurizio Giunti
#
# This is free software; you can redistribute it and/or modify
#
## BEGIN USER CONFIGURATION ##
#
# Set running directory and username (not root).
MLDONKEYDIR=/home/donkey/.mldonkey
USERNAME=donkey
#
## END USER CONFIGURATION ##
# Include funzioni bsd per la gestione dei servizi
. /etc/rc.subr
. /etc/rc.conf
if test -n ${mldonkey_enable:-""} && checkyesno mldonkey_enable; then
else
exit 100
fi
getpid() {
PID=`ps ax -o "pid user command" | grep "ml[nN]et-real” | grep -o -E “[0-9]+ “`
echo $PID
}
status() {
STATUSPID=`getpid`
if [ -n "$STATUSPID" ];then
if [ `ps -p $STATUSPID | wc -l` -eq 2 ]; then
echo “mldonkey (pid $STATUSPID) running…”
return 1
else
echo “Stale PID ???”
fi
fi
echo “mldonkey is not running”
return 0
}
start() {
# see if there is a mldonkey running
status
if [ $? = 0 ]; then
echo “Starting mldonkey”
cd $MLDONKEYDIR
# Remove old servers
rm -rf servers.ini*
# Remove tmp files
rm -rf *.tmp
# Run MLDonkey
su $USERNAME -c “nice -n 19 /usr/local/bin/mlnet -daemon 2> /dev/null”
fi
return 0
}
stop() {
STOPPID=`getpid`
status
if [ $? = 1 ]; then
echo “Stopping mldonkey”
kill $STOPPID
sleep 3
return 0
fi
return 1
}
case “$1″ in
’status’)
status ;;
’start’)
start ;;
’stop’)
stop ;;
‘restart’)
stop
start ;;
*)
echo “usage $0 start|stop|restart|status”
exit 1 ;;
esac
exit $?
##– end
Ricordatevi poi di aggiungere il modo di esecuzione allo script con chmod +x mldonkey.sh .
Per attivare questo script è necessario aggiungere al file /etc/rc.conf la seguente riga:
mldonkey_enable="YES"
RC script for Linux
#!/bin/sh
#
# MLDonkey start/stop script - (c) 2005 Maurizio Giunti
#
# This is free software; you can redistribute it and/or modify
#
## BEGIN USER CONFIGURATION ##
#
# Set running directory and username (not root).
MLDONKEYDIR=/home/donkey/.mldonkey
USERNAME=donkey
#
## END USER CONFIGURATION ##
# Include funzioni bsd per la gestione dei servizi
status() {
STATUSPID=`pgrep -U donkey`
if [ -n "$STATUSPID" ];then
if [ `ps -p $STATUSPID | wc -l` -eq 2 ]; then
echo “mldonkey (pid $STATUSPID) running…”
return 1
else
echo “Stale PID ???”
fi
fi
echo “mldonkey is not running”
return 0
}
start() {
# see if there is a mldonkey running
status
if [ $? = 0 ]; then
echo “Starting mldonkey”
cd $MLDONKEYDIR
# Remove old servers
rm -rf servers.ini*
# Remove tmp files
rm -rf *.tmp
# Run MLDonkey
su $USERNAME -c “nice -n 19 mlnet -daemon 2> /dev/null”
fi
return 0
}
stop() {
STOPPID=`pgrep -U donkey`
status
if [ $? = 1 ]; then
echo “Stopping mldonkey”
kill $STOPPID
sleep 3
return 0
fi
return 1
}
case “$1″ in
’status’)
status ;;
’start’)
start ;;
’stop’)
stop ;;
‘restart’)
stop
start ;;
*)
echo “usage $0 start|stop|restart|status”
exit 1 ;;
esac
exit $?
NOTA: con le ultime versioni distribuite nei Ports, viene installato anche un ottimo script di avvio quindi alcune parti di questo post non sono più attuali.