ruTorrent <--> rTorrent, UNIX socket

saroos1

Member
May 25, 2018
718
0
16
I'm trying to use a UNIX socket for communication between rTorrent and ruTorrent, rather than a TCP port. To be clear, it currently works using these config values:

Code: (.rtorrent.rc)
scgi_port = 127.0.0.1:5000
Code: (ruTorrent config.php)
$scgi_port = 5000;
$scgi_host = "127.0.0.1";

I am running nginx with php5-fpm, and my nginx site has this block:
Code:
location ~ \.php$ {
try_files $uri =404;

fastcgi_pass php5-fpm-sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_param HTTPS on;
}
Then I have a file /etc/nginx/conf.d/php-sock.conf:
Code:
upstream php5-fpm-sock {
server unix:/var/run/php5-fpm.soc;
}
My understanding is that this passes any php files through to php-fpm using FastCGI. Under my web root is a rutorrent directory, and I have an nginx location block used to set up basic HTTP auth - this seems to work fine. I've seen a lot of talk about rpc plugin, etc. and I have not configured any of these to my knowledge, but in my nginx log file I see listed POST /rutorrent/plugins/httprpc.

Anyway, to try a unix socket I've set it up like this:

.rtorrent.rc:
Code:
scgi_local = /var/run/rtorrent/rtorrent-scgi.soc
ruTorrent config.php:
Code:
$scgi_port = 0;
$scgi_host = "unix:///var/run/rtorrent/rtorrent-scgi.soc";
But rtorrent gives the usual message 'No connection to rtorrent, check scgi_port and scgi_host' etc. I checked that rtorrent had created the socket and then tried adjusting the permissions on it and the /var/run/rtorrent directory but the error persisted. Even setting rwx for everyone did not work.

So why can't rutorrent find the socket to communicate with rtorrent? Like I said, works fine using a port.

Thanks in advance.
 

saroos1

Member
May 25, 2018
718
0
16
I've found a few other threads with the same problem, but none of them managed to help me at all sad.gif
 

saroos1

Member
May 25, 2018
718
0
16
Maybe serverfault would be a better fit for our question than stackoverflow - it's not really a programming question.

edit: progress! if I create the socket as /tmp/rpc.socket and make it readable, writable and executable by anyone then it works. I don't want to do this for obvious reasons smiley.gif

The default permissions are rwxrwxr-x which don't work. Adding www-data and rtorrent to the same group, and then making that group the owner of the file doesn't work. HOWEVER making www-data the owner (with the default permissions) of the file works. So what gives? I don't really want the socket to reside here with permissions that could potentially make rtorrent vulnerable.
 

saroos1

Member
May 25, 2018
718
0
16
.rtorrent.rc:

Code:
directory =
session =

encoding_list = UTF-8

port_range = 55950-55950
port_random = no

check_hash = no

use_udp_trackers = no
dht = disable
peer_exchange = no

# watch a directory for new torrents and stop those that have been deleted
schedule = watch_directory,5,5,load_start=
schedule = untied_directory,5,5,stop_untied=

# close torrents when diskspace is low
schedule = low_diskspace,5,60,close_low_diskspace=100M

scgi_port = 127.0.0.1:5000
#scgi_local = /tmp/rpc.socket

encryption = allow_incoming,enable_retry,try_outgoing

rutorrent config.php:
Code:
<?php
// configuration parameters

// for snoopy client
@define('HTTP_USER_AGENT', 'Mozilla/5.0 (Windows NT 6.0; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0', true);
@define('HTTP_TIME_OUT', 30, true); // in seconds
@define('HTTP_USE_GZIP', true, true);
$httpIP = null; // IP string. Or null for any.

@define('RPC_TIME_OUT', 5, true); // in seconds

@define('LOG_RPC_CALLS', false, true);
@define('LOG_RPC_FAULTS', true, true);

// for php
@define('PHP_USE_GZIP', false, true);
@define('PHP_GZIP_LEVEL', 2, true);

$schedule_rand = 10; // rand for schedulers start, +0..X seconds

$do_diagnostic = true;
$log_file = '/tmp/rutorrent_errors.log'; // path to log file (comment or leave blank to disable logging)

$saveUploadedTorrents = true; // Save uploaded torrents to profile/torrents directory or not
$overwriteUploadedTorrents = false; // Overwrite existing uploaded torrents in profile/torrents directory or make unique name

$topDirectory = ''; // Upper available directory. Absolute path with trail slash.
$forbidUserSettings = false;

$scgi_port = 5000;
$scgi_host = "127.0.0.1";

// For web->rtorrent link through unix domain socket
// (scgi_local in rtorrent conf file), change variables
// above to something like this:
//
//$scgi_port = 0;
//$scgi_host = "unix:///tmp/rpc.socket";

$XMLRPCMountPoint = "/RPC2"; // DO NOT DELETE THIS LINE!!! DO NOT COMMENT THIS LINE!!!

$pathToExternals = array(
"php" => '/usr/bin/php', // Something like /usr/bin/php. If empty, will be found in PATH.
"curl" => '/usr/bin/curl', // Something like /usr/bin/curl. If empty, will be found in PATH.
"gzip" => '/bin/gzip', // Something like /usr/bin/gzip. If empty, will be found in PATH.
"id" => '/usr/bin/id', // Something like /usr/bin/id. If empty, will be found in PATH.
"stat" => '/usr/bin/stat', // Something like /usr/bin/stat. If empty, will be found in PATH.
);

$localhosts = array( // list of local interfaces
"127.0.0.1",
"localhost",
);

$profilePath = '../share'; // Path to user profiles
$profileMask = 0777; // Mask for files and directory creation in user profiles.
// Both Webserver and rtorrent users must have read-write access to it.
// For example, if Webserver and rtorrent users are in the same group then the value may be 0770.

$tempDirectory = null; // Temp directory. Absolute path with trail slash. If null, then autodetect will be used.
Those are the working setups - the socket code is commented out.
 

lisas4567

Member
May 25, 2018
773
0
16
ok I see we have the same thing smiley.gif I'll watch them on another forum and if I find the solution I'll post the answer here
 

peshua19

Member
May 25, 2018
897
0
16
schedule = scgi_permission,0,0,"execute.nothrow=chmod,0770,/…/.scgi_local"

And possibly a similar chgrp to set it to a shared group.
 

saroos1

Member
May 25, 2018
718
0
16
This changes the permissions successfully, but I can't get it to change the group. Changing the group manually afterwards doesn't make rutorrent work.

Not sure why the schedule command is being used here? Either way, I tried making something similar up:
Code:
schedule = scgi_group,0,0,"execute.nothrow=chgrp,rtorrent-nginx,/home/rtorrent/scgi.socket"
but I have no documentation so no idea how to structure that. Likewise, I tried this:
Code:
execute = chmod,0770,/home/rtorrent/scgi.socket
execute = chgrp,rtorrent-nginx,/home/rtorrent/scgi.socketThe chmod worked but the chgrp did not. Opening a bash shell as the rtorrent user and typing:
Code:
chgrp rtorrent-nginx /home/rtorrent/scgi.socketChanges the group but, as I said above, this doesn't fix rutorrent.