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!')
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: