diff options
author | John Mulligan <jmulligan@redhat.com> | 2023-11-18 17:50:29 +0100 |
---|---|---|
committer | John Mulligan <jmulligan@redhat.com> | 2024-01-02 15:30:21 +0100 |
commit | 2d8045d96f1a305b57a34ff96c130959821c393f (patch) | |
tree | 1e51a63aa0b929a416882cdf4b3a1b8557286cac /src/cephadm/cephadm.py | |
parent | cephadm: add a terminate_service systemd function (diff) | |
download | ceph-2d8045d96f1a305b57a34ff96c130959821c393f.tar.xz ceph-2d8045d96f1a305b57a34ff96c130959821c393f.zip |
cephadm: minor reorgs to command_rm_daemon
Make a few small chanes to command_rm_daemon to clean it up in
preparation for future changes. Move the construction of a
DaemonIdentity earlier and use the service name derived directly from it
if possible. I didn't remove the old approach of looking up a service
name in the listing because I don't know if doing so would break
old/adopted services and there's no unit test coverage for that.
Signed-off-by: John Mulligan <jmulligan@redhat.com>
Diffstat (limited to '')
-rwxr-xr-x | src/cephadm/cephadm.py | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index 82e29d941ee..c44dfbecbde 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -4136,10 +4136,19 @@ def command_rm_daemon(ctx): lock = FileLock(ctx, ctx.fsid) lock.acquire() - (daemon_type, daemon_id) = ctx.name.split('.', 1) - unit_name = lookup_unit_name_by_daemon_name(ctx, ctx.fsid, ctx.name) - - if daemon_type in ['mon', 'osd'] and not ctx.force: + ident = DaemonIdentity.from_context(ctx) + try: + # attempt a fast-path conversion that maps the fsid+name to + # the systemd service name, verifying that there is such a service + call_throws(ctx, ['systemctl', 'status', ident.service_name]) + unit_name = ident.service_name + except RuntimeError: + # fall back to looking up all possible services that might match + # (JJM) Preserved this operation in case theres some backwards compat + # issues where the DaemonIdentity derived name is not correct. + unit_name = lookup_unit_name_by_daemon_name(ctx, ctx.fsid, ctx.name) + + if ident.daemon_type in ['mon', 'osd'] and not ctx.force: raise Error('must pass --force to proceed: ' 'this command may destroy precious data!') @@ -4151,21 +4160,21 @@ def command_rm_daemon(ctx): verbosity=CallVerbosity.DEBUG) # force remove rgw admin socket file if leftover - if daemon_type in ['rgw']: + if ident.daemon_type in ['rgw']: rgw_asok_path = f'/var/run/ceph/{ctx.fsid}/ceph-client.{ctx.name}.*.asok' call(ctx, ['rm', '-rf', rgw_asok_path], verbosity=CallVerbosity.DEBUG) - ident = DaemonIdentity(ctx.fsid, daemon_type, daemon_id) data_dir = ident.data_dir(ctx.data_dir) - if daemon_type in ['mon', 'osd', 'prometheus'] and \ + if ident.daemon_type in ['mon', 'osd', 'prometheus'] and \ not ctx.force_delete_data: # rename it out of the way -- do not delete backup_dir = os.path.join(ctx.data_dir, ctx.fsid, 'removed') if not os.path.exists(backup_dir): makedirs(backup_dir, 0, 0, DATA_DIR_MODE) - dirname = '%s.%s_%s' % (daemon_type, daemon_id, - datetime.datetime.utcnow().strftime(DATEFMT)) + dirname = '%s_%s' % ( + ident.daemon_name, datetime.datetime.utcnow().strftime(DATEFMT) + ) os.rename(data_dir, os.path.join(backup_dir, dirname)) else: |