diff options
author | Martin Babinsky <mbabinsk@redhat.com> | 2015-01-21 13:40:36 +0100 |
---|---|---|
committer | Martin Kosek <mkosek@redhat.com> | 2015-01-27 13:35:06 +0100 |
commit | 55b7eed77e5f76c159ba157d020e93aa9d43bdc5 (patch) | |
tree | 9b587e418aef58783595608b272042d6564896b0 /ipaserver/install/dsinstance.py | |
parent | c90286cbbc1ab21e185c4d60d3a86142172c47ca (diff) | |
download | freeipa-55b7eed77e5f76c159ba157d020e93aa9d43bdc5.tar.gz freeipa-55b7eed77e5f76c159ba157d020e93aa9d43bdc5.tar.xz freeipa-55b7eed77e5f76c159ba157d020e93aa9d43bdc5.zip |
Use 'remove-ds.pl' to remove DS instance
The patch adds a function which calls 'remove-ds.pl' during DS instance
removal. This should allow for a more thorough removal of DS related data
during server uninstallation (such as closing custom ports, cleaning up
slapd-* entries etc.)
This patch is related to https://fedorahosted.org/freeipa/ticket/4487.
Reviewed-By: Martin Basti <mbasti@redhat.com>
Diffstat (limited to 'ipaserver/install/dsinstance.py')
-rw-r--r-- | ipaserver/install/dsinstance.py | 62 |
1 files changed, 35 insertions, 27 deletions
diff --git a/ipaserver/install/dsinstance.py b/ipaserver/install/dsinstance.py index 66267f4cd..1e07c6d0d 100644 --- a/ipaserver/install/dsinstance.py +++ b/ipaserver/install/dsinstance.py @@ -64,6 +64,7 @@ IPA_SCHEMA_FILES = ("60kerberos.ldif", "15rfc4876.ldif") ALL_SCHEMA_FILES = IPA_SCHEMA_FILES + ("05rfc2247.ldif", ) +DS_INSTANCE_PREFIX = 'slapd-' def find_server_root(): @@ -81,29 +82,29 @@ def config_dirname(serverid): def schema_dirname(serverid): return config_dirname(serverid) + "/schema/" -def erase_ds_instance_data(serverid): - installutils.rmtree(paths.ETC_DIRSRV_SLAPD_INSTANCE_TEMPLATE % serverid) - installutils.rmtree(paths.USR_LIB_SLAPD_INSTANCE_TEMPLATE % serverid) - - installutils.rmtree(paths.USR_LIB_DIRSRV_SLAPD_INSTANCE_DIR_TEMPLATE % serverid) - - installutils.rmtree(paths.VAR_LIB_SLAPD_INSTANCE_DIR_TEMPLATE % serverid) - - installutils.rmtree(paths.SLAPD_INSTANCE_LOCK_TEMPLATE % serverid) - - installutils.remove_file(paths.SLAPD_INSTANCE_SOCKET_TEMPLATE % serverid) - - installutils.rmtree(paths.VAR_LIB_DIRSRV_INSTANCE_SCRIPTS_TEMPLATE % serverid) - - installutils.remove_file(paths.DS_KEYTAB) - - installutils.remove_file(paths.SYSCONFIG_DIRSRV_INSTANCE % serverid) +def remove_ds_instance(serverid, force=False): + """A wrapper around the 'remove-ds.pl' script used by + 389ds to remove a single directory server instance. In case of error + additional call with the '-f' flag is performed (forced removal). If this + also fails, then an exception is raised. + """ + instance_name = ''.join([DS_INSTANCE_PREFIX, serverid]) + args = [paths.REMOVE_DS_PL, '-i', instance_name] + if force: + args.append('-f') + root_logger.debug("Forcing instance removal") + + try: + ipautil.run(args) + except ipautil.CalledProcessError: + if force: + root_logger.error("Instance removal failed.") + raise + root_logger.debug("'%s' failed. " + "Attempting to force removal" % paths.REMOVE_DS_PL) + remove_ds_instance(serverid, force=True) -# try: -# shutil.rmtree(paths.VAR_LOG_DIRSRV_INSTANCE_TEMPLATE % serverid) -# except: -# pass def get_ds_instances(): ''' @@ -113,8 +114,7 @@ def get_ds_instances(): matches 389ds behavior. ''' - dirsrv_instance_dir=paths.ETC_DIRSRV - instance_prefix = 'slapd-' + dirsrv_instance_dir = paths.ETC_DIRSRV instances = [] @@ -123,9 +123,10 @@ def get_ds_instances(): # Must be a directory if os.path.isdir(pathname): # Must start with prefix and not end with .removed - if basename.startswith(instance_prefix) and not basename.endswith('.removed'): + if (basename.startswith(DS_INSTANCE_PREFIX) and + not basename.endswith('.removed')): # Strip off prefix - instance = basename[len(instance_prefix):] + instance = basename[len(DS_INSTANCE_PREFIX):] # Must be non-empty if instance: instances.append(instance) @@ -774,9 +775,16 @@ class DsInstance(service.Service): self.disable() serverid = self.restore_state("serverid") - if not serverid is None: + if serverid is not None: self.stop_tracking_certificates(serverid) - erase_ds_instance_data(serverid) + root_logger.debug("Removing DS instance %s" % serverid) + try: + remove_ds_instance(serverid) + root_logger.debug("Removing DS keytab") + installutils.remove_file(paths.DS_KEYTAB) + except ipautil.CalledProcessError: + root_logger.error("Failed to remove DS instance. You may " + "need to remove instance data manually") # At one time we removed this user on uninstall. That can potentially # orphan files, or worse, if another useradd runs in the intermim, |