fix init
This commit is contained in:
@@ -536,10 +536,7 @@ def install_symlinks(rtorrent_install, libtorrent_install, xmlrpc_install=None,
|
||||
run(["ldconfig"], debug=debug)
|
||||
|
||||
|
||||
def write_service(service_path, binary_path, runtime_lib_dirs, *, runtime_directory=None):
|
||||
runtime_directory_lines = ""
|
||||
if runtime_directory:
|
||||
runtime_directory_lines = f"RuntimeDirectory={runtime_directory}\nRuntimeDirectoryMode=0750\n"
|
||||
def write_service(service_path, binary_path, runtime_lib_dirs):
|
||||
service_content = f"""[Unit]
|
||||
Description=rTorrent for %I | https://git.linuxiarz.pl/gru/tools_scripts/_edit/master/install_rtorrent.py
|
||||
After=network.target
|
||||
@@ -549,6 +546,8 @@ Type=simple
|
||||
User=%I
|
||||
Group=%I
|
||||
KillMode=process
|
||||
RuntimeDirectory=%I
|
||||
RuntimeDirectoryMode=0750
|
||||
WorkingDirectory=/home/%I
|
||||
ExecStartPre=-/bin/rm -f /home/%I/.session/rtorrent.lock
|
||||
ExecStart={binary_path} -o system.daemon.set=true -n -o import=/home/%I/.rtorrent.rc
|
||||
@@ -557,7 +556,7 @@ TimeoutStopSec=300
|
||||
Restart=always
|
||||
RestartSec=3
|
||||
LimitNOFILE=1048576
|
||||
{runtime_directory_lines}Environment=LD_LIBRARY_PATH={runtime_lib_dirs}
|
||||
Environment=LD_LIBRARY_PATH={runtime_lib_dirs}
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -582,11 +581,8 @@ def rtorrent_bind_address_directive(rtorrent_ref, rtorrent_version=None):
|
||||
return "network.bind_address.set"
|
||||
return "network.bind_address.ipv4.set"
|
||||
|
||||
def build_rtorrent_config_content(username, scgi_port, torrent_port, bind_address_directive, scgi_backend="tcp", scgi_socket="/run/rtorrent/rtorrent.sock"):
|
||||
if scgi_backend == "unix":
|
||||
scgi_line = f"network.scgi.open_local = {scgi_socket}\nexecute.nothrow = chmod,660,{scgi_socket}"
|
||||
else:
|
||||
scgi_line = f"network.scgi.open_port = 127.0.0.1:{scgi_port}"
|
||||
def build_rtorrent_config_content(username, scgi_port, torrent_port, bind_address_directive, scgi_unix_socket=None):
|
||||
scgi_line = f"network.scgi.open_local = {scgi_unix_socket}" if scgi_unix_socket else f"{scgi_line}"
|
||||
return f"""
|
||||
## https://git.linuxiarz.pl/gru/tools_scripts/_edit/master/install_rtorrent.py
|
||||
# Generated by install_rtorrent.py
|
||||
@@ -640,9 +636,9 @@ pieces.hash.on_completion.set = 0
|
||||
""".lstrip()
|
||||
|
||||
|
||||
def write_rtorrent_config(user_home, username, scgi_port, torrent_port, bind_address_directive, *, scgi_backend="tcp", scgi_socket="/run/rtorrent/rtorrent.sock", force_config=False):
|
||||
def write_rtorrent_config(user_home, username, scgi_port, torrent_port, bind_address_directive, *, force_config=False, scgi_unix_socket=None):
|
||||
config_path = Path(user_home) / ".rtorrent.rc"
|
||||
config_content = build_rtorrent_config_content(username, scgi_port, torrent_port, bind_address_directive, scgi_backend=scgi_backend, scgi_socket=scgi_socket)
|
||||
config_content = build_rtorrent_config_content(username, scgi_port, torrent_port, bind_address_directive, scgi_unix_socket)
|
||||
|
||||
if config_path.exists() and not force_config:
|
||||
print(f"Config already exists: {config_path}")
|
||||
@@ -816,9 +812,8 @@ def build_parser():
|
||||
parser.add_argument("--user", default=DEFAULT_USER, help=f"System user for the service (default: {DEFAULT_USER})")
|
||||
parser.add_argument("--group", default=DEFAULT_GROUP, help=f"System group for the service (default: {DEFAULT_GROUP})")
|
||||
parser.add_argument("--home", default=DEFAULT_HOME, help=f"Home directory for the service user (default: {DEFAULT_HOME})")
|
||||
parser.add_argument("--scgi-port", type=int, default=DEFAULT_SCGI_PORT, help=f"SCGI TCP listen port for rTorrent XMLRPC/SCGI (default: {DEFAULT_SCGI_PORT})")
|
||||
parser.add_argument("--scgi-backend", choices=["tcp", "unix"], default=os.getenv("RTORRENT_SCGI_BACKEND", "tcp"), help="rTorrent SCGI backend to write in .rtorrent.rc (default: tcp).")
|
||||
parser.add_argument("--scgi-socket", default=os.getenv("RTORRENT_SCGI_SOCKET", "/run/rtorrent/rtorrent.sock"), help="Unix socket path used when --scgi-backend unix is selected.")
|
||||
parser.add_argument("--scgi-port", type=int, default=DEFAULT_SCGI_PORT, help=f"SCGI listen port for rTorrent XMLRPC/SCGI (default: {DEFAULT_SCGI_PORT})")
|
||||
parser.add_argument("--scgi-unix-socket", default="", help="Use Unix socket SCGI listener instead of TCP, for example /run/rtorrent/rtorrent.sock")
|
||||
parser.add_argument("--torrent-port", type=int, default=DEFAULT_TORRENT_PORT, help=f"Incoming BitTorrent listen port (default: {DEFAULT_TORRENT_PORT})")
|
||||
parser.add_argument("--force-config", action="store_true", help="Overwrite existing ~/.rtorrent.rc. By default, existing config is left unchanged and the proposed changes are printed.")
|
||||
parser.add_argument("--only-build", action="store_true", help="Only build and install libtorrent/rTorrent under /opt. Skip user, config and systemd.")
|
||||
@@ -870,10 +865,7 @@ def main():
|
||||
print(" - skip service user, config and systemd setup")
|
||||
else:
|
||||
print(f" - configure systemd service for user '{args.user}'")
|
||||
if args.scgi_backend == "unix":
|
||||
print(f" - use SCGI Unix socket {args.scgi_socket} and torrent port {args.torrent_port}")
|
||||
else:
|
||||
print(f" - use SCGI port {args.scgi_port} and torrent port {args.torrent_port}")
|
||||
print(f" - use SCGI socket {args.scgi_unix_socket} and torrent port {args.torrent_port}" if args.scgi_unix_socket else f" - use SCGI port {args.scgi_port} and torrent port {args.torrent_port}")
|
||||
|
||||
if not prompt_yes_no("Continue?", default=True, assume_yes=args.yes):
|
||||
print("Aborted by user.")
|
||||
@@ -912,7 +904,7 @@ def main():
|
||||
prepare_user_dirs(args.home, args.user)
|
||||
bind_address_directive = rtorrent_bind_address_directive(args.rtorrent_ref, rtorrent_version)
|
||||
print(f"Using rTorrent bind address directive: {bind_address_directive}")
|
||||
write_rtorrent_config(args.home, args.user, args.scgi_port, args.torrent_port, bind_address_directive, scgi_backend=args.scgi_backend, scgi_socket=args.scgi_socket, force_config=args.force_config)
|
||||
write_rtorrent_config(args.home, args.user, args.scgi_port, args.torrent_port, bind_address_directive, force_config=args.force_config, scgi_unix_socket=args.scgi_unix_socket or None)
|
||||
runtime_lib_dirs = [f"{libtorrent_install}/lib"]
|
||||
if args.rpc_backend == "xmlrpc-c" and xmlrpc_install:
|
||||
runtime_lib_dirs.append(f"{xmlrpc_install}/lib")
|
||||
@@ -920,12 +912,7 @@ def main():
|
||||
runtime_lib_dirs.append(f"{curl_install}/lib")
|
||||
if cares_install:
|
||||
runtime_lib_dirs.append(f"{cares_install}/lib")
|
||||
runtime_directory = None
|
||||
if args.scgi_backend == "unix" and args.scgi_socket.startswith("/run/"):
|
||||
parts = Path(args.scgi_socket).parts
|
||||
if len(parts) >= 3:
|
||||
runtime_directory = parts[2]
|
||||
write_service(DEFAULT_SERVICE_PATH, "/usr/local/bin/rtorrent", ":".join(runtime_lib_dirs), runtime_directory=runtime_directory)
|
||||
write_service(DEFAULT_SERVICE_PATH, "/usr/local/bin/rtorrent", ":".join(runtime_lib_dirs))
|
||||
enable_service(args.user, debug=args.debug)
|
||||
print(f"\nService status hint: systemctl status rtorrent@{args.user}.service")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user