'fabric: run() hangs without any errors
from fabric.api import env
from fabric.api import run
class FabricSupport:
def __init__ (self):
pass
def run(self, host, command):
env.key_filename = 'C:/.ssh/dev.pub'
env.host_string = "%s:%s" % (host, 22)
run(command, timeout=5)
fab = FabricSupport()
def execute(host, txt):
stdout = ""
try:
stdout = fab.run(host, txt)
except Exception, e:
stdout = str(e)
return stdout
result = execute("23.23.23.23", "uname -a")
it just outputs the following and stays like that indefinitely. timeout doesn't seem to be working. It would be great if it was more verbose so I could investigate what is going on.
[12.45.241.11:22] run: uname -a
Solution 1:[1]
I encountered the same problem today with an Ubuntu host. My problem was the active shell setting:
env.shell = /bin/sh -l -c
With this shell the script would not cleanly execute the remote command and hangup the ssh connection. The control remained inside the ssh shell, causing a timeout in fabric.
With the setting:
env.shell = "/bin/bash -c"
everything was OK.
General advice: check the shell and parameters according to your host OS.
Solution 2:[2]
I came across the same hanging error this week when I need to run a job taking long time on remote machine.
I resolved it by specifying 'keepalive' option in fabric.api.env config. This config will ask fabric to send keepalive message every a few minutes.
http://docs.fabfile.org/en/1.14/usage/env.html#keepalive
I set the value to be 30 and it doesn't hang on a job running for 3 hours.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Freek Wiekmeijer |
| Solution 2 | Isengard |
