PDA

View Full Version : Far girare mldonkey come demone


Cemb
14-08-2005, 11:58
Ciao a tutti!
Da poco ho risistemato il mio serverino/muletto.
Ci ho messo debian testing con kernel 2.6 ricompilato e mi connetto dai vari client con ssh.

Ho installato i binari precompilati di mldonkey nella home dell'utente "mldonkey", che ho creato per l'occasione, ed il programma è correttamente configurato e funziona alla grande. Accedo da remoto tramite interfaccia web sulla porta 4080, come è normale che sia con questo programma p2p.

Il punto però è che io vorrei che il programma venisse avviato come demone, in modo da lanciarlo all'avvio o lanciarlo/stopparlo da ssh e poi spegnere il client e lasciarlo attivo sul server. Questo sistema funzionava egregiamente sulla distribuzione ipfrog che avevo in precedenza.

Ho trovato uno script da installare in /etc/init.d , nella fattispecie questo:

#!/bin/sh
#
# MLDonkey start/stop script - (c) 2003 Lucas Peetz Dulley
#
# This is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# DESCRIPTION:
# An useful and simple(?) script for starting, stopping and restarting
# MLDonkey as a daemon.
#
# REQUIRES:
# - bash, ps, wc, grep, awk and netcat.
#
# INSTALL:
# - become root
# - copy this file to /etc/init.d/
# - make the file executable "chmod +x /etc/init.d/MLDonkey"
# - create links in the rc.* (in Debian: "update-rc.d MLDonkey defaults")
#
# USAGE:
# - run "/etc/init.d/MLDonkey start" (to start)
# - run "/etc/init.d/MLDonkey stop" (to stop)
# - run "/etc/init.d/MLDonkey restart" (to restart)
#

## BEGIN USER CONFIGURATION ##
#
# Set running directory and username (not root).
MLDONKEYDIR=/full/path/to/mldonkey/directory/
USERNAME=username
#
# Set Netcat's (TCP/IP swiss army knife) filename - usually "nc" or "netcat"
NETCAT=nc
#
## END USER CONFIGURATION ##

status() {
PID=`ps ax -o "pid user command" | grep -E [[:space:]]\{3\}./mlnet | awk {'print $1'}`

if [ $PID ];then
if [ `ps -p $PID | wc -l` -eq 2 ]; then
echo "mldonkey (pid $PID) running..."
return 1
else
echo "Stale PID"
fi
fi
echo "mldonkey is stopped"
return 0
}

start() {
# see if there is a mldonkey running
status &> /dev/null
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 -+19 ./mlnet -daemon &> /dev/null"
fi
return 0
}

stop() {
status &> /dev/null
if [ $? = 1 ]; then
echo "Stopping mldonkey:"
cd $MLDONKEYDIR
bash -c "$NETCAT 127.0.0.1 4000 <<STOPHERE
close_fds
kill
STOPHERE" &> /dev/null
sleep 10
return 0
fi
return 1
}

case "$1" in
'status')
status ;;
'start')
start ;;
'stop')
stop ;;
'restart')
stop
start ;;
*)
echo "usage $0 start|stop|restart"
exit 1 ;;
esac

exit $?
##-- eof


Purtroppo se lo avvio mi dice "starting mldonkey" e mi dà un processo attivo, ma di fatto mldonkey non è raggiungibile tramite interfaccia web da remoto (l'unica disponibile per me, perchè sul server non è installato nessun server grafico e nessun web browser). Se invece avvio mldonkey col comando ./mlnet è tutto ok.

Sapreste dirmi come far funzionare mldonkey (o magari qualsiasi programma) come demone?

Vi ringrazio, buona domenica a tutti!

Pardo
14-08-2005, 18:40
nohup nice -n 19 ./mlnet &
^D

quando la shell termina, vengono brutalizzati solo i processi che hanno nice minore di un certo valore... v. man nice e man nohup

Cemb
14-08-2005, 18:44
Credo di non aver capito.. mi spieghi questo comando?

Cemb
14-08-2005, 18:47
uh, hai editato..

Spiega un momento che comando è e come funziona. Ho visto che va solo da root..
se lo lancio da utente non funziona. Com'è?

Pardo
14-08-2005, 19:14
Veramente nohup e nice vanno da user, al limite pasta l'errore che da`...

Cemb
14-08-2005, 23:58
Veramente nohup e nice vanno da user, al limite pasta l'errore che da`...
ok, grazie!
Domani riprovo (al momento il server è spento, anche perchè sto facendo i preparativi per la ri-partenza).

Comunque mi hai già fatto un grande regalo con questa stringa, ora devo leggermi un po' di pagine di man! :)

Byez!

Cemb
15-08-2005, 10:57
ritiro tutto, funziona se lancio il programma dall'user che possiede i files.

(era un banale problema di permessi)

Se poi voglio killare il processo qual è il modo corretto? Uccidere il core di mldonkey non svolge l'effetto sperato (resta un processo attivo).

Devo dargli il kill manualmente?

grazie!

Pardo
15-08-2005, 11:16
ah gia`...
beh prova cosi` allora
nohup nice -n 19 ./mlnet -daemon &