[Freeipa-devel] [PATCH 1 of 8] Add service.is_running() helper

Mark McLoughlin markmc at redhat.com
Fri Jan 11 12:00:38 UTC 2008


# HG changeset patch
# User Mark McLoughlin <markmc at redhat.com>
# Date 1200047785 0
# Node ID b5037ba7a95d0ec53356625778d28da508545ab0
# Parent  b7a80814c4703b9e16e6dea17884f546f997b8da
Add service.is_running() helper

Add a simple helper to check whether a service is running
and make ipa-server-install use it to check whether ntpd
is running.

Signed-off-by: Mark McLoughlin <markmc at redhat.com>

diff -r b7a80814c470 -r b5037ba7a95d ipa-server/ipa-install/ipa-server-install
--- a/ipa-server/ipa-install/ipa-server-install	Fri Jan 04 16:44:33 2008 -0500
+++ b/ipa-server/ipa-install/ipa-server-install	Fri Jan 11 10:36:25 2008 +0000
@@ -239,15 +239,6 @@ def read_admin_password():
     admin_password = read_password("IPA admin")
     return admin_password
 
-def check_ntp():
-    ret_code = 1
-    p = subprocess.Popen(["/sbin/service", "ntpd", "status"], stdout=subprocess.PIPE,
-                         stderr=subprocess.PIPE)
-    stdout, stderr = p.communicate()
-
-    return p.returncode
-    
-
 def main():
     global ds
     ds = None
@@ -452,7 +443,7 @@ def main():
     print "\t   This ticket will allow you to use the IPA tools (e.g., ipa-adduser)"
     print "\t   and the web user interface."
 
-    if check_ntp() != 0:
+    if not service.is_running("ntpd"):
         print "\t3. Kerberos requires time synchronization between clients"
         print "\t   and servers for correct operation. You should consider enabling ntpd."
 
diff -r b7a80814c470 -r b5037ba7a95d ipa-server/ipaserver/service.py
--- a/ipa-server/ipaserver/service.py	Fri Jan 04 16:44:33 2008 -0500
+++ b/ipa-server/ipaserver/service.py	Fri Jan 11 10:36:25 2008 +0000
@@ -29,6 +29,14 @@ def start(service_name):
 
 def restart(service_name):
     ipautil.run(["/sbin/service", service_name, "restart"])
+    
+def is_running(service_name):
+    ret = True
+    try:
+        ipautil.run(["/sbin/service", service_name, "status"])
+    except CalledProcessError:
+        ret = False
+    return ret
     
 def chkconfig_on(service_name):
     ipautil.run(["/sbin/chkconfig", service_name, "on"])
@@ -60,6 +68,9 @@ class Service:
     def restart(self):
         restart(self.service_name)
 
+    def is_running(self):
+        return is_running(self.service_name)
+
     def chkconfig_on(self):
         chkconfig_on(self.service_name)
 




More information about the Freeipa-devel mailing list