[Freeipa-devel] [PATCH 1/3] Preserve original service_name in services

Simo Sorce simo at redhat.com
Tue Oct 23 00:48:24 UTC 2012


From: Simo Sorce <ssorce at redhat.com>

This is needed to be able to reference stuff always wth the same name.
The platform specific private name must be kept in a platform specific
variable.
In the case of systemd we store it in systemd_name
For the redhat platform wellknown names and service name are the same so
currently no special name is needed.
---
 ipapython/platform/fedora16.py |   12 ++++++------
 ipapython/platform/systemd.py  |   19 ++++++++++---------
 2 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/ipapython/platform/fedora16.py b/ipapython/platform/fedora16.py
index 794c39e2091f9402282e18fbe162d40892cb1e0d..45b4f6e28126caab20a6bce5b583cbd6a702fcd1 100644
--- a/ipapython/platform/fedora16.py
+++ b/ipapython/platform/fedora16.py
@@ -67,16 +67,16 @@ system_units['pki_tomcatd'] = system_units['pki-tomcatd']
 
 class Fedora16Service(systemd.SystemdService):
     def __init__(self, service_name):
+        systemd_name = service_name
         if service_name in system_units:
-            service_name = system_units[service_name]
+            systemd_name = system_units[service_name]
         else:
             if len(service_name.split('.')) == 1:
                 # if service_name does not have a dot, it is not foo.service
                 # and not a foo.target. Thus, not correct service name for
                 # systemd, default to foo.service style then
-                service_name = "%s.service" % (service_name)
-        super(Fedora16Service, self).__init__(service_name)
-
+                systemd_name = "%s.service" % (service_name)
+        super(Fedora16Service, self).__init__(service_name, systemd_name)
 # Special handling of directory server service
 #
 # We need to explicitly enable instances to install proper symlinks as
@@ -104,8 +104,8 @@ class Fedora16DirectoryService(Fedora16Service):
 
     def restart(self, instance_name="", capture_output=True, wait=True):
         if len(instance_name) > 0:
-            elements = self.service_name.split("@")
-            srv_etc = os.path.join(self.SYSTEMD_ETC_PATH, self.service_name)
+            elements = self.systemd_name.split("@")
+            srv_etc = os.path.join(self.SYSTEMD_ETC_PATH, self.systemd_name)
             srv_tgt = os.path.join(self.SYSTEMD_ETC_PATH, self.SYSTEMD_SRV_TARGET % (elements[0]))
             srv_lnk = os.path.join(srv_tgt, self.service_instance(instance_name))
             if not os.path.exists(srv_etc):
diff --git a/ipapython/platform/systemd.py b/ipapython/platform/systemd.py
index c174488c08a73ce02b5f568ddd24c98d8dab83d1..6c25a79b6ecdfbda1c85ada6642a656d704fdb2d 100644
--- a/ipapython/platform/systemd.py
+++ b/ipapython/platform/systemd.py
@@ -27,25 +27,26 @@ class SystemdService(base.PlatformService):
     SYSTEMD_LIB_PATH = "/lib/systemd/system/"
     SYSTEMD_SRV_TARGET = "%s.target.wants"
 
-    def __init__(self, service_name):
+    def __init__(self, service_name, systemd_name):
         super(SystemdService, self).__init__(service_name)
-        self.lib_path = os.path.join(self.SYSTEMD_LIB_PATH, self.service_name)
+        self.systemd_name = systemd_name
+        self.lib_path = os.path.join(self.SYSTEMD_LIB_PATH, self.systemd_name)
         self.lib_path_exists = None
 
     def service_instance(self, instance_name):
         if self.lib_path_exists is None:
             self.lib_path_exists = os.path.exists(self.lib_path)
 
-        elements = self.service_name.split("@")
+        elements = self.systemd_name.split("@")
 
         # Short-cut: if there is already exact service name, return it
         if self.lib_path_exists and len(instance_name) == 0:
             if len(elements) == 1:
                 # service name is like pki-tomcatd.target or krb5kdc.service
-                return self.service_name
+                return self.systemd_name
             if len(elements) > 1 and elements[1][0] != '.':
                 # Service name is like pki-tomcatd at pki-tomcat.service and that file exists
-                return self.service_name
+                return self.systemd_name
 
         if len(elements) > 1:
             # We have dynamic service
@@ -59,7 +60,7 @@ class SystemdService(base.PlatformService):
                 if os.path.exists(srv_lib):
                     return tgt_name
 
-        return self.service_name
+        return self.systemd_name
 
     def parse_variables(self, text, separator=None):
         """
@@ -82,7 +83,7 @@ class SystemdService(base.PlatformService):
         if instance_name in base.wellknownports:
             ports = base.wellknownports[instance_name]
         else:
-            elements = self.service_name.split("@")
+            elements = self.systemd_name.split("@")
             if elements[0] in base.wellknownports:
                 ports = base.wellknownports[elements[0]]
         if ports:
@@ -141,7 +142,7 @@ class SystemdService(base.PlatformService):
     def enable(self, instance_name=""):
         if self.lib_path_exists is None:
             self.lib_path_exists = os.path.exists(self.lib_path)
-        elements = self.service_name.split("@")
+        elements = self.systemd_name.split("@")
         l = len(elements)
 
         if self.lib_path_exists and (l > 1 and elements[1][0] != '.'):
@@ -183,7 +184,7 @@ class SystemdService(base.PlatformService):
             self.__enable(instance_name)
 
     def disable(self, instance_name=""):
-        elements = self.service_name.split("@")
+        elements = self.systemd_name.split("@")
         if instance_name != "" and len(elements) > 1:
             # Remove instance, we need to do following:
             #  Remove link from /etc/systemd/system/<service>.target.wants/<service>@<instance_name>.service
-- 
1.7.1




More information about the Freeipa-devel mailing list