Python 我是否误解了fabtools.service.is_正在运行的功能?
我是不是误会了你的工具 当我跑步时:Python 我是否误解了fabtools.service.is_正在运行的功能?,python,fabric,upstart,Python,Fabric,Upstart,我是不是误会了你的工具 当我跑步时: status some-service def blah(): if fabtools.service.is_running('some-service'): print "some-service is running!" 它回答说 some-service stop/waiting 但当我跑步时: status some-service def blah(): if fabtools.service.is_runn
status some-service
def blah():
if fabtools.service.is_running('some-service'):
print "some-service is running!"
它回答说
some-service stop/waiting
但当我跑步时:
status some-service
def blah():
if fabtools.service.is_running('some-service'):
print "some-service is running!"
它说它正在运行,而我清楚地知道它不是。我是否误解了“正在运行”功能的作用
编辑:
查看源代码:
def is_running(service):
"""
Check if a service is running.
::
import fabtools
if fabtools.service.is_running('foo'):
print "Service foo is running!"
"""
with settings(hide('running', 'stdout', 'stderr', 'warnings'), warn_only=True):
res = sudo('service %(service)s status' % locals())
return res.succeeded
它仍然让我感到困惑,因为它似乎在检查服务是否存在,而不是它是否正在运行你是对的。实现只检查服务是否存在,而不检查状态。 我将行修改为:
res = sudo('service {} status|grep "running"'.format(service))
…现在它可以工作了。fabtools.service.u正在运行,现在确实可以工作了
当我停止kibana服务并在python命令行模式下运行此服务时,请参见以下内容:
>>> fabtools.service.is_running('kibana')
False
当我启动kibana服务时,它返回true
>>> fabtools.service.is_running('kibana')
True
什么是目标机器操作系统?