首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将rtorrent作为系统服务在专用用户下运行?

如何将rtorrent作为系统服务在专用用户下运行?
EN

Unix & Linux用户
提问于 2021-05-27 06:13:01
回答 2查看 3.3K关注 0票数 3

我试图让rtorrent作为一个systemd service运行,但是服务没有启动。这是配置文件和我能得到的任何日志。如果你需要的话,询问更多的信息。我在跑步:

代码语言:javascript
复制
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.2 LTS
Release:        20.04
Codename:       focal
代码语言:javascript
复制
$ systemctl status rtorrent
● rtorrent.service - rTorrent
     Loaded: loaded (/etc/systemd/system/rtorrent.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Thu 2021-05-27 08:52:43 EEST; 5min ago
    Process: 20199 ExecStart=/usr/bin/tmux new-session -d -P -s rt -n rtorrent /usr/bin/rtorrent (code=exited, status=0/SUCCESS)
    Process: 20205 ExecStop=/usr/bin/tmux send-keys -t rt:rtorrent C-q (code=exited, status=1/FAILURE)
   Main PID: 20201 (code=exited, status=0/SUCCESS)

May 27 08:52:43 $MACHINE systemd[1]: Starting rTorrent...
May 27 08:52:43 $MACHINE tmux[20199]: rt:
May 27 08:52:43 $MACHINE systemd[1]: Started rTorrent.
May 27 08:52:43 $MACHINE tmux[20205]: no server running on /tmp/tmux-110/default
May 27 08:52:43 $MACHINE systemd[1]: rtorrent.service: Control process exited, code=exited, status=1/FAILURE
May 27 08:52:43 $MACHINE systemd[1]: rtorrent.service: Failed with result 'exit-code'.

配置文件..。

代码语言:javascript
复制
[Unit]
Description=rTorrent
Requires=network.target local-fs.target

[Service]
Type=forking
KillMode=none
User=rt
Group=adm
ExecStart=/usr/bin/tmux new-session -d -P -s rt -n rtorrent /usr/bin/rtorrent
ExecStop=/usr/bin/tmux send-keys -t rt:rtorrent C-q
WorkingDirectory=/tmp/tmux-110/

[Install]
WantedBy=multi-user.target

一些更多的日志:

代码语言:javascript
复制
$ journalctl -u rtorrent
May 27 08:52:43 $MACHINE systemd[1]: Starting rTorrent...
May 27 08:52:43 $MACHINE tmux[20199]: rt:
May 27 08:52:43 $MACHINE systemd[1]: Started rTorrent.
May 27 08:52:43 $MACHINE tmux[20205]: no server running on /tmp/tmux-110/default
May 27 08:52:43 $MACHINE systemd[1]: rtorrent.service: Control process exited, code=exited, status=1/FAILURE
May 27 08:52:43 $MACHINE systemd[1]: rtorrent.service: Failed with result 'exit-code'.

到目前为止,我已经将用户rt添加到adm组中,但我无法理解为什么tmux不能作为rt启动。我还授权rt用户启动服务,这要归功于enable选项:loginctl enable-linger rt,我首先用:sudo adduser --system --gecos "rTorrent Client" --disabled-password --group --home /home/rt rt添加了rt用户。如何使rtorrentsystemd服务的形式运行,并以tmux作为专用用户?或者有没有其他方法可以使用systemd作为服务来运行它呢?任何帮助都是非常感谢的。

UPDATE:所以,为了重新开始,我创建了一个名为rtorrent with:sudo adduser --system --gecos "rTorrent System Client" --disabled-password --group --home /home/rtorrent rtorrent的新用户,并将/etc/systemd/system/rtorrent.service文件更改为此(还在/home/rtorrent/.rtorrent.rc因为这个职位中添加了system.daemon = true ):

代码语言:javascript
复制
[Unit]
Description=rTorrent System Daemon
After=network.target

[Service]
Type=simple
User=rtorrent
Group=rtorrent

ExecStartPre=-/bin/rm -f /home/rtorrent/.session/rtorrent.lock
ExecStart=/usr/bin/rtorrent -o import=/home/rtorrent/.rtorrent.rc
Restart=on-failure
RestartSec=3

[Install]
WantedBy=multi-user.target

但毕竟我得到了这个错误:

代码语言:javascript
复制
$ systemctl status rtorrent
● rtorrent.service - rTorrent System Daemon
     Loaded: loaded (/etc/systemd/system/rtorrent.service; enabled; vendor preset: enabled)
     Active: activating (auto-restart) (Result: exit-code) since Thu 2021-05-27 10:12:26 EEST; 2s ago
    Process: 22855 ExecStartPre=/bin/rm -f /home/rtorrent/.session/rtorrent.lock (code=exited, status=0/SUCCESS)
    Process: 22856 ExecStart=/usr/bin/rtorrent -o import=/home/rtorrent/.rtorrent.rc (code=exited, status=255/EXCEPTION)
   Main PID: 22856 (code=exited, status=255/EXCEPTION)

为什么会发生这种情况?我做错什么了?

UPDATE 2:还有一件事,这个职位建议不要在/etc/systemd/system/中删除任何文件,而是将它们放在基于Debian的系统中的/lib/systemd/system中。因此,我将unit-file移到那里,在启用它时,它会自动将symlink创建为/etc/systemd/system/。但是,我还是发现了一个错误:

代码语言:javascript
复制
$ sudo systemctl status rtorrent
● rtorrent.service - rTorrent System Daemon
     Loaded: loaded (/lib/systemd/system/rtorrent.service; enabled; vendor preset: enabled)
     Active: activating (auto-restart) (Result: exit-code) since Thu 2021-05-27 10:39:14 EEST; 924ms ago
    Process: 24530 ExecStartPre=/bin/rm -f /home/rtorrent/.session/rtorrent.lock (code=exited, status=0/SUCCESS)
    Process: 24531 ExecStart=/usr/bin/rtorrent -o import=/home/rtorrent/.rtorrent.rc (code=exited, status=255/EXCEPTION)
   Main PID: 24531 (code=exited, status=255/EXCEPTION)
EN

回答 2

Unix & Linux用户

回答已采纳

发布于 2021-12-06 15:35:06

rtorrent作为守护进程和屏幕/ tmux

从rtorrent 0.9.7,Starting / tmux 不再需要了运行rtorrent作为一个系统范围的守护进程if,您不需要它的控制台接口。它以前是强制性的,因为rtorrent要求一个活动的终端被控制,即使您只使用外部接口(例如ruTorrent)通过SCGI来管理您的洪流。

如果您确实希望使用屏幕或tmux运行rtorrent,以便能够使用终端控制它,请参阅这个答案

只需将以下配置添加到您的rtorrent.rc文件中,将rtorrent作为守护进程运行:

代码语言:javascript
复制
system.daemon.set = true

您的will只能通过SCGI使用外部软件来控制它,所以您还必须在配置文件中配置SCGI:

代码语言:javascript
复制
# Bind SCGI to localhost only on port 5000
network.scgi.open_port = 127.0.0.1:5000

注意:您的配置文件可能已经包含了一个scgi_port = ...指令。这是打开SCGI端口的旧方法,与上面的方法相当,但是不要将它们都放在配置文件中,否则rtorrent会抱怨端口已经打开:Error in option file: :: SCGI already enabled.

服务文件

先前的回答对于服务文件的外观是正确的。但是您必须注意正在使用的rtorrent配置文件。

默认情况下,rtorrent将加载~/.rtorrent.rc文件作为其配置文件。如果您还使用单元文件中的-o import ~/.rtorrent.rc选项加载它,它将使rtorrent加载文件两次。它导致rtorrent抱怨SCGI端口已经打开,因为它两次读取network.scgi.open_portscgi_port配置行。您还应该添加-n选项开关,以防止rtorrent读取其默认配置文件。

单元文件/etc/systemd/system/rtorrent.service应该如下所示:

代码语言:javascript
复制
[Unit]
Description=rTorrent system daemon
After=network.target

[Service]
Type=simple
User=torrent
Group=torrent

# Change these settings to match your install:
Environment=RTORRENT_DIR=/home/torrent
Environment=RTORRENT_CONFIG=${RTORRENT_DIR}/.rtorrent.rc
Environment=SESSION_DIR=${RTORRENT_DIR}/session

ExecStartPre=/bin/rm -f ${SESSION_DIR}/rtorrent.lock
ExecStart=/usr/bin/rtorrent -n -o import=${RTORRENT_CONFIG}

Restart=on-failure
RestartSec=3

[Install]
WantedBy=multi-user.target
票数 3
EN

Unix & Linux用户

发布于 2021-05-27 06:25:18

我不明白为什么会有人想要一个tmux在你的rtorrent周围。这里tmux的功能是什么?如果您绝对需要额外的进程开销,可以尝试https://askubuntu.com/questions/802189/how-to-run-tmux-screen-with-systemd-230

无论如何,创建一个/etc/systemd/system/rtorrent.service

代码语言:javascript
复制
[Unit]
Description=rTorrent System Daemon
After=network.target

[Service]
Type=simple
User=rtorrent
Group=rtorrent

ExecStartPre=-/bin/rm -f /home/rt/.session/rtorrent.lock
ExecStart=/usr/bin/rtorrent -o import=/home/rt/rtorrent.rc
Restart=on-failure
RestartSec=3

[Install]
WantedBy=multi-user.target

回答你的最后一个问题。

票数 5
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/651591

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档