Как запустить rtorrent как службу systemd под выделенным пользователем?

В Linux обычно установлен GNU awk . Я не знаю, какая версия awk поддерживает начальные нули для строки формата %s, но, похоже, она не соответствует стандарту -.

Попробуйте использовать %013d вместо %013s.

2
27.05.2021, 15:11
2 ответа

После предыдущего ответа я еще немного покопался и решил проблему. Итак, во-первых, я хочу поблагодарить @Ljm Duallaart за то, что он указал мне правильное направление. Я пробовал с tmuxи screen, но у меня это не сработало, и я действительно хотел заставить его работать с собственным daemon. И, наконец, я сделал:

  38890 rtorrent   20   0  176M 17404 15588 S  0.0  0.8  0:00.03 ├─ /usr/bin/rtorrent -o import=/home/rtorrent/.rtorrent.rc
  38892 rtorrent   20   0  176M 17404 15588 S  0.0  0.8  0:00.00 │  ├─ /usr/bin/rtorrent -o import=/home/rtorrent/.rtorrent.rc
  38891 rtorrent   20   0  176M 17404 15588 S  0.0  0.8  0:00.00 │  └─ /usr/bin/rtorrent -o import=/home/rtorrent/.rtorrent.rc
$ sudo systemctl status rtorrent
● rtorrent.service - rTorrent System Daemon
     Loaded: loaded (/lib/systemd/system/rtorrent.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2021-05-27 14:19:51 EEST; 8min ago
    Process: 38889 ExecStartPre=/bin/rm -f /home/rtorrent/.session/rtorrent.lock (code=exited, status=0/SUCCESS)
   Main PID: 38890 (rtorrent main)
      Tasks: 3 (limit: 18976)
     Memory: 2.2M
     CGroup: /system.slice/rtorrent.service
             └─38890 /usr/bin/rtorrent -o import=/home/rtorrent/.rtorrent.rc

May 27 14:19:51 ubuntu-internship systemd[1]: Starting rTorrent System Daemon...
May 27 14:19:51 ubuntu-internship systemd[1]: Started rTorrent System Daemon.

Первая ошибка, с которой я столкнулся, была связана с этим маленьким дефисом в файле модуля, который в предыдущем ответе предлагалось использовать:ExecStartPre=-/bin/rm -f /home/rt/.session/rtorrent.lock. Выяснив это, внимательно изучите файл rtorrent.service. Вторая ошибка была связана с чем-то в моем файле .rtorrent.rc. Это потому, что я раскомментировал эту строку в файле:

#XMLRP-C
#network.scgi.open_port = 127.0.0.1:5000

и я получил эту ошибку, ясно указывающую на то, что:

May 27 14:19:35 $MACHINE systemd[1]: rtorrent.service: Scheduled restart job, restart counter is at 4716.
May 27 14:19:35 $MACHINE systemd[1]: Stopped rTorrent System Daemon.
May 27 14:19:35 $MACHINE systemd[1]: Starting rTorrent System Daemon...
May 27 14:19:35 $MACHINE systemd[1]: Started rTorrent System Daemon.
May 27 14:19:35 $MACHINE rtorrent[38864]: rtorrent: Error in option file: ~/.rtorrent.rc:113: SCGI already enabled.
May 27 14:19:35 $MACHINE systemd[1]: rtorrent.service: Main process exited, code=exited, status=255/EXCEPTION
May 27 14:19:35 $MACHINE systemd[1]: rtorrent.service: Failed with result 'exit-code'.

Но после комментирования строки обратно. Просто запустилось без проблем. Итак, для тех, кто когда-либо пытался запустить rtorrentкак systemd serviceи наткнулся на этот пост :«В своих поисках истины вы нашли только половину ее», потому что rtorrentработает отлично, как это, но если вы хотите подключиться к нему через rutorrent, вы не сможете, потому что демон не запустится, когда я открою SCGI port. Если вы найдете решение следующего вопроса, напишите мне в комментариях :«Как заставить rtorrentи rutorrentработать вместе при запуске rtorrent на его system-daemon»?
Вот мой systemd-unit fileи мойrtorrent.rc:

[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
# This is an example resource file for rTorrent. Copy to
# ~/.rtorrent.rc and enable/modify the options as needed. Remember to
# uncomment the options you wish to enable.m

# Implements a system.use_daemon variable that allows users to enable daemon mode via 
system.daemon.set = true


# Maximum and minimum number of peers to connect to per torrent.
#min_peers = 40
#max_peers = 100

# Same as above but for seeding completed torrents (-1 = same as downloading)
#min_peers_seed = 10
#max_peers_seed = 50

# Maximum number of simultanious uploads per torrent.
#max_uploads = 15

# Global upload and download rate in KiB. "0" for unlimited.
#download_rate = 0
#upload_rate = 0

# Default directory to save the downloaded torrents.
directory = /home/rtorrent/Downloads

# Default session directory. Make sure you don't run multiple instance
# of rtorrent using the same session directory. Perhaps using a
# relative path?
session = /home/rtorrent/.rtorrent-session

# Watch a directory for new torrents, and stop those that have been
# deleted.
schedule = watch_directory, 5, 5, "load.start_verbose=/home/rtorrent/watch/*.torrent"
#schedule = untied_directory,5,5,stop_untied=

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

# The ip address reported to the tracker.
#ip = 127.0.0.1
#ip = rakshasa.no

# The ip address the listening socket and outgoing connections is
# bound to.
#bind = 127.0.0.1
#bind = rakshasa.no

# Port range to use for listening.
port_range = 45000-45022

# Start opening ports at a random position within the port range.
port_random = no

# Check hash for finished torrents. Might be usefull until the bug is
# fixed that causes lack of diskspace not to be properly reported.
#check_hash = no

# Set whetever the client should try to connect to UDP trackers.
#use_udp_trackers = yes

# Alternative calls to bind and ip that should handle dynamic ip's.
#schedule = ip_tick,0,1800,ip=rakshasa
#schedule = bind_tick,0,1800,bind=rakshasa

# Encryption options, set to none (default) or any combination of the following:
# allow_incoming, try_outgoing, require, require_RC4, enable_retry, prefer_plaintext
#
# The example value allows incoming encrypted connections, starts unencrypted
# outgoing connections but retries with encryption if they fail, preferring
# plaintext to RC4 encryption after the encrypted handshake
#
encryption = allow_incoming,enable_retry,try_outgoing
# Enable DHT support for trackerless torrents or when all trackers are down.
# May be set to "disable" (completely disable DHT), "off" (do not start DHT),
# "auto" (start and stop DHT as needed), or "on" (start DHT immediately).
# The default is "off". For DHT to work, a session directory must be defined.
# 
#dht.mode.set = on

# UDP port to use for DHT. 
# 
dht_port = 6881

# Enable peer exchange (for torrents not marked private)
#
#protocol.pex.set = no
#trackers.use_udp.set = no

#
# Do not modify the following parameters unless you know what you're doing.
#

# Hash read-ahead controls how many MB to request the kernel to read
# ahead. If the value is too low the disk may not be fully utilized,
# while if too high the kernel might not be able to keep the read
# pages in memory thus end up trashing.
#hash_read_ahead = 10

# Interval between attempts to check the hash, in milliseconds.
#hash_interval = 100

# Number of attempts to check the hash while using the mincore status,
# before forcing. Overworked systems might need lower values to get a
# decent hash checking rate.
#hash_max_tries = 10
#SCGI
#scgi_port = 127.0.0.1:5000

#XMLRP-C
#network.scgi.open_port = 127.0.0.1:5000

####### Heavy I/O seedbox configuration
####### Uncomment lines below if you have 1Gbit+ Internet link
####### thanks Zebirek
####pieces.memory.max.set = 8048M
####network.max_open_sockets.set = 999
####network.max_open_files.set = 600
####network.http.max_open.set = 99
####network.receive_buffer.size.set = 32M
####network.send_buffer.size.set    = 64M
####pieces.preload.type.set = 2
#####pieces.preload.min_size.set = 262144
#####pieces.preload.min_rate.set = 5120
1
28.07.2021, 11:28

Я не понимаю, зачем кому-то tmuxрядом с вашим rtorrent. Какова функция tmuxздесь? Вы можете попробоватьhttps://askubuntu.com/questions/802189/how-to-run-tmux-screen-with-systemd-230если вы абсолютно хотите, чтобы эти дополнительные накладные расходы процесса.

В любом случае, создайте /etc/systemd/system/rtorrent.serviceс

[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

Это ответ на ваш последний вопрос.

3
28.07.2021, 11:28

Теги

Похожие вопросы