Per poterlo utilizzare in completa sicurezza dobbiamo creare un utente non privilegiato (quindi non appartenente al gruppo wheel), che utilizzeremo per avviarlo. Tutto ciò, evidentemente, per limitare i rischi.
Usiamo adduser per crearlo, chiamandolo donkey:
# adduser
Username: donkey
Full name: Utente per avvio mldonkey
Uid (Leave empty for default):
Login group [donkey]:
Login group is donkey. Invite donkey into other groups? []:
Login class [default]:
Shell (sh csh tcsh nologin) [sh]:
Home directory [/home/donkey]:
Use password-based authentication? [yes]: no
Lock out the account after creation? [no]:
A questo punto dobbiamo creare uno script per avviare in automatico il servizio.
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.