]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
ceph-daemon: implement 'adopt' for legacy style daemons
authorSage Weil <sage@redhat.com>
Wed, 2 Oct 2019 21:19:14 +0000 (16:19 -0500)
committerSage Weil <sage@redhat.com>
Sat, 5 Oct 2019 01:33:35 +0000 (20:33 -0500)
Caveats:

 - this doesn't clean out /etc/ceph/*, since we don't know which is the
   last daemon to go, and/or whether the user wants to keep it around
   for using the ceph CLI on this host
 - leaves behind /var/lib/ceph/bootstrap-* keys, even after all daemons
   have been converted.

Signed-off-by: Sage Weil <sage@redhat.com>
src/ceph-daemon

index 3017fa2578571838d77a2c1105ed34dc6222ca9f..af8f7ff852712d8cafe86c52f90c8070c95648ae 100755 (executable)
@@ -84,8 +84,8 @@ def get_legacy_config_fsid(cluster):
         if 'global' in config and 'fsid' in config['global']:
             return config['global']['fsid']
     except:
-        return 'unknown'
-    return 'unknown'
+        return None
+    return None
 
 def get_legacy_daemon_fsid(cluster_name, daemon_type, daemon_id):
     fsid = None
@@ -272,7 +272,8 @@ def deploy_daemon(fsid, daemon_type, daemon_id, c, uid, gid,
 
     deploy_daemon_units(fsid, daemon_type, daemon_id, c)
 
-def deploy_daemon_units(fsid, daemon_type, daemon_id, c):
+def deploy_daemon_units(fsid, daemon_type, daemon_id, c,
+                        enable=True, start=True):
     # cmd
     data_dir = get_data_dir(args.data_dir, fsid, daemon_type, daemon_id)
     with open(data_dir + '/cmd', 'w') as f:
@@ -290,8 +291,10 @@ def deploy_daemon_units(fsid, daemon_type, daemon_id, c):
     subprocess.check_output(['systemctl', 'daemon-reload'])
 
     unit_name = get_unit_name(fsid, daemon_type, daemon_id)
-    subprocess.check_output(['systemctl', 'enable', unit_name])
-    subprocess.check_output(['systemctl', 'start', unit_name])
+    if enable:
+        subprocess.check_output(['systemctl', 'enable', unit_name])
+    if start:
+        subprocess.check_output(['systemctl', 'start', unit_name])
 
 def install_base_units(fsid):
     """
@@ -864,6 +867,61 @@ def command_ls():
 
 ##################################
 
+def command_adopt():
+    (daemon_type, daemon_id) = args.name.split('.')
+    if args.style == 'legacy':
+        fsid = get_legacy_daemon_fsid(args.cluster, daemon_type, daemon_id)
+        if not fsid:
+            raise RuntimeError('could not detect fsid; add fsid = to ceph.conf')
+
+        # NOTE: implicit assumption here that the units correspond to the
+        # cluster we are adopting based on the /etc/{defaults,sysconfig}/ceph
+        # CLUSTER field.
+        unit_name = 'ceph-%s@%s' % (daemon_type, daemon_id)
+        (enabled, active) = check_unit(unit_name)
+
+        if active:
+            logging.info('Stopping old systemd unit %s...' % unit_name)
+            subprocess.check_output(['systemctl', 'stop', unit_name])
+        if enabled:
+            logging.info('Disabling old systemd unit %s...' % unit_name)
+            subprocess.check_output(['systemctl', 'disable', unit_name])
+
+        logging.info('Moving data...')
+        makedirs(os.path.join(args.data_dir, fsid))
+        data_dir = get_data_dir(args.data_dir, fsid, daemon_type, daemon_id)
+        subprocess.check_output([
+            'mv',
+            '/var/lib/ceph/%s/%s-%s' % (daemon_type, args.cluster, daemon_id),
+            data_dir])
+        subprocess.check_output([
+            'cp',
+            '/etc/ceph/%s.conf' % args.cluster,
+            os.path.join(data_dir, 'config')])
+
+        logging.info('Moving logs...')
+        log_dir = get_log_dir(args.log_dir, fsid)
+        makedirs(log_dir)
+        try:
+            subprocess.check_output(
+                ['mv',
+                 '/var/log/ceph/%s-%s.%s.log*' % (args.cluster,
+                                                  daemon_type, daemon_id),
+                 os.path.join(log_dir)],
+                shell=True)
+        except:
+            pass
+
+        logging.info('Creating new units...')
+        c = get_container(fsid, daemon_type, daemon_id)
+        deploy_daemon_units(fsid, daemon_type, daemon_id, c,
+                            enable=True,  # unconditionally enable the new unit
+                            start=active)
+    else:
+        raise RuntimeError('adoption of style %s not implemented' % args.style)
+
+##################################
+
 def command_rm_daemon():
     (daemon_type, daemon_id) = args.name.split('.')
     if daemon_type in ['mon', 'osd'] and not args.force:
@@ -944,6 +1002,22 @@ parser_ls = subparsers.add_parser(
     'ls', help='list daemon instances on this host')
 parser_ls.set_defaults(func=command_ls)
 
+parser_adopt = subparsers.add_parser(
+    'adopt', help='adopt daemon deployed with a different tool')
+parser_adopt.set_defaults(func=command_adopt)
+parser_adopt.add_argument(
+    '--name', '-n',
+    required=True,
+    help='daemon name (type.id)')
+parser_adopt.add_argument(
+    '--style',
+    required=True,
+    help='deployment style (legacy, ...)')
+parser_adopt.add_argument(
+    '--cluster',
+    default='ceph',
+    help='cluster name')
+
 parser_rm_daemon = subparsers.add_parser(
     'rm-daemon', help='remove daemon instance')
 parser_rm_daemon.set_defaults(func=command_rm_daemon)