title: Unable to truly background an SSH tunnel using Fabric and nohup
body: <p>I can't seem to get Fabric to play nice with backgrounding a process that I've used nohup on. . . It should be possible, given various pieces of information, including <a href="https://github.com/fabric/fabric/issues/216" rel="nofollow">here</a> and <a href="http://docs.fabfile.org/en/1.2.2/faq.html#why-can-t-i-run-programs-in-the-background-with-it-makes-fabric-hang" rel="nofollow">here</a>.</p>
  
  <pre><code>def test():
  h = 'xxxxx.compute-1.amazonaws.com'    
  ports = [16646, 9090, 6666]
  
  with settings(host_string = h):
      tun_s = "ssh  -o StrictHostKeyChecking=no -i ~/.ssh/kp.pem %s@%s " % (env.user, h)      
  
      for port in ports:
          p_forward = "-L %d:localhost:%d" % (port, port)
          tun_s = "%s %s" % (tun_s, p_forward)
  
      tun_s = "%s -N" % tun_s
      # create the tunnel. . .
      print "creating tunnel %s" % tun_s
      run("nohup '%s' &gt;&amp; /dev/null &lt; /dev/null &amp;" % tun_s)
      print "fin"
  </code></pre>
  
  <p>Abbreviated output:</p>
  
  <pre><code>ubuntu@domU-xxx:~/deploy$ fab test
  executing on tunnel ssh  -o StrictHostKeyChecking=no -i ~/.ssh/kp.pem ubuntu@xxx  -L 16646:localhost:16646 -L 9090:localhost:9090 -L 6666:localhost:6666 -N
  [xxx.compute-1.amazonaws.com] run: nohup 'ssh  -o StrictHostKeyChecking=no -i ~/.ssh/kp.pem ubuntu@xxx.compute-1.amazonaws.com  -L 16646:localhost:16646 -L 9090:localhost:9090 -L 6666:localhost:6666 -N' &gt;&amp; /dev/null &lt; /dev/null &amp;
  fin
  
  Done.
  Disconnecting from xxxx
  </code></pre>
  
  <p>I know there is no problem with the tunnel command per se because if I strip away the nohup stuff it works fine (but obviously Fabric hangs). I'm pretty sure that it's not properly getting detached and when the run function returns the tunnel process is immediately dying.</p>
  
  <p>But why?</p>
  
  <p>This also happens with a python command in another part of my code. </p>