Preserve original service_name in services

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.
This commit is contained in:
Simo Sorce 2012-10-22 20:48:24 -04:00 committed by Rob Crittenden
parent 3d7ff982ec
commit 09dbc1f36b
2 changed files with 16 additions and 15 deletions

View File

@ -71,16 +71,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
@ -108,8 +108,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):

View File

@ -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@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