在某些主机上将命令与Fabric一起放置在后台不起作用 [英] Putting command in the background with Fabric does not work on some hosts
问题描述
出于测试目的,我使用普通的ssh命令行工具运行以下命令:
For testing purposes, I am running the following command, with plain ssh command line tool:
ssh user@host "nohup sleep 100 >> /tmp/xxx 2>&1 < /dev/null &"
这在我所有的主机中都按预期工作:后台创建了一个睡眠过程,并且ssh立即完成.
This is working as expected, in all my hosts: a sleep process is created in the background, and the ssh finishes immediately.
我正在尝试使用Fabric在python中实现此功能.我最终进行了run
呼叫.这是Fabric日志记录报告的内容:
I am trying to implement this functionality in python using Fabric. I end up doing a run
call. This is what the Fabric logging is reporting:
[user@host] run: nohup sleep 100 >> /tmp/xxx 2>&1 < /dev/null &
这正是我所期望的.但是,如果我检查主机中正在运行的进程,则sleep 100
不是其中之一.更糟糕的是:该问题仅在我的某些主机上发生.
Which is exactly what I expect. But if I check the processes which are running in my host, sleep 100
is not one of them. Worse yet: the problem happens only on some of my hosts.
我还通过添加"\ necho $!"添加了更多信息,以显示已创建的进程.到由Fabric运行的命令.这是据报道:
I also added some more info to show what process has been created, by appending a "\necho $!" to the command to be run by Fabric. This is what was reported:
[user@host] run: nohup sleep 100 >> /tmp/xxx 2>&1 < /dev/null &
echo $!
[user@host] out: 30935
由于Fabric报告已经创建了该进程,所以我对如何进行调试的想法不多了,但是我看不到另一端正在运行任何进程.系统日志报告正在打开和关闭ssh会话:
I am running out of ideas on how to debug this, since Fabric is reporting that the process has been created, but I see no process running in the other end. The syslog reports that an ssh session is being opened and closed:
Dec 6 09:12:09 host sshd[2835]: Accepted publickey for user from 67.133.172.14 port 37732 ssh2
Dec 6 09:12:09 host sshd[2838]: pam_unix(sshd:session): session opened for user user by (uid=0)
Dec 6 09:12:10 host sshd[2838]: pam_unix(sshd:session): session closed for user user
我能以某种方式增加ssh守护程序正在生成的日志记录的数量,以便至少可以看到通过ssh请求的命令是什么吗?
Could I somehow increase the amount of logging that the ssh daemon is producing, so that I can see at least what command is being requested via ssh?
I know that Fabric has some issues with running commands in the background, but that does not seem to be my problem. Could there be other issues with Fabric / ssh / background processes?
我已经在所有系统上安装了dtach
. Ubuntu 8.04中打包的版本太旧,不允许通过ssh调用dtach -n
(终端问题),因此我不得不下载并编译 dtach来源.完成之后,我可以使用Fabric运行这样的命令:
I have installed dtach
on all my systems. The version packaged in Ubuntu 8.04 is too old, and does not allow calling dtach -n
over ssh (problems with terminal), so I had to download and compile the dtach sources. After doing that, I was able to run my command like this, with Fabric:
[user @ host]运行:dtach -n/tmp/Y sleep 100 >>/tmp/xxx 2>& 1
[user@host] run: dtach -n /tmp/Y sleep 100 >> /tmp/xxx 2>&1
这在所有主机上都能正常工作.但这不适合我的情况,因为:
This is working fine in all hosts. But this does not fit my scenario, because:
- dtach创建两个进程:一个用于dtach本身,另一个用于正在运行的进程.
- 我无法获得启动过程的提示
推荐答案
您可能碰到臭名昭著的 织物问题#395 .这些问题最简单的解决方法是使用pty=False
运行您的任务.
You are probably bumping into the infamous Fabric issue #395. The easiet workaround for these problems is to run your task with pty=False
.
这篇关于在某些主机上将命令与Fabric一起放置在后台不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!