LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices

Reply
 
Search this Thread
Old 02-17-2008, 02:58 PM   #1
imagineaxion
Member
 
Registered: Sep 2004
Location: Epsom, Surrey
Distribution: Ubuntu & Mac OS X
Posts: 141

Rep: Reputation: 16
screen & rtorrent init.d start


Hi

I have recently setup rtorrent to run on my Ubuntu server.
I have set it up to automatically start on boot which is now working fine.
rtorrent runs in screen and this all boots up and starts 100% as I want it to.

The problem is when I for example make some changes to the config file and want to restart the service

When I run the command
Code:
/etc/init.d/rtorrentInit stop
It stops the screen and rtorrent which is great.

The problem is trying to restart it. If I run
Code:
/etc/init.d/rtorrentInit start
nothing happens

I then have to reboot the server for screen and rtorrent to start again as they do automatically on boot

Now I am sure you can see how this can be a problem as it is a server and I really do not need to be restarting my it every 5 minutes while making changes

Your help is much anticipated and will be much appreciated

Thanks
G
 
Old 02-17-2008, 07:17 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,485
Blog Entries: 54

Rep: Reputation: 2902Reputation: 2902Reputation: 2902Reputation: 2902Reputation: 2902Reputation: 2902Reputation: 2902Reputation: 2902Reputation: 2902Reputation: 2902Reputation: 2902
Quote:
Originally Posted by imagineaxion View Post
If I run
Code:
/etc/init.d/rtorrentInit start
nothing happens
Maybe posting the contents of your rtorrentInit script could help people make sense of it?
 
Old 02-17-2008, 08:16 PM   #3
Mephisto
Member
 
Registered: Oct 2002
Location: Washington D.C, USA
Distribution: Slack 12, Etch, Gutsy
Posts: 453

Rep: Reputation: 30
also try and reattach the screen and see if there is any messages there:

Code:
screen -ls
to list all detached screens. Assuming there is only one
Code:
screen -r
to reattach it.

At a guess your stop script is stopping rtorrent but not terminating the screen. Then when you try to start it again it fails because there is already a screen of that name.
 
Old 02-18-2008, 02:03 PM   #4
imagineaxion
Member
 
Registered: Sep 2004
Location: Epsom, Surrey
Distribution: Ubuntu & Mac OS X
Posts: 141

Original Poster
Rep: Reputation: 16
Hi

Thanks for the reply.

Been at work and unable to reply

OK, so here is the script file from init.d

Code:
#!/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=torrnt

# 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/torrnt/.rtorrent.rc

# set of options to run with
options=""

# default directory for screen, needs to be an absolute path
base=/home/torrnt/

# name of screen session
srnname="srntorrent"

# 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
Hope you can see the problem from this

Thanks again!
G

Last edited by imagineaxion; 02-18-2008 at 02:05 PM.
 
Old 02-18-2008, 04:39 PM   #5
imagineaxion
Member
 
Registered: Sep 2004
Location: Epsom, Surrey
Distribution: Ubuntu & Mac OS X
Posts: 141

Original Poster
Rep: Reputation: 16
Mephisto

You could be right. If that is the case? How do I get the stop command to kill both.

I am not 100% sure if this is the case and I am unable to test it at this stage as I can't risk needed to reboot.
Should have a chance tomorrow.

In the mean time any suggestions on the script I posted and how I could get them both to stop if this is the case would be much appreciated

Thanks
G
 
Old 02-18-2008, 07:33 PM   #6
Mephisto
Member
 
Registered: Oct 2002
Location: Washington D.C, USA
Distribution: Slack 12, Etch, Gutsy
Posts: 453

Rep: Reputation: 30
Well based on the script it looks like it reuses the screen if it exists so you should be fine there. I would need to install rtorrent to try and decipher the problem, I will try tomorrow night on a VM. Sorry I can not be faster, but I did not bring my VMs with me tonight and do not want to install rtorrent on my main laptop.

Anyway a few notes:
- the init script does use a named screen (srntorrent) running as the user torrnt
- init logs are located at /var/log/rtorrentInit.log


First things first, when you start and stop the rtorrent do you use
Code:
/etc/init.d/rtorrentInit start|stop
or
Code:
sudo/etc/init.d/rtorrentInit start|stop
if you are not doing a sudo, are you sure rtorrent is being stopped? It is set to run as a specific user so I would not expect a different normal user to be able to stop it.

If you are using sudo try:
Code:
tail -n20 /var/log/rtorrentInit.log
and see if you spot any obvious errors.

you could try
Code:
screen -r srntorrent
and look around but based on the script I do not think you will see anything there. Never know though.
 
Old 02-19-2008, 06:22 AM   #7
imagineaxion
Member
 
Registered: Sep 2004
Location: Epsom, Surrey
Distribution: Ubuntu & Mac OS X
Posts: 141

Original Poster
Rep: Reputation: 16
Hi Mephisto

I had a look in the log files but there is nothing useful in there. In fact I think there is nothing in their since I first starting setting this up and had some permission problems accessing the .rtorrent.rc file.

I will get a snap of this later anyway to make sure.

Quote:
First things first, when you start and stop the rtorrent do you use

Code:
/etc/init.d/rtorrentInit start|stop

or

Code:
sudo/etc/init.d/rtorrentInit start|stop
I have been using sudo

I have also checked to make sure that they are no longer running using
ps -ef | grep torrent

This actually shows if either rtorrent or the screen (srntorrent) are running
I believe (will confirm tonight) both are killed with the command
Code:
sudo /etc/init.d/rtorrentInit stop
 
Old 02-19-2008, 03:20 PM   #8
imagineaxion
Member
 
Registered: Sep 2004
Location: Epsom, Surrey
Distribution: Ubuntu & Mac OS X
Posts: 141

Original Poster
Rep: Reputation: 16
Hi

Ahh OK...

When I use the command
Code:
sudo /etc/init.d/rtorrentInit stop
it does just stop rtorrent and using the command
Code:
sudo /etc/init.d/rtorrentInit start
does bring it back up

Think I may have been using the kill command to end screen as well thinking I needed to and expecting the init script to create a new screen session.

So why is it that I cannot start it if I kill of screen. Should it not just create a new one?

Thanks
G
 
Old 04-19-2008, 01:32 PM   #9
onepostonly
LQ Newbie
 
Registered: Apr 2008
Posts: 6

Rep: Reputation: 0
Try

Code:
/etc/init.d/rtorrentInit stop
screen -wipe
/etc/init.d/rtorrentInit start
The "screen -wipe" part might be just what you need, it removes destroyed sessions

Last edited by onepostonly; 04-19-2008 at 01:36 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Starting screen + rtorrent at boot Per M. Linux - Software 4 09-28-2007 09:16 AM
howto start X bypassing the login screen? & related Q's sharathg786 Fedora 1 03-17-2007 06:59 AM
Dynebolic HDD start & screen resolution broknindarkagain Linux - Newbie 1 05-12-2006 06:53 AM
add screen / screen init not found for device 0 jamaso Slackware 5 12-29-2002 05:46 PM
INIT problem, won't start x bulliver Linux - General 7 11-06-2002 11:42 PM


All times are GMT -5. The time now is 12:01 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration