Automatyczny start rtorrent'a w screen

Instalacja i konfiguracja oprogramowania sieciowego.
dariuszpod
Piegowaty Guziec
Piegowaty Guziec
Posty: 7
Rejestracja: 10 cze 2009, 16:02
Płeć: Mężczyzna
Wersja Ubuntu: 9.04
Środowisko graficzne: GNOME

Automatyczny start rtorrent'a w screen

Post autor: dariuszpod »

Cześć Wszystkim.
Chciałbym aby rtorrent uruchamiał się wraz ze startem komputera w programie screen.
Dodałem do /etc/inid.d skrypt, który powinien to teoretycznie uczynić. Niestety rtorrent nie startuje. Skrypt ten uruchamiałem ręcznie z konsoli ./rtorrent start niestety pojawia się monit o hasło. Wpisuje hasło superużytkownika i okazuje się że jest ono złe i wyświetla się komunikat o braku dostępu. Niewiem tylko czemu.
Kiedyś w SuSe robiłem podobnie i nie było problemów. Rtorrent ładnie się uruchamiał w tle. Potem screen -r rtorrent i już go miałem. Może ktoś coś podpowie. Coś mi się wydaje że chodzi o to "su" i jakieś hasło ale błądzę, błądzę i nic nie mogę wykombinować.
Poniżej skrypt:

Kod: Zaznacz cały

#!/bin/sh
#############
###<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="darek"

# 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="`su -c 'echo $HOME' $user`/.rtorrent.rc"

# set of options to run with
options=""

# default directory for screen, needs to be an absolute path
base="`su -c 'echo $HOME' $user`"

# 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
  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
  # 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
  su -c "screen -S "${srnname}" -X screen rtorrent ${options} 2>&1 1>/dev/null" ${user} | tee -a "$logfile" >&2
}

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"`
    if ps -A | grep -sq ${pid}.*rtorrent ; then # make sure the pid doesn't belong to another process
        kill -s INT ${pid}
    fi
}

getsession() { 
    session=`cat "$1" | grep "^[[:space:]]*session[[:space:]]*=" | sed "s/^[[:space:]]*session[[:space:]]*=[[:space:]]*//" `
    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
Awatar użytkownika
mario_7
Administrator
Administrator
Posty: 8656
Rejestracja: 30 sie 2006, 13:11
Płeć: Mężczyzna
Wersja Ubuntu: 20.04
Środowisko graficzne: GNOME
Architektura: x86_64

Re: Automatyczny start rtorrent'a w screen

Post autor: mario_7 »

Hasło nie jest prawidłowe bo pewnie nie masz konta root, a korzystasz z polecenia su, które się do niego odwołuje. Rozwiązanie - przed su dodaj sudo - wtedy hasło Twojego użytkownika zadziała.

Różnice między su a sudo są opisane w wielu miejscach w Internecie - bez problemu je znajdziesz, jeśli Cię to interesuje. Generalnie w Ubuntu używa się sudo.
dariuszpod
Piegowaty Guziec
Piegowaty Guziec
Posty: 7
Rejestracja: 10 cze 2009, 16:02
Płeć: Mężczyzna
Wersja Ubuntu: 9.04
Środowisko graficzne: GNOME

Re: Automatyczny start rtorrent'a w screen

Post autor: dariuszpod »

No tak ale przecież ja chcę aby rtorrent startował automatycznie więc jak mam zmienić ten skrypt. Czy mam dopisać przed su sudo.
Naprzykład w skrypcie jest
# the full path to the filename where you store your rtorrent configuration
config="`su -c 'echo $HOME' $user`/.rtorrent.rc"

to mam zmienić na:
# the full path to the filename where you store your rtorrent configuration
config="`sudo su -c 'echo $HOME' $user`/.rtorrent.rc"

A jak skrypt będzie startował to co mam podać hasło. To bez sensu.
Awatar użytkownika
mario_7
Administrator
Administrator
Posty: 8656
Rejestracja: 30 sie 2006, 13:11
Płeć: Mężczyzna
Wersja Ubuntu: 20.04
Środowisko graficzne: GNOME
Architektura: x86_64

Re: Automatyczny start rtorrent'a w screen

Post autor: mario_7 »

To chyba ze zmęczenia już... Przyjrzałem się lepiej temu skryptowi i to jednak nie o to chodzi. Tzn. tak, to kwestia su, ale w innym kontekście. Zmieniłem polecenia z su na wariant z sudo, ale nie gwarantuję, że to działa. Na oko powinno. ;)

Kod: Zaznacz cały

#!/bin/sh
#############
###<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="darek"

# 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="`sudo -u $user echo $HOME`/.rtorrent.rc"

# set of options to run with
options=""

