From 10dcb6102cdeeb207e6658b7e298737a4f4e7fc6 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Sat, 23 Mar 2013 04:19:04 +0100 Subject: [PATCH] Fix code to properly set up a tunnel --- command_daemon/start.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/command_daemon/start.py b/command_daemon/start.py index 79e8d16..5f22872 100644 --- a/command_daemon/start.py +++ b/command_daemon/start.py @@ -1,4 +1,4 @@ -import sys, subprocess +import sys, os, subprocess stfu = open("/dev/null", "w") @@ -14,8 +14,13 @@ port = int(sys.argv[3]) keyfile = sys.argv[4] session_key = sys.argv[5] -if run_command(["ssh", "%s@%s" % (user, host), "-i", keyfile, "cd /etc/cvm/command_daemon; echo '%s' > session_key && ./command_daemon" % session_key]) == 0: - if run_command(["autossh", "-f", "-i", keyfile, "-M", str(port + 1), "%s@%s" % (user, host), "-L", "%s:localhost:3434" % port, "-N"]) == 0: +if run_command(["ssh", "%s@%s" % (user, host), "-o", "UserKnownHostsFile=/etc/cvm/knownhosts", "-o", "StrictHostKeyChecking=no", "-i", keyfile, "cd /etc/cvm/command_daemon; echo '%s' > session_key && ./command_daemon" % session_key]) == 0: + # Make autossh verify the connection is still alive every 10 seconds. + os.environ["AUTOSSH_POLL"] = 10 + os.environ["AUTOSSH_FIRST_POLL"] = 10 + + if run_command(["autossh", "-f", "-i", keyfile, "-M", str(port + 1), "-o", "UserKnownHostsFile=/etc/cvm/knownhosts", "-o", "StrictHostKeyChecking=no", "%s@%s" % (user, host), "-L", "%s:localhost:3434" % port, "-N"]) == 0: + sys.stdout.write("Tunnel established.\n"); exit(0) else: sys.stderr.write("Failed to establish tunnel.\n")