0

Code is as below. I will explain here.

I use fabric to check the mount point status for 2 server. The command is

df -h /mnt

The problem of this command is that it may hang there forever, so the fabric code will hang forever. I think some timeout mechanism will fix this issue. But I did not find it on the fabric doc. Is there any setting about this ?

import fabric
from fabric import ThreadingGroup as Group

directory = '/mnt'
group = Group('server1', 'server2', user='someuser', connect_kwargs={'password':'somepassword'})
try:
    result = group.run("df -h %s" % directory)
except fabric.exceptions.GroupException as e:
    err = e
    pass
Kramer Li
  • 2,284
  • 5
  • 27
  • 55

1 Answers1

2

Option #1: use bash timeout to stop the command timeout 10 df -h

Option #2: use the run function's timeout parameter. timeout is specified in seconds, and a CommandTimeout exception is raised if the command times out.

Group.run

Executes Connection.run on all member Connections.

and Connection.run

wraps an SSH-capable implementation of invoke.runners.Runner.run; see its documentation for details.

2ps
  • 15,099
  • 2
  • 27
  • 47