【问题标题】:Reading logs with fabric用织物读取日志
【发布时间】:2013-06-10 18:39:05
【问题描述】:

我正在尝试使用我的结构脚本通过 tail -f 读取日志:

@task
def log(service):
    sudo("tail -n 50 -f " + service)

使用 -f 选项,您必须通过 Ctrl-C 手动终止 tail。它不适用于结构版本(fab 日志:),Ctrl-C 不会终止远程命令:

<remote-host>$ ps aux | grep tail
root     27314  0.0  0.0  33380  1744 ?        Ss   10:49   0:00 sudo -S -p sudo password: /bin/bash -l -c tail -n 50 -f /var/log/karma/gunicorn_gevent_error.log
root     27315  0.0  0.0   5592   584 ?        S    10:49   0:00 tail -n 50 -f /var/log/karma/gunicorn_gevent_error.log
... <they stack> ...
mezhenin 27337  0.0  0.0   7788   864 pts/8    R+   10:49   0:00 grep tail

以上做事的正确方法是什么?

【问题讨论】:

  • 您究竟想如何阅读日志?这是您运行的定期任务吗?
  • @moowiz2020,我想“实时”读取日志,例如 tail -f。我在发布后手动运行此任务以检查问题。

标签: python linux shell ssh fabric


【解决方案1】:

我找到了解决这个问题的正确方法。我需要使用env.remote_interrupt = True:

env.remote_interrupt = True
env.LOG = '<path to log>'

@task
def log():
    assert(env.remote_interrupt == True)
    with settings(warn_only=True):
        sudo("tail -n 50 -f " + env.LOG)

【讨论】:

  • 这不适用于最新的 Fabric 2。而且我在新文档中找不到 remote_interrupt 的等效项。有什么提示吗?
  • @glenfant 我使用了以下connections = [...];ThreadingGroup.from_connections(connections).run("tail -f log")
猜你喜欢
  • 2017-05-12
  • 1970-01-01
  • 1970-01-01
  • 2019-03-24
  • 2018-11-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多