Server per il P2P con Debian: differenze tra le versioni

Vai alla navigazione Vai alla ricerca
Riga 187: Riga 187:


===Script di avvio===
===Script di avvio===
''Rtorrent'' dovrà partire all'avvio del ''server''; dobbiamo, dunque, "demonizzarlo" creando il file <tt>/etc/init.d/rtorrent</tt>:<pre>#!/bin/sh### BEGIN INIT INFO# Provides:      rtorrent# Required-Start:  $network # Required-Stop:  $network # Default-Start:  2 3 4 5# Default-Stop:    0 1 6# Short-Description: Start rtorrent as a daemon### END INIT INFO################<Notes>################# This script depends on screen.# For the stop function to work, you must set an# explicit session directory using ABSOLUTE paths (no, ~ is not absolute) in your rtorrent.rc.# If you typically just start rtorrent with just "rtorrent" on the# command line, all you need to change is the "user" option.# Attach to the screen session as your user with # "screen -dr rtorrent". Change "rtorrent" with srnname option.# Licensed under the GPLv2 by lostnihilist: lostnihilist _at_ gmail _dot_ com#################</Notes>##########################################Start Configuration########################## You can specify your configuration in a different file # (so that it is saved with upgrades, saved in your home directory,# or whateve reason you want to)# by commenting out/deleting the configuration lines and placing them# in a text file (say /home/user/.rtorrent.init.conf) exactly as you would# have written them here (you can leave the comments if you desire# and then uncommenting the following line correcting the path/filename # for the one you used. note the space after the ".".# . /etc/rtorrent.init.conf#Do not put a space on either side of the equal signs e.g.# user = user # will not work# system user to run asuser="mulo"# the system group to run as, not implemented, see d_start for beginning implementation# group=`id -ng "$user"`# the full path to the filename where you store your rtorrent configurationconfig="/home/mulo/.rtorrent.rc"# set of options to run withoptions=""# default directory for screen, needs to be an absolute path#base="/home/${user}"base="/home/mulo"# name of screen sessionsrnname="rtorrent"# file to log to (makes for easier debugging if something goes wrong)logfile="/var/log/rtorrentInit.log"##########################END CONFIGURATION##########################PATH=/usr/bin:/usr/local/bin:/usr/local/sbin:/sbin:/bin:/usr/sbinDESC="rtorrent"NAME=rtorrentDAEMON=$NAMESCRIPTNAME=/etc/init.d/$NAMEcheckcnfg() {   exists=0   for i in `echo "$PATH" | tr ':' '\n'` ; do       if [ -f $i/$NAME ] ; then           exists=1           break       fi   done   if [ $exists -eq 0 ] ; then       echo "cannot find rtorrent binary in PATH $PATH" | tee -a "$logfile" >&2       exit 3   fi   if ! [ -r "${config}" ] ; then         echo "cannot find readable config ${config}. Check that it is there and permissions are appropriate." | tee -a "$logfile" >&2       exit 3     fi     session=`getsession "$config"`     if ! [ -d "${session}" ] ; then       echo "cannot find readable session directory ${session} from config ${config}. Check permissions." | tee -a "$logfile" >&2       exit 3   fi}d_start() { [ -d "${base}" ] && cd "${base}" stty stop undef && stty start undef # robert 20080807 su -c "screen -ls | grep -sq "\.${srnname}:space:" " ${user} || su -c "screen -dm -S ${srnname} 2>&1 1>/dev/null" ${user} | tee -a "$logfile" >&2 su -c "screen -ls | grep -sq "\.${srnname}:space:" " ${user} || su -c "screen -dm -S ${srnname} " ${user}# this works for the screen command, but starting rtorrent below adopts screen session gid# even if it is not the screen session we started (e.g. running under an undesirable gid#su -c "screen -ls | grep -sq "\.${srnname}[[:space:]]" " ${user} || su -c "sg \"$group\" -c \"screen -fn -dm -S ${srnname} 2>&1 1>/dev/null\"" ${user} | tee -a "$logfile" >&2# robert 20080807 su -c "screen -S "${srnname}" -X screen rtorrent ${options} 2>&1 1>/dev/null" ${user} | tee -a "$logfile" >&2su -c "screen -S "${srnname}" -X screen rtorrent ${options}" ${user}}d_stop() {   session=`getsession "$config"`   if ! [ -s ${session}/rtorrent.lock ] ; then       return   fi   pid=`cat ${session}/rtorrent.lock | awk -F: '{print($2)}' | sed "s/[^0-9]//g"`       pid2=`su $user -c 'screen -ls' | awk -F [.] '/[[:digit:]].rtorrent/{print($1)}' | sed "s/[^0-9]//g"`   if ps -A | grep -sq ${pid}.*rtorrent ; then # make sure the pid doesn't belong to another process       kill -s INT ${pid}; kill -s KILL ${pid2}   fi       su $user -c 'screen -wipe'}getsession() {     session=`awk '/^[[:space:]]?session[[:space:]]?=[[:space:]]?/{print($3)}' "$config"`   echo $session}checkcnfgcase "$1" in start)   echo -n "Starting $DESC: $NAME"   d_start   echo "."   ;; stop)   echo -n "Stopping $DESC: $NAME"   d_stop   echo "."   ;; restart|force-reload)   echo -n "Restarting $DESC: $NAME"   d_stop   sleep 1   d_start   echo "."   ;; *)   echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2   exit 1   ;;esacexit 0</pre>Quindi impostiamo il nostro servizio affinché parta all'avvio:<pre># chmod +x /etc/init.d/rtorrent# update-rc.d rtorrent defaults</pre>Per testare che tutto funzioni proviamo ad avviare il demone:<pre>/etc/init.d/rtorrent start</pre>e a collegarci all'interfaccia grafica all'URL ''http://<IpAddressMulo>/rtgui''
''Rtorrent'' dovrà partire all'avvio del ''server''; dobbiamo, dunque, "demonizzarlo" creando il file <tt>/etc/init.d/rtorrent</tt>:
<pre>
#!/bin/sh
### BEGIN INIT INFO
# Provides:      rtorrent
# Required-Start:  $network  
# Required-Stop:  $network  
# Default-Start:  2 3 4 5
# Default-Stop:    0 1 6
# Short-Description: Start rtorrent as a daemon
### END INIT INFO
 
