How to start, stop and restart rtorrent?

63

Solution 1

To start rtorrent, just press Ctrl+Alt+T on your keyboard to open Terminal. When it opens, run the command(s) below:

rtorrent

To stop Ctrl+D To quit Ctrl+q

The above commands you do after pressing Enter, in the rtorrent window.

For more information see the output of:

rtorrent -h

and/or see Using rtorrent like a pro

Solution 2

The accepted answer is correct but does not specify how to perform a "safe" shutdown of the rtorrent service with a systemctl service script.

Most existing answers or scripts "kill" either the screen session or the rtorrent process itself. In doing so, they send a SIGINT (2)or SIGQUIT (3) signal which stops/kills the rtorrent process. The drawback is that typically the lock-file of rtorrent is not deleted because rtorrent was not shut down properly. Consequently, the next start of rtorrent would fail because of the persistent lock file.

Taking a look at the source code of rtorrent shows that it expects a SIGTERM (15). Hence, considering a systemctl service script the stop command could look like:

ExecStop=/usr/bin/kill -s 15 \`pidof rtorrent`

If pidof is not available you can also use something like:

ps -A | grep "rtorrent" | awk '{print $1}'
  • ps list the current processes
  • grep extracts the rtorrent process particulars
  • awk selects the pid and displays it to stdout

In case you need to wait until shutdown is complete, you can use killall -w. Note that:

killall may wait forever if the signal was ignored, had no effect, or if the process stays in zombie state (source: man killall).

Share:
63

Related videos on Youtube

Alpaslan
Author by

Alpaslan

Updated on September 18, 2022

Comments

  • Alpaslan
    Alpaslan almost 2 years

    Say, I have a string like the first line and I need to convert it to the second line.

    "English       ,Spanish         ,Eastern Japanese          "
    "English,Spanish,Eastern Japanese"
    

    As you see, there are several whitespaces before commas, but each element may have spaces between its variables, too (like "Eastern Japanese"). So, all I need is to delete multiple whitespaces coming before commas. I can trim the last occuring whitespaces before using replaceAll() method, that is no problem.

    • Admin
      Admin almost 11 years
      have you tried sudo service start rtorrent?
    • Admin
      Admin almost 11 years
      sudo service rtorrent start that is, but yes, I've tried that. It just outputs rtorrent: unrecognized service. If I write sudo service rto and press tab it completes to rtorrentInit.sh. I don't know what that is, but I remember (from a guide that is long gone far off into the interwebs) that I wrote rtorrent and stop, but not in which order and whether there is another word in between. I did not write rtorrentInit.sh that first time.
    • Admin
      Admin almost 11 years
      Yeah, Thats what I meant. Have a look here: Ubuntu 12.04 LTS Dedicated Server rTorrent. The last 7-8 steps are about installing and starting rtorrent. Maybe it can shed some light.
    • Admin
      Admin almost 11 years
      I've already read that from top to bottom. But thank you anyways. For the moment I can get around with screen and just jump into rtorrent and quit from in there, but I'll leave this thread open if anyone happens to know the answer.
  • lindhe
    lindhe almost 11 years
    This is the correct answer. I am afraid that I might have mixed up the instructions for this program with some other program, so exactly what I was looking for probably does not exist. I apologize for the trouble, but hope someone else will have use of this thread.
  • Alpaslan
    Alpaslan almost 9 years
    Works like a charm. Much appreciated
  • Wiktor Stribiżew
    Wiktor Stribiżew almost 9 years
    Like question, like answer :)
  • David Foerster
    David Foerster almost 8 years
    kill -s 15 `pidof rtorrent` could be more simply killall rtorrent (15 or SIGTERM is the default signal sent by kill and killall).
  • David Foerster
    David Foerster almost 8 years
    Also, where in signal_handler.cc do you see that rtorrent expects SIGTERM to terminate itself gracefully? I only see signal generic signal handler management code but no actual signal handlers.
  • Cbhihe
    Cbhihe almost 8 years
    Should not that be: /usr/bin/kill -n 15 `pidof rtorrent` or /usr/bin/kill -s SIGTERM \$(pidof rtorrent) ? You're mixing up signal names and numbers. -- From man kill, kill -l will actually give you the list of signal names and corresponding signal codes. -- Also note that although back ticks, as in `cmd`, are not officially deprecated, I have read that $(cmd) is actually favored as clearer.
  • Zanna
    Zanna almost 7 years
    Don't forget about pgrep :) The command pgrep rtorrent returns just the PID, so no need for piping or parsing
  • Skippy le Grand Gourou
    Skippy le Grand Gourou about 5 years
    It's worth mentioning that it can take a while for rtorrent to close all files and exit after Ctrl+q — it doesn't mean it wasn't the right combination.