如何通过fabric文件退出监控进程?
我正在使用fabric来连接到一个远程主机。在那里我调用了supervisor来查看状态。但是我不知道怎么用fabric文件退出supervisor界面。该怎么做呢?
我的fabfile是这样的:
from fabric.api import run
from fabric.api import env
env.hosts = [
'my_host'
]
def my_fab():
run("supervisorctl -u 'me' -p 'aaa'")
>>> fab my_fab
>>> # plenty of stdout
>>> supervisor> # I'm stuckled here
1 个回答
2
这段内容主要是关于如何使用 supervisorctl
,而不是 fabric
。
避免在命令中使用需要用户交互的fab调用
Fabric 是用来一次性执行命令的工具,它执行完命令后就会返回,不会在控制台上长时间停留。解决你问题的方法是不要进入交互模式(那种需要进一步输入的模式),而是只在非交互模式下调用 supervisor
。
在非交互模式下调用 supervisorctl
Supervisor 控制命令有交互模式和非交互模式。
你需要使用非交互模式。
比如在我的安装中,我有一个叫 logproxy
的服务。
这样调用 supervisorctl
:
$ supervisorctl status logproxy
logproxy STOPPED Not started
把这个应用到你的 fab 任务上就能让它正常工作。
根据“欢迎使用 Fabric!”中的示例代码,它看起来会是这样的:
from fabric.api import run
def super_status():
uname = "zen"
pswd = "then"
cmd = "supervisorctl -u {uname} -p {pswd} status logproxy".format(uname=uname, pswd=pswd)
# to see the command you are going to call, just for show
print cmd
# and run it
run(cmd)
然后可以使用它。
$ fab -l
来列出服务。
并调用任务 super_status
:
$ fab super_status -H localhost