bsd Avviare rtorrent al boot su FreeBSDAvviare rtorrent al boot su FreeBSD

Di Emanuele Cipolla | Ago 26, 2008
Stampa questo post Stampa questo post Articolo originale

rtorrent è un client BitTorrent con interfaccia testuale molto leggero. rtorrent può essere lanciato in background con l’ausilio di screen o dtach, e 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 "screen -dmS rtorrent_init 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"

Tags: FreeBSD

Post correlati

Lascia un commento

Se vuoi inserire un commento, per favore completa il form sottostante.

Nome (obbligatorio)

Email (obbligatorio)

Sito Web

Commenti

© 2008 - 2009 Tuttolinux - novità ed articoli dal mondo del pinguino !
Tutti i contenuti © dei rispettivi autori. Leggi questo per ulteriori informazioni.
Creative Commons LicenseIl contenuto di questo sito web è pubblicato sotto una Licenza Creative Commons.

Warning: stristr() [function.stristr]: Empty delimiter in /home/.nine/luckylinux/tutto-linux.com/wp-content/plugins/wassup/wassup.php on line 2093