From 7cd9c2443cc7b7fc881320742bf6c8cac9f66894 Mon Sep 17 00:00:00 2001
From: Mark Reynolds <mreynolds@redhat.com>
Date: Mon, 5 Aug 2019 12:52:05 -0400
Subject: [PATCH] Beta for db home directory

---
 ldap/admin/src/defaults.inf.in       | 1 +
 ldap/ldif/template-dse.ldif.in       | 1 +
 rpm/389-ds-base.spec.in              | 2 ++
 src/lib389/lib389/instance/remove.py | 1 +
 src/lib389/lib389/instance/setup.py  | 9 ++++++---
 src/lib389/lib389/paths.py           | 4 +++-
 6 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/ldap/admin/src/defaults.inf.in b/ldap/admin/src/defaults.inf.in
index f74929581..f19fb1786 100644
--- a/ldap/admin/src/defaults.inf.in
+++ b/ldap/admin/src/defaults.inf.in
@@ -57,6 +57,7 @@ access_log = @localstatedir@/log/dirsrv/slapd-{instance_name}/access
 audit_log = @localstatedir@/log/dirsrv/slapd-{instance_name}/audit
 error_log = @localstatedir@/log/dirsrv/slapd-{instance_name}/errors
 db_dir = @localstatedir@/lib/dirsrv/slapd-{instance_name}/db
+db_home_dir = /dev/shm/dirsrv/slapd-{instance_name}
 backup_dir = @localstatedir@/lib/dirsrv/slapd-{instance_name}/bak
 ldif_dir = @localstatedir@/lib/dirsrv/slapd-{instance_name}/ldif
 
diff --git a/ldap/ldif/template-dse.ldif.in b/ldap/ldif/template-dse.ldif.in
index 9efff58c5..19abcf841 100644
--- a/ldap/ldif/template-dse.ldif.in
+++ b/ldap/ldif/template-dse.ldif.in
@@ -905,6 +905,7 @@ objectclass: extensibleObject
 cn: config
 nsslapd-mode: 600
 nsslapd-directory: %db_dir%
+nsslapd-db-home-directory: %db_home_dir%
 nsslapd-subtree-rename-switch: on
 
 dn: cn=default indexes, cn=config,cn=ldbm database,cn=plugins,cn=config
diff --git a/rpm/389-ds-base.spec.in b/rpm/389-ds-base.spec.in
index 53f3a0b82..7669287bb 100644
--- a/rpm/389-ds-base.spec.in
+++ b/rpm/389-ds-base.spec.in
@@ -430,6 +430,7 @@ popd
 mkdir -p $RPM_BUILD_ROOT/var/log/%{pkgname}
 mkdir -p $RPM_BUILD_ROOT/var/lib/%{pkgname}
 mkdir -p $RPM_BUILD_ROOT/var/lock/%{pkgname}
+mkdir -p $RPM_BUILD_ROOT/dev/shm/%{pkgname}
 
 # for systemd
 mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/systemd/system/%{groupname}.wants
