当我使用 fabric reboot() 时,为什么我的远程主机 return 出现错误代码 -1?
Why does my remote host return a error code -1 when I use fabric reboot()?
本地主机环境:CentOS 7、Python3.5.1、Fabric3 (1.11.1.post1)
远程主机环境:CentOS 7
fib文件:
def fuc():
reboot()
bash:
fab -f fibfile.py -H host -u root -p password
远程主机确实重新启动了,但是 returns 一个致命错误:
sudo() received nonzero return code -1 while executing 'reboot'!
现在我使用warn_only
来防止失败:
fab 文件:
def test():
with settings(warn_only=True):
reboot()
我在使用ansible的时候发现了类似的问题:
我认为最佳答案是正确的:
reboot
is shutting down the server so quickly that the server is tearing down the SSH connection.
shutdown -r now
return同样的致命错误:
sudo() received nonzero return code -1 while executing 'shutdown -r now'!
shutdown -r +1
return 成功:
out: Shutdown scheduled for Mon 2016-05-23 14:16:48 UTC, use 'shutdown -c' to cancel.
但是关机最多只能延迟一分钟。
所以我们只能选择等待一分钟或者忽略错误。
我开始在一些新的虚拟机上遇到这个问题。正如 Jon Stark 所说,我认为他们关闭得太快了。
为了修复它,我忽略了错误和警告,就像这样。
with settings(hide('warnings'),
warn_only=True,
):
sudo("shutdown -r now")
您可以将 shell 会话置于后台,它会休眠 1 秒,然后执行 reboot
命令。由于 nohup issue,必须在不使用 nohup
命令的情况下完成。我使用 tmux
...
reboot(command='tmux new-session -d "sleep 1; reboot;"')
本地主机环境:CentOS 7、Python3.5.1、Fabric3 (1.11.1.post1)
远程主机环境:CentOS 7
fib文件:
def fuc():
reboot()
bash:
fab -f fibfile.py -H host -u root -p password
远程主机确实重新启动了,但是 returns 一个致命错误:
sudo() received nonzero return code -1 while executing 'reboot'!
现在我使用warn_only
来防止失败:
fab 文件:
def test():
with settings(warn_only=True):
reboot()
我在使用ansible的时候发现了类似的问题:
我认为最佳答案是正确的:
reboot
is shutting down the server so quickly that the server is tearing down the SSH connection.
shutdown -r now
return同样的致命错误:
sudo() received nonzero return code -1 while executing 'shutdown -r now'!
shutdown -r +1
return 成功:
out: Shutdown scheduled for Mon 2016-05-23 14:16:48 UTC, use 'shutdown -c' to cancel.
但是关机最多只能延迟一分钟。 所以我们只能选择等待一分钟或者忽略错误。
我开始在一些新的虚拟机上遇到这个问题。正如 Jon Stark 所说,我认为他们关闭得太快了。
为了修复它,我忽略了错误和警告,就像这样。
with settings(hide('warnings'),
warn_only=True,
):
sudo("shutdown -r now")
您可以将 shell 会话置于后台,它会休眠 1 秒,然后执行 reboot
命令。由于 nohup issue,必须在不使用 nohup
命令的情况下完成。我使用 tmux
...
reboot(command='tmux new-session -d "sleep 1; reboot;"')