]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Apply sysctl.d migration from /usr/lib to /etc
authorwindgmbh <49904312+windgmbh@users.noreply.github.com>
Fri, 12 Nov 2021 15:51:03 +0000 (16:51 +0100)
committerAdam King <adking@redhat.com>
Sun, 17 Apr 2022 01:41:24 +0000 (21:41 -0400)
A fix regarding the SYSCTL_DIR location (#53130) requires to migrate
sysctl.d/*.conf files from /usr/lib to /etc.
Signed-off-by: Lukas Mayer <lmayer@wind.gmbh>
(cherry picked from commit a167a27f30536958e0f2c513d351642e81ba06d5)

src/cephadm/cephadm

index 8681db2493ca9fe56bca01312ef270d884dd74ab..793ea84ebacccfa30ef0a60915ec4fa22ccbbb9c 100755 (executable)
@@ -3312,6 +3312,47 @@ def install_sysctl(ctx: CephadmContext, fsid: str, daemon_type: str) -> None:
         call_throws(ctx, ['sysctl', '--system'])
 
 
+def migrate_sysctl_dir(ctx: CephadmContext, fsid: str) -> None:
+    """
+    Cephadm once used '/usr/lib/sysctl.d' for storing sysctl configuration.
+    This moves it to '/etc/sysctl.d'.
+    """
+    deprecated_location: str = '/usr/lib/sysctl.d'
+    deprecated_confs: List[str] = glob(f'{deprecated_location}/90-ceph-{fsid}-*.conf')
+    if not deprecated_confs:
+        return
+
+    file_count: int = len(deprecated_confs)
+    logger.info(f'Found sysctl {file_count} files in deprecated location {deprecated_location}. Starting Migration.')
+    for conf in deprecated_confs:
+        try:
+            shutil.move(conf, ctx.sysctl_dir)
+            file_count -= 1
+        except shutil.Error as err:
+            if str(err).endswith('already exists'):
+                logger.warning(f'Destination file already exists. Deleting {conf}.')
+                try:
+                    os.unlink(conf)
+                    file_count -= 1
+                except OSError as del_err:
+                    logger.warning(f'Could not remove {conf}: {del_err}.')
+            else:
+                logger.warning(f'Could not move {conf} from {deprecated_location} to {ctx.sysctl_dir}: {err}')
+
+    # Log successful migration
+    if file_count == 0:
+        logger.info(f'Successfully migrated sysctl config to {ctx.sysctl_dir}.')
+        return
+
+    # Log partially successful / unsuccessful migration
+    files_processed: int = len(deprecated_confs)
+    if file_count < files_processed:
+        status: str = f'partially successful (failed {file_count}/{files_processed})'
+    elif file_count == files_processed:
+        status = 'unsuccessful'
+    logger.warning(f'Migration of sysctl configuration {status}. You may want to perform a migration manually.')
+
+
 def install_base_units(ctx, fsid):
     # type: (CephadmContext, str) -> None
     """
@@ -4848,6 +4889,9 @@ def command_deploy(ctx):
     else:
         logger.info('%s daemon %s ...' % ('Deploy', ctx.name))
 
+    # Migrate sysctl conf files from /usr/lib to /etc
+    migrate_sysctl_dir(ctx, ctx.fsid)
+
     # Get and check ports explicitly required to be opened
     daemon_ports = []  # type: List[int]
 
@@ -6135,9 +6179,11 @@ def command_rm_cluster(ctx):
                 os.remove(fname)
 
     # rm sysctl settings
-    sysctl_dir = Path(ctx.sysctl_dir)
-    for p in sysctl_dir.glob(f'90-ceph-{ctx.fsid}-*.conf'):
-        p.unlink()
+    sysctl_dirs: List[Path] = [Path(ctx.sysctl_dir), Path('/usr/lib/sysctl.d')]
+
+    for sysctl_dir in sysctl_dirs:
+        for p in sysctl_dir.glob(f'90-ceph-{ctx.fsid}-*.conf'):
+            p.unlink()
 
     # cleanup remaining ceph directories
     ceph_dirs = [f'/run/ceph/{ctx.fsid}', f'/tmp/var/lib/ceph/{ctx.fsid}', f'/var/run/ceph/{ctx.fsid}']