# default directory for screen, needs to be an absolute path
base="`sudo -u $user echo $HOME`"

# 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
  sudo -u ${user} screen -ls | grep -sq "\.${srnname}[[:space:]]" || sudo -u ${user} screen -dm -S ${srnname} 2>&1 1>/dev/null | tee -a "$logfile" >&2
  # 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
  sudo -u ${user} screen -S "${srnname}" -X screen rtorrent ${options} 2>&1 1>/dev/null | tee -a "$logfile" >&2
}

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"`
    if ps -A | grep -sq ${pid}.*rtorrent ; then # make sure the pid doesn't belong to another process
        kill -s INT ${pid}
    fi
}

getsession() {
    session=`cat "$1" | grep "^[[:space:]]*session[[:space:]]*=" | sed "s/^[[:space:]]*session[[:space:]]*=[[:space:]]*//" `
    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
kasjo
Serdeczny Borsuk
Serdeczny Borsuk
Posty: 175
Rejestracja: 31 paź 2007, 16:38
Płeć: Mężczyzna
Wersja Ubuntu: 11.10
Środowisko graficzne: KDE Plasma
Architektura: x86

Re: Automatyczny start rtorrent'a w screen

Post autor: kasjo »

Ja to robię w ten sposób:
W cronie (dla zwykłego użytkownika) dodaje wpis:
@reboot /home/kasjo/skrypty/skrypt.sh
gdzie skrypt.sh będzie wyglądał mniej więcej tak:

Kod: Zaznacz cały

#!/bin/bash
screen -dmSL torrent
screen -S torrent -X screen rtorrent
Wiem, że ten "screen" po "-X" jest jakby nie na miejscu ale w inny sposób nie mogłem zmusić do odpalenia czegokolwiek na "zdetachowanym" screenie

edit:
Właśnie przejrzałem ten wasz skrypt i tam też tak samo to uruchamiają więc chyba tak ma być :)
dariuszpod
Piegowaty Guziec
Piegowaty Guziec
Posty: 7
Rejestracja: 10 cze 2009, 16:02
Płeć: Mężczyzna
Wersja Ubuntu: 9.04
Środowisko graficzne: GNOME

Re: Automatyczny start rtorrent'a w screen

Post autor: dariuszpod »

Witam ponownie.
Udało mi się po zmianie su na sudo w skrypcie odpalić przy starcie kompa rtorrenta w screenie.
Musiałem tylko plik konfiguracyjny .rtorrent.rc przekopiować do głównego katalogu /
Może ktoś podpowie czemu nie został użyty plik z katalogu /home/darek/.rtorrent.rc?
Robson92
Piegowaty Guziec
Piegowaty Guziec
Posty: 2
Rejestracja: 16 kwie 2012, 17:45
Płeć: Mężczyzna
Wersja Ubuntu: 12.04
Środowisko graficzne: Brak
Architektura: x86_64
Kontakt:

Re: Automatyczny start rtorrent'a w screen

Post autor: Robson92 »

Witam wszystkich.
Mam bardzo podobny problem. Zamieniłem skrypt /etc/init.d/rtorrent na ten zmieniony przez mario_7 (+ oczywiście podmieniłem swoją nazwę użytkownika). Można go ręcznie bez podawania hasła uruchomić po zalogowaniu się i nie wyrzuca błędów. Niestety skrypt wciąż nie uruchamia się przy starcie systemu.
Awatar użytkownika
mario_7
Administrator
Administrator
Posty: 8656
Rejestracja: 30 sie 2006, 13:11
Płeć: Mężczyzna
Wersja Ubuntu: 20.04
Środowisko graficzne: GNOME
Architektura: x86_64

Re: Automatyczny start rtorrent'a w screen

Post autor: mario_7 »

Jakiś ślad w logach co się z nim dzieje podczas startu systemu?
Robson92
Piegowaty Guziec
Piegowaty Guziec
Posty: 2
Rejestracja: 16 kwie 2012, 17:45
Płeć: Mężczyzna
Wersja Ubuntu: 12.04
Środowisko graficzne: Brak
Architektura: x86_64
Kontakt:

Re: Automatyczny start rtorrent'a w screen

Post autor: Robson92 »

jeżeli chodzi o log rtorrenta to przy starcie systemu nic do niego nie dopisuje, a jeżeli ręcznie go uruchomię to wtedy dopisuje komunikat o istniejącej sesji

Edit: Ok już nie ważne. Wszystkiemu winne było szyfrowanie partycji. Po usunięcia szyfrowania wszystko działa jak należy.
ODPOWIEDZ

Wróć do „Sieci, serwery, Internet”

Kto jest online

Użytkownicy przeglądający to forum: Obecnie na forum nie ma żadnego zarejestrowanego użytkownika i 1 gość