Avviare rtorrent al boot su FreeBSD

26 08 2008

rtorrent è un client BitTorrent con interfaccia testuale molto leggero che può essere lanciato in background con l’ausilio di screen o dtach. Persino la wiki ufficiale del progetto suggerisce esplicitamente come si possa avviare il programma automaticamente al boot su un sistema GNU/Linux.

Sia rtorrent che screen/dtach funzionano perfettamente anche su FreeBSD: manca però un script di init funzionante.

Quel che segue è un tentativo in tal senso che dovrebbe soddisfare le esigenze di un buon numero di utenti; le differenze rispetto ai suoi omologhi per GNU/Linux riguardano principalmente i parametri di lancio: ritengo che uno script di init non debba essere un secondo file di configurazione, che, nella fattispecie, è .rtorrent.rc.

Segue il contenuto dello script. Per utilizzarlo, piazzatelo in /usr/local/etc/rc.d/rtorrent e dategli i permessi di esecuzione con chmod +x /usr/local/etc/rc.d/rtorrent.

#!/bin/sh
#
# rtorrent RCng startup script
# by Emanuele Cipolla (mail at emanuelecipolla dot net)
# Shamelessly ripped off the aMule startup script by Gabriele Cecchetti (amule.org forum)
# 

# PROVIDE: rtorrent
# REQUIRE: NETWORKING SERVERS
# BEFORE: DAEMON
# KEYWORD: shutdown

#
# Add the following lines to /etc/rc.conf to enable rtorrent at startup
# rtorrent (bool): Set to "NO" by default.
#                Set it to "YES" to enable rtorrent
# rtorrent_user (str): Set to user running rtorrent
#                    (default 'rtorrent')
# rtorrent_home (str): Set to home directory of user running rtorrent
#                    (default /home/${rtorrent_user})

. /etc/rc.subr

name="rtorrent"
rcvar=`set_rcvar`

load_rc_config $name

[ -z "$rtorrent_enable" ] && rtorrent_enable="NO"
[ -z "$rtorrent_user" ] && rtorrent_user="rtorrent"
[ -z "$rtorrent_home" ] && rtorrent_home="/home/${rtorrent_user}"

required_dirs=${rtorrent_home}
required_files="${rtorrent_home}/.rtorrent.rc"

start_cmd="${name}_start"
stop_cmd="${name}_stop"

rtorrent_start()
{
        if [ ! -f /var/run/${name}.run ]
        then
      cd ${rtorrent_home}
       su ${rtorrent_user} -c "/usr/local/bin/screen -dmS rtorrent_init /usr/local/bin/rtorrent"
      touch /var/run/${name}.run
          echo "Started ${name}."
          echo `date` : "Started ${name}." >> /var/log/${name}.log
        else
          echo "${name} seems to be already running -- remove /var/run/${name}.run manually if needed."
        fi
}

rtorrent_stop()
{
        if [ -f /var/run/${name}.run ]
        then
          killall -INT $(echo -n 'ps aux | grep rtorrent | grep -v rtorrent_init') 2>>/var/log/${name}.log >>/var/log/${name}.log
          rm -f /var/run/${name}.run
          echo "Stopped ${name}."
          echo `date` : "Stopped ${name}." >> /var/log/${name}.log
        else
          echo "${name} doesn't seem to be running -- create /var/run/${name}.run if needed."
        fi
}

run_rc_command "$1"

Azioni

Informazione

Lascia un commento

Puoi usare questi tag : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>