From 338d8e7d27349b8cfdf69dc43b53fc5786c34c1c Mon Sep 17 00:00:00 2001 From: Daniel Hellstern Date: Thu, 13 May 2021 20:51:06 +0000 Subject: [PATCH 1/6] Enabled SSH multiplexing/persistence --- rffmpeg.py | 20 ++++++++++++-------- rffmpeg.yml.sample | 3 +++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/rffmpeg.py b/rffmpeg.py index 96d8097..2a855a3 100755 --- a/rffmpeg.py +++ b/rffmpeg.py @@ -73,6 +73,7 @@ try: "logfile": o_config["rffmpeg"]["logging"]["logfile"], "remote_hosts": o_config["rffmpeg"]["remote"]["hosts"], "remote_user": o_config["rffmpeg"]["remote"]["user"], + "remote_persist": o_config["rffmpeg"]["remote"]["persist"], "remote_args": o_config["rffmpeg"]["remote"]["args"], "pre_commands": o_config["rffmpeg"]["commands"]["pre"], "ffmpeg_command": o_config["rffmpeg"]["commands"]["ffmpeg"], @@ -213,14 +214,17 @@ def setup_remote_command(target_host): rffmpeg_ssh_command.append("-q") # Set our connection timeouts, in case one of several remote machines is offline - rffmpeg_ssh_command.append("-o") - rffmpeg_ssh_command.append("ConnectTimeout=1") - rffmpeg_ssh_command.append("-o") - rffmpeg_ssh_command.append("ConnectionAttempts=1") - rffmpeg_ssh_command.append("-o") - rffmpeg_ssh_command.append("StrictHostKeyChecking=no") - rffmpeg_ssh_command.append("-o") - rffmpeg_ssh_command.append("UserKnownHostsFile=/dev/null") + rffmpeg_ssh_command.extend([ "-o", "ConnectTimeout=1" ]) + rffmpeg_ssh_command.extend([ "-o", "ConnectionAttempts=1" ]) + rffmpeg_ssh_command.extend([ "-o", "StrictHostKeyChecking=no" ]) + rffmpeg_ssh_command.extend([ "-o", "UserKnownHostsFile=/dev/null" ]) + + # Use SSH control persistence to keep sessions alive for subsequent commands + persist = config["remote_persist"] + if persist > 0: + rffmpeg_ssh_command.extend([ "-o", "ControlMaster=auto" ]) + rffmpeg_ssh_command.extend([ "-o", "ControlPath=/tmp/persist-%r@%h:%p" ]) + rffmpeg_ssh_command.extend([ "-o", "ControlPersist={}".format(persist) ]) for arg in config["remote_args"]: if arg: diff --git a/rffmpeg.yml.sample b/rffmpeg.yml.sample index 70f0cd3..ada5795 100644 --- a/rffmpeg.yml.sample +++ b/rffmpeg.yml.sample @@ -34,6 +34,9 @@ rffmpeg: # The remote SSH user to connect as user: jellyfin + # How long to persist SSH sessions (0 to disable) + persist: 120 + # A YAML list of additional SSH arguments (e.g. private keys), # one line per space-separated argument element. args: From 9b28a7b81b32a4e062262b8757bdae7a52ede543 Mon Sep 17 00:00:00 2001 From: Daniel Hellstern Date: Thu, 13 May 2021 21:10:09 +0000 Subject: [PATCH 2/6] Increased default persistence length to 300 seconds --- rffmpeg.yml.sample | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rffmpeg.yml.sample b/rffmpeg.yml.sample index ada5795..68a2930 100644 --- a/rffmpeg.yml.sample +++ b/rffmpeg.yml.sample @@ -35,7 +35,7 @@ rffmpeg: user: jellyfin # How long to persist SSH sessions (0 to disable) - persist: 120 + persist: 300 # A YAML list of additional SSH arguments (e.g. private keys), # one line per space-separated argument element. From dafbe71e8e6d6e601efebfaa2edf23bedcafa049 Mon Sep 17 00:00:00 2001 From: Daniel Hellstern Date: Thu, 13 May 2021 21:12:32 +0000 Subject: [PATCH 3/6] Moved persistence length to fallback configuration section --- rffmpeg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rffmpeg.py b/rffmpeg.py index 2a855a3..833693d 100755 --- a/rffmpeg.py +++ b/rffmpeg.py @@ -73,7 +73,6 @@ try: "logfile": o_config["rffmpeg"]["logging"]["logfile"], "remote_hosts": o_config["rffmpeg"]["remote"]["hosts"], "remote_user": o_config["rffmpeg"]["remote"]["user"], - "remote_persist": o_config["rffmpeg"]["remote"]["persist"], "remote_args": o_config["rffmpeg"]["remote"]["args"], "pre_commands": o_config["rffmpeg"]["commands"]["pre"], "ffmpeg_command": o_config["rffmpeg"]["commands"]["ffmpeg"], @@ -85,6 +84,7 @@ except Exception as e: # Handle the fallback configuration using get() to avoid failing config["ssh_command"] = o_config["rffmpeg"]["commands"].get("ssh", "ssh") +config["remote_persist"] = o_config["rffmpeg"]["remote"].get("persist", 0) config["fallback_ffmpeg_command"] = o_config["rffmpeg"]["commands"].get("fallback_ffmpeg", config["ffmpeg_command"]) config["fallback_ffprobe_command"] = o_config["rffmpeg"]["commands"].get("fallback_ffprobe", config["ffprobe_command"]) From 8972232d79859b67c21f7120dc0db98650dba531 Mon Sep 17 00:00:00 2001 From: Daniel Hellstern Date: Fri, 14 May 2021 01:40:35 +0000 Subject: [PATCH 4/6] Switched to /dev/shm for persistence --- rffmpeg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rffmpeg.py b/rffmpeg.py index 833693d..277b628 100755 --- a/rffmpeg.py +++ b/rffmpeg.py @@ -223,7 +223,7 @@ def setup_remote_command(target_host): persist = config["remote_persist"] if persist > 0: rffmpeg_ssh_command.extend([ "-o", "ControlMaster=auto" ]) - rffmpeg_ssh_command.extend([ "-o", "ControlPath=/tmp/persist-%r@%h:%p" ]) + rffmpeg_ssh_command.extend([ "-o", "ControlPath=/dev/shm/ssh-%r@%h:%p" ]) rffmpeg_ssh_command.extend([ "-o", "ControlPersist={}".format(persist) ]) for arg in config["remote_args"]: From 3690e079d4cbea61dacb6fdd0e6db3966e256435 Mon Sep 17 00:00:00 2001 From: Daniel Hellstern Date: Fri, 14 May 2021 01:41:12 +0000 Subject: [PATCH 5/6] /run/shm* --- rffmpeg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rffmpeg.py b/rffmpeg.py index 277b628..8e79d5b 100755 --- a/rffmpeg.py +++ b/rffmpeg.py @@ -223,7 +223,7 @@ def setup_remote_command(target_host): persist = config["remote_persist"] if persist > 0: rffmpeg_ssh_command.extend([ "-o", "ControlMaster=auto" ]) - rffmpeg_ssh_command.extend([ "-o", "ControlPath=/dev/shm/ssh-%r@%h:%p" ]) + rffmpeg_ssh_command.extend([ "-o", "ControlPath=/run/shm/ssh-%r@%h:%p" ]) rffmpeg_ssh_command.extend([ "-o", "ControlPersist={}".format(persist) ]) for arg in config["remote_args"]: From 6b89ae369c1de91d7d2d598a1b6a28338c86ab75 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Tue, 25 May 2021 21:55:02 -0400 Subject: [PATCH 6/6] Ensure persist value is an integer --- rffmpeg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rffmpeg.py b/rffmpeg.py index 8e79d5b..dc4e73c 100755 --- a/rffmpeg.py +++ b/rffmpeg.py @@ -84,7 +84,7 @@ except Exception as e: # Handle the fallback configuration using get() to avoid failing config["ssh_command"] = o_config["rffmpeg"]["commands"].get("ssh", "ssh") -config["remote_persist"] = o_config["rffmpeg"]["remote"].get("persist", 0) +config["remote_persist"] = int(o_config["rffmpeg"]["remote"].get("persist", 0)) config["fallback_ffmpeg_command"] = o_config["rffmpeg"]["commands"].get("fallback_ffmpeg", config["ffmpeg_command"]) config["fallback_ffprobe_command"] = o_config["rffmpeg"]["commands"].get("fallback_ffprobe", config["ffprobe_command"])