#############
###<Notes>###
#############
# This script depends on screen.
# For the stop function to work, you must set an
# explicit session directory using ABSOLUTE paths (no, ~ is not absolute) in your rtorrent.rc.
# If you typically just start rtorrent with just "rtorrent" on the
# command line, all you need to change is the "user" option.
# Attach to the screen session as your user with  
# "screen -dr rtorrent". Change "rtorrent" with srnname option.
# Licensed under the GPLv2 by lostnihilist: lostnihilist _at_ gmail _dot_ com
##############
###</Notes>###
##############
#######################
##Start Configuration##
#######################
# You can specify your configuration in a different file  
# (so that it is saved with upgrades, saved in your home directory,
# or whateve reason you want to)
# by commenting out/deleting the configuration lines and placing them
# in a text file (say /home/user/.rtorrent.init.conf) exactly as you would
# have written them here (you can leave the comments if you desire
# and then uncommenting the following line correcting the path/filename  
# for the one you used. note the space after the ".".
# . /etc/rtorrent.init.conf
#Do not put a space on either side of the equal signs e.g.
# user = user  
# will not work
# system user to run as
user="mulo"
# the system group to run as, not implemented, see d_start for beginning implementation
# group=`id -ng "$user"`
# the full path to the filename where you store your rtorrent configuration
config="/home/mulo/.rtorrent.rc"
# set of options to run with
options=""
# default directory for screen, needs to be an absolute path
#base="/home/${user}"
base="/home/mulo"
# name of screen session
srnname="rtorrent"
# file to log to (makes for easier debugging if something goes wrong)
logfile="/var/log/rtorrentInit.log"
#######################
###END CONFIGURATION###
#######################
 
