当我使用fabric reboot()时,为什么远程主机返回错误代码1?

2024-03-29 09:05:21 发布

您现在位置:Python中文网/ 问答频道 /正文

本地主机环境:CentOS 7、Python 3.5.1、Fabric3(1.11.1.post1)
远程主机环境:CentOS 7

光纤文件:

def fuc():
    reboot()

巴什:

^{pr2}$

远程主机已重新启动,但返回fatalError:

sudo() received nonzero return code -1 while executing 'reboot'!

现在我使用warn_only来防止失败:

工厂文件:

def test():
    with settings(warn_only=True):
        reboot()

Tags: 文件only远程环境defsudofabric3post1
3条回答

您可以将shell会话置于后台,该会话休眠1秒,然后执行reboot命令。由于nohup issue,必须在不使用nohup命令的情况下完成。我用tmux。。。在

reboot(command='tmux new-session -d "sleep 1; reboot;"')

我在使用ansible时发现了一个类似的问题:link

我认为最重要的答案是正确的:

reboot is shutting down the server so quickly that the server is tearing down the SSH connection.

{cd1>返回相同的错误^:

sudo() received nonzero return code -1 while executing 'shutdown -r now'!

shutdown -r +1返回成功:

out: Shutdown scheduled for Mon 2016-05-23 14:16:48 UTC, use 'shutdown -c' to cancel.

但关闭只能延迟至少一分钟。 所以我们只能选择等待一分钟或忽略错误。在

我开始在一些新的虚拟机上遇到这个问题。我认为他们关闭得太快了,正如乔恩·斯塔克所说。在

为了修复它,我忽略错误和警告,就像这样。在

with settings(hide('warnings'),
              warn_only=True,
             ):
    sudo("shutdown -r now")

相关问题 更多 >