2013-02-12 19 views
1

我誤解了fabtools?我誤解了fabtools.service.is_running的作用?

當我運行:

status some-service 

它回覆

some-service stop/waiting 

但是當我運行:

def blah(): 
    if fabtools.service.is_running('some-service'): 
     print "some-service is running!" 

它說,它正在運行,當我清楚的知道這是不是。我誤解了'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 

它仍然混淆了我在這個意義上,似乎什麼檢查,如果該服務是不是有它是否正在運行

+0

什麼是目標機器操作系統? – Redian 2013-02-13 08:34:03

回答

0

你是對的。該實現僅檢查服務是否存在,而不是狀態。
我修改了行改爲:

res = sudo('service {} status|grep "running"'.format(service)) 

...現在它的工作原理。