PATH=/usr/bin:/usr/local/bin:/usr/local/sbin:/sbin:/bin:/usr/sbin
DESC="rtorrent"
NAME=rtorrent
DAEMON=$NAME
SCRIPTNAME=/etc/init.d/$NAME
checkcnfg() {
exists=0
for i in `echo "$PATH" | tr ':' '\n'` ; do
if [ -f $i/$NAME ] ; then
exists=1
break
fi
done
if [ $exists -eq 0 ] ; then
echo "cannot find rtorrent binary in PATH $PATH" | tee -a "$logfile" >&2
exit 3
fi
if ! [ -r "${config}" ] ; then  
echo "cannot find readable config ${config}. Check that it is there and permissions are appropriate." | tee -a "$logfile" >&2
exit 3  
fi  
session=`getsession "$config"`  
if ! [ -d "${session}" ] ; then
echo "cannot find readable session directory ${session} from config ${config}. Check permissions." | tee -a "$logfile" >&2
exit 3
fi
}
d_start() {
  [ -d "${base}" ] && cd "${base}"
  stty stop undef && stty start undef
  # robert 20080807 su -c "screen -ls | grep -sq "\.${srnname}:space:" " ${user} || su -c "screen -dm -S ${srnname} 2>&1 1>/dev/null" ${user} | tee -a "$logfile" >&2
  su -c "screen -ls | grep -sq "\.${srnname}:space:" " ${user} || su -c "screen -dm -S ${srnname} " ${user}
# this works for the screen command, but starting rtorrent below adopts screen session gid
# even if it is not the screen session we started (e.g. running under an undesirable gid
#su -c "screen -ls | grep -sq "\.${srnname}[[:space:]]" " ${user} || su -c "sg \"$group\" -c \"screen -fn -dm -S ${srnname} 2>&1 1>/dev/null\"" ${user} | tee -a "$logfile" >&2
# robert 20080807 su -c "screen -S "${srnname}" -X screen rtorrent ${options} 2>&1 1>/dev/null" ${user} | tee -a "$logfile" >&2
su -c "screen -S "${srnname}" -X screen rtorrent ${options}" ${user}
}
d_stop() {
session=`getsession "$config"`
if ! [ -s ${session}/rtorrent.lock ] ; then
return
fi
pid=`cat ${session}/rtorrent.lock | awk -F: '{print($2)}' | sed "s/[^0-9]//g"`
        pid2=`su $user -c 'screen -ls' | awk -F [.] '/[[:digit:]].rtorrent/{print($1)}' | sed "s/[^0-9]//g"`
if ps -A | grep -sq ${pid}.*rtorrent ; then # make sure the pid doesn't belong to another process
kill -s INT ${pid}; kill -s KILL ${pid2}
fi
        su $user -c 'screen -wipe'
}
getsession() {  
session=`awk '/^[[:space:]]?session[[:space:]]?=[[:space:]]?/{print($3)}' "$config"`
echo $session
}
checkcnfg
case "$1" in
  start)
echo -n "Starting $DESC: $NAME"
d_start
echo "."
;;
  stop)
echo -n "Stopping $DESC: $NAME"
d_stop
echo "."
;;
  restart|force-reload)
echo -n "Restarting $DESC: $NAME"
d_stop
sleep 1
d_start
echo "."
;;
  *)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 1
;;
esac
exit 0
</pre>
 
Quindi impostiamo il nostro servizio affinché parta all'avvio:
 
<pre>
# chmod +x /etc/init.d/rtorrent
# update-rc.d rtorrent defaults
</pre>
 
Per testare che tutto funzioni proviamo ad avviare il demone:
 
<pre>/etc/init.d/rtorrent start</pre>
 
e a collegarci all'interfaccia grafica all'URL ''http://<IpAddressMulo>/rtgui''
 
===Specifiche===
===Specifiche===
*Porte da aprire ** 6881-6999 (tcp)** 6881 (udp)*Limiti banda** download    75 KiB** upload    5 KiB*Connessione tramite webUI all'indirizzo http://<IpAddressMulo>/rtgui[[Immagine:rtgui.jpg]]
*Porte da aprire ** 6881-6999 (tcp)** 6881 (udp)*Limiti banda** download    75 KiB** upload    5 KiB*Connessione tramite webUI all'indirizzo http://<IpAddressMulo>/rtgui[[Immagine:rtgui.jpg]]
909

contributi

Menu di navigazione