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!
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!