diff --git a/rffmpeg.py b/rffmpeg.py index 96d8097..dc4e73c 100755 --- a/rffmpeg.py +++ b/rffmpeg.py @@ -84,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"] = 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"]) @@ -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=/run/shm/ssh-%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..68a2930 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: 300 + # A YAML list of additional SSH arguments (e.g. private keys), # one line per space-separated argument element. args: