(ctx)
| 4117 | |
| 4118 | |
| 4119 | def command_rm_daemon(ctx): |
| 4120 | # type: (CephadmContext) -> None |
| 4121 | lock = FileLock(ctx, ctx.fsid) |
| 4122 | lock.acquire() |
| 4123 | |
| 4124 | ident = DaemonIdentity.from_context(ctx) |
| 4125 | try: |
| 4126 | # attempt a fast-path conversion that maps the fsid+name to |
| 4127 | # the systemd service name, verifying that there is such a service |
| 4128 | call_throws(ctx, ['systemctl', 'status', ident.service_name]) |
| 4129 | unit_name = ident.service_name |
| 4130 | except RuntimeError: |
| 4131 | # fall back to looking up all possible services that might match |
| 4132 | # (JJM) Preserved this operation in case theres some backwards compat |
| 4133 | # issues where the DaemonIdentity derived name is not correct. |
| 4134 | unit_name = lookup_unit_name_by_daemon_name(ctx, ctx.fsid, ctx.name) |
| 4135 | |
| 4136 | if ident.daemon_type in ['mon', 'osd'] and not ctx.force: |
| 4137 | raise Error('must pass --force to proceed: ' |
| 4138 | 'this command may destroy precious data!') |
| 4139 | |
| 4140 | terminate_service(ctx, unit_name) |
| 4141 | |
| 4142 | # clean up any extra systemd unit files |
| 4143 | sd_path_info = systemd_unit.sidecars_from_dropin( |
| 4144 | systemd_unit.PathInfo(ctx.unit_dir, ident), missing_ok=True |
| 4145 | ) |
| 4146 | for sc_unit in sd_path_info.sidecar_unit_files.values(): |
| 4147 | terminate_service(ctx, sc_unit.name) |
| 4148 | unlink_file(sc_unit, missing_ok=True) |
| 4149 | terminate_service(ctx, sd_path_info.init_ctr_unit_file.name) |
| 4150 | unlink_file(sd_path_info.init_ctr_unit_file, missing_ok=True) |
| 4151 | unlink_file(sd_path_info.drop_in_file, missing_ok=True) |
| 4152 | try: |
| 4153 | sd_path_info.drop_in_file.parent.rmdir() |
| 4154 | except OSError: |
| 4155 | pass |
| 4156 | |
| 4157 | # force remove rgw admin socket file if leftover |
| 4158 | if ident.daemon_type in ['rgw']: |
| 4159 | rgw_asok_path = f'/var/run/ceph/{ctx.fsid}/ceph-client.{ctx.name}.*.asok' |
| 4160 | call(ctx, ['rm', '-rf', rgw_asok_path], |
| 4161 | verbosity=CallVerbosity.DEBUG) |
| 4162 | |
| 4163 | data_dir = ident.data_dir(ctx.data_dir) |
| 4164 | |
| 4165 | if ident.daemon_type == 'rgw': |
| 4166 | d3n_state(ctx, data_dir, action=D3NStateAction.CLEANUP) |
| 4167 | |
| 4168 | if ident.daemon_type in ['mon', 'osd', 'prometheus'] and \ |
| 4169 | not ctx.force_delete_data: |
| 4170 | # rename it out of the way -- do not delete |
| 4171 | backup_dir = os.path.join(ctx.data_dir, ctx.fsid, 'removed') |
| 4172 | if not os.path.exists(backup_dir): |
| 4173 | makedirs(backup_dir, 0, 0, DATA_DIR_MODE) |
| 4174 | dirname = '%s_%s' % ( |
| 4175 | ident.daemon_name, datetime.datetime.utcnow().strftime(DATEFMT) |
| 4176 | ) |
nothing calls this directly
no test coverage detected