The chkconfig --list option is not reliable as it works differently on a
F15 system with systemd enabled services, avoid using it as we have
alternative better ways.

Simo.

-- 
Simo Sorce * Red Hat, Inc * New York
>From a7252afb01770efd5c7884752811ce859893a004 Mon Sep 17 00:00:00 2001
From: Simo Sorce <sso...@redhat.com>
Date: Wed, 4 May 2011 10:21:27 -0400
Subject: [PATCH] install-scripts: avoid using --list with chkconfig

This option does not behave properly in F15 as chkconfig does not list services
moved to use systemd service files.

Plus there are more direct ways than parsing its output, which are more
reliable.

Also just testing for the availability of the service calling 'chkconfig name'
is enough.
---
 ipa-client/ipa-install/ipa-client-install |    2 +-
 ipaserver/install/service.py              |   23 ++++++-----------------
 2 files changed, 7 insertions(+), 18 deletions(-)

diff --git a/ipa-client/ipa-install/ipa-client-install b/ipa-client/ipa-install/ipa-client-install
index 5533b9ab2ea35c0d216f9cd8339570da19c66623..90f75744b2704be7a4d15d943bf0eb3038abba11 100755
--- a/ipa-client/ipa-install/ipa-client-install
+++ b/ipa-client/ipa-install/ipa-client-install
@@ -169,7 +169,7 @@ def chkconfig(name, status):
 
     chkconfig returns 1 if the service is unknown, 0 otherwise
     """
-    (sout, serr, returncode) = run(['/sbin/chkconfig', name, '--list'], raiseonerr=False)
+    (sout, serr, returncode) = run(['/sbin/chkconfig', name], raiseonerr=False)
 
     # If the service isn't installed return with no error
     if returncode == 1:
diff --git a/ipaserver/install/service.py b/ipaserver/install/service.py
index 1ebd96d7b48a8d8d1df41950da517e18383f2d9c..8fb321a989010222fce1cffbd32bc8ac7bc85335 100644
--- a/ipaserver/install/service.py
+++ b/ipaserver/install/service.py
@@ -73,24 +73,13 @@ def chkconfig_del(service_name):
     ipautil.run(["/sbin/chkconfig", "--del", service_name])
 
 def is_enabled(service_name):
-    (stdout, stderr, returncode) = ipautil.run(["/sbin/chkconfig", "--list", service_name])
+    runlevels = { '3':False, '4':False, '5':False }
+    for rl in runlevels:
+        (stdout, stderr, returncode) = ipautil.run(["/sbin/chkconfig", "--level", rl, service_name])
+        if returncode == 0:
+            runlevels[rl] = True
 
-    runlevels = {}
-    for runlevel in range(0, 7):
-        runlevels[runlevel] = False
-
-    for line in stdout.split("\n"):
-        parts = line.split()
-        if parts[0] == service_name:
-            for s in parts[1:]:
-                (runlevel, status) = s.split(":")[0:2]
-                try:
-                    runlevels[int(runlevel)] = status == "on"
-                except ValueError:
-                    pass
-            break
-
-    return (runlevels[3] and runlevels[4] and runlevels[5])
+    return (runlevels['3'] and runlevels['4'] and runlevels['5'])
 
 def print_msg(message, output_fd=sys.stdout):
     logging.debug(message)
-- 
1.7.4.4

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to