3
我似乎無法使Fabric能夠很好地處理我使用nohup的背景。 。 。給出各種信息應該是可能的,包括here和here。無法使用Fabric和nohup真正背景SSH隧道
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 %[email protected]%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' >& /dev/null < /dev/null &" % tun_s)
print "fin"
縮略的輸出:
[email protected]:~/deploy$ fab test
executing on tunnel ssh -o StrictHostKeyChecking=no -i ~/.ssh/kp.pem [email protected] -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 [email protected] -L 16646:localhost:16646 -L 9090:localhost:9090 -L 6666:localhost:6666 -N' >& /dev/null < /dev/null &
fin
Done.
Disconnecting from xxxx
我知道有與隧道命令本身沒有問題,因爲如果我奪走了nohup的東西,它工作正常(但顯然面料掛起)。我很確定它沒有正確分離,並且當運行函數返回隧道進程時立即死亡。
但是爲什麼?
這也發生在我的代碼的另一部分的python命令。
爲什麼_你使用nohup?如果你問我,這是多餘的。 – sehe
嗯,你是否嘗試使用-T禁用ssh的tty分配,並且還禁用pty = False的任務的tty分配? – favoretti
@sehe,爲什麼它是多餘的?我還應該如何分離這個過程,以便布料可以在隧道不死的情況下返回? – Edwardr