python - 如何在 Fabric 2 中等待 shell 脚本重启
问题描述
我正在使用 Fabric 2,并尝试在多个主机上按顺序运行 shell 脚本。在脚本中,它配置了一些设置并重新启动该主机。但是,当我运行我的任务时,它会在脚本在第一台主机上运行后结束(我猜是因为 SSH 连接由于重新启动而终止)。我尝试将 'warn_only' 设置为 True,但我看不到在 Fabric 2 上设置此值的位置。
添加:
with settings(warn_only=True):
引发“NameError:未定义全局名称'settings'”错误。
warn_only 是否有正确的格式?如果在 Fabric 2 中还不可能,是否有办法继续运行我的任务,而不管这次重新启动如何?
我的脚本:
from fabric import *
import time
import csv
@task
def test(ctx):
hosts = ['1.1.1.1', '2.2.2.2']
for host in hosts:
c = Connection(host=host, user="user", connect_kwargs={"password": "password"})
c.run("./shell_script.sh")
configured = False
while not configured:
result = c.run("cat /etc/hostname")
if result != "default": configured = True
time.sleep(10)
解决方案
看起来您可以使用config
连接类的参数而不是with settings()
构造,并且warn_only
已重命名为warn
;
with Connection(host=host, user="user", connect_kwargs={"password": "password"}) as c:
c.run("./shell_script.sh", warn=True)
推荐阅读
- php - 如何在 php 中为 google drive api 添加多种 mime 类型
- c# - 有没有办法获取快捷链接的图标?
- c - 每次使用时对结构进行类型定义是否都会重新引入它?
- python - 转换日期类型
- php - 来自表单的mailchimp PHP API发送组
- javascript - 为什么我不能为变量 x 赋值
- java - 将 java 作为 java 应用程序运行与在服务器上运行的区别
- java - 比较两个 JSON 并显示我们更改了哪一列的活动?
- c++ - 使用动态索引访问参数包类型元组的单个元素
- html - 在 Vue3 中使用 InputMask PrimeVue 的问题