@@ -634,6 +635,7 @@ exit 0
 %{_prefix}/lib/sysctl.d/*
 %dir %{_localstatedir}/lib/%{pkgname}
 %dir %{_localstatedir}/log/%{pkgname}
+%dir /dev/shm/%{pkgname}
 %ghost %dir %{_localstatedir}/lock/%{pkgname}
 %exclude %{_sbindir}/ldap-agent*
 %exclude %{_mandir}/man1/ldap-agent.1.gz
diff --git a/src/lib389/lib389/instance/remove.py b/src/lib389/lib389/instance/remove.py
index c9a872eb7..158c481cb 100644
--- a/src/lib389/lib389/instance/remove.py
+++ b/src/lib389/lib389/instance/remove.py
@@ -44,6 +44,7 @@ def remove_ds_instance(dirsrv, force=False):
     remove_paths['cert_dir'] = dirsrv.ds_paths.cert_dir
     remove_paths['config_dir'] = dirsrv.ds_paths.config_dir
     remove_paths['db_dir'] = dirsrv.ds_paths.db_dir
+    remove_paths['db_home_dir'] = dirsrv.ds_paths.db_home_dir
     remove_paths['db_dir_parent'] = dirsrv.ds_paths.db_dir + "/../"
     ### WARNING: The changelogdb isn't removed. we assume it's in:
     # db_dir ../changelogdb. So remove that too!
diff --git a/src/lib389/lib389/instance/setup.py b/src/lib389/lib389/instance/setup.py
index bb0ff32f5..58cd09c17 100644
--- a/src/lib389/lib389/instance/setup.py
+++ b/src/lib389/lib389/instance/setup.py
@@ -275,6 +275,7 @@ class SetupDs(object):
                  'inst_dir': ds_paths.inst_dir,
                  'backup_dir': ds_paths.backup_dir,
                  'db_dir': ds_paths.db_dir,
+                 'db_home_dir': ds_paths.db_home_dir,
                  'ldif_dir': ds_paths.ldif_dir,
                  'lock_dir': ds_paths.lock_dir,
                  'log_dir': ds_paths.log_dir,
@@ -733,11 +734,12 @@ class SetupDs(object):
                 ds_suffix=ds_suffix,
                 config_dir=slapd['config_dir'],
                 db_dir=slapd['db_dir'],
+                db_home_dir=slapd['db_home_dir']
             ))
 
         # Create all the needed paths
         # we should only need to make bak_dir, cert_dir, config_dir, db_dir, ldif_dir, lock_dir, log_dir, run_dir?
-        for path in ('backup_dir', 'cert_dir', 'db_dir', 'ldif_dir', 'lock_dir', 'log_dir', 'run_dir'):
+        for path in ('backup_dir', 'cert_dir', 'db_dir', 'db_home_dir', 'ldif_dir', 'lock_dir', 'log_dir', 'run_dir'):
             self.log.debug("ACTION: creating %s", slapd[path])
             try:
                 os.umask(0o007)  # For parent dirs that get created -> sets 770 for perms
@@ -853,8 +855,9 @@ class SetupDs(object):
 
         # Do selinux fixups
         if general['selinux']:
-            selinux_paths = ('backup_dir', 'cert_dir', 'config_dir', 'db_dir', 'ldif_dir',
-                             'lock_dir', 'log_dir', 'run_dir', 'schema_dir', 'tmp_dir')
+            selinux_paths = ('backup_dir', 'cert_dir', 'config_dir', 'db_dir',
+                             'db_home_dir', 'ldif_dir', 'lock_dir', 'log_dir',
+                             'run_dir', 'schema_dir', 'tmp_dir')
             for path in selinux_paths:
                 selinux_restorecon(slapd[path])
 
diff --git a/src/lib389/lib389/paths.py b/src/lib389/lib389/paths.py
index b1734ed22..d4e86b9d9 100644
--- a/src/lib389/lib389/paths.py
+++ b/src/lib389/lib389/paths.py
@@ -57,6 +57,7 @@ MUST = [
     'log_dir',
     'inst_dir',
     'db_dir',
+    'db_home_dir',
     'backup_dir',
     'ldif_dir',
     'initconfig_dir',
@@ -76,6 +77,7 @@ CONFIG_MAP = {
     'lock_dir' : ('cn=config','nsslapd-lockdir'),
     'inst_dir' : ('cn=config','nsslapd-instancedir'),
     'db_dir' : ('cn=config,cn=ldbm database,cn=plugins,cn=config', 'nsslapd-directory'),
+    'db_home_dir' : ('cn=config,cn=ldbm database,cn=plugins,cn=config', 'nsslapd-db-home-directory'),
     'backup_dir': ('cn=config','nsslapd-bakdir'),
     'ldif_dir': ('cn=config','nsslapd-ldifdir'),
     'error_log' : ('cn=config', 'nsslapd-errorlog'),
@@ -126,7 +128,7 @@ class Paths(object):
         for spath in search_paths:
             if os.path.isfile(spath):
                 return spath
-        raise IOError('defaults.inf not found in any wellknown location!')
+        raise IOError('defaults.inf not found in any well known location!')
 
     def _read_defaults(self):
         spath = self._get_defaults_loc(DEFAULTS_PATH)
-- 
2.21.0

