Run a torrent client + Plex Media Server as “services”

daemonsplexsoftware-recommendationtorrent

I'm using an old iMac as a torrent client & Plex Media Server.

But I would like those to run as "services", i.e., not as part of a User account, and without having to log in.

Best Answer

You can use launchd, tmux and this script to launch rTorrent as a daemon.

This post describes how to install rTorrent and run it as a daemon using tmux. First, install software:

$brew install rtorrent --with-xmlrpc-c
$brew install tmux

Parameter –with-xmlrpc-c is needed to use GUI clients with rTorrent. rTorrent needs terminal to run. We provide virtual terminal using tmux. To autostart rTorrent create launchd sript and place it to

/Library/LaunchAgents/rtorrent.plist

The script:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>rtorrent</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/bin/tmux</string>
        <string>new-session</string>
        <string>-s</string>
        <string>rtorrent</string>
        <string>-d</string>
        <string>rtorrent</string>
    </array>
    <key>KeepAlive</key>
    <true/>
</dict>
</plist>

Load script:

$sudo launchctl load -w /Library/LaunchAgents/rtorrent.plist
$launchctl list | grep rtorrent

If all is ok you will see something like this:

- 1 rtorrent
4868 - 0x7f872252ff90.anonymous.rtorrent

Now you can attach to tmux session and start using rTorrent:

$tmux attach-session -t rtorrent

To restart script unload it and load again:

$sudo launchctl unload -w /Library/LaunchAgents/rtorrent.plist
$sudo launchctl load -w /Library/LaunchAgents/rtorrent.plist

To view launchd logs run:

$sudo launchctl log level debug
$tail -f /var/log/system.log | grep launchd

The rTorrent installation is over, now you can install GUI client. There is free client for Mac OS X called Nativa. It not very good, but you can try it. To use any client you need to add this in your .rtorrent.rc:

scgi_port = 127.0.0.1:5000

Source