Walt Stoneburner's Ramblings

Currating Chaos

Toggling Apple's Spotlight by the CLI

Every once in a while, Apple does an update that causes the machine to eat up CPU cycles and go in a tail spin, filling the log with mds and mdsworker issues.

As of 2020-09-17 with macOS Mojave v10.14.16, the problem appears to have been introduced as of Security Update 2020-003, and people are very unhappy on Apple's forum in multiple topic about the same subject. The problem still exists as of Security Update 2020-004.

For instance, I'm seeing the error message below tens of thousands of times as launchd spins up a process, another process skills it, and the cycle repeats because launchd sees the process didn't start:

Sep 17 14:35:50 langbox com.apple.xpc.launchd[1] (com.apple.mdworker.shared.00000000-0000-0000-0000-000000000000[524]): Service exited due to SIGKILL | sent by mds[72]

This is the metadata service that's indexing your drives, and it's what's providing the information to SpotLight so you can easily find things.

Turn Spotlight Indexing Off

It's not manadatory to have these services running, but it's very much part of the Apple operating system expereince.

When this kind of problem happens, sometimes it makes sense to just turn off Spotlight (until Apple fixes it with a patch):

$ sudo mdutil -a -i off

Without a drive provided as an argument, this will turn off Spotlight indexing for all connected drives, TimeMachine included.

Be forewarned, Spotlight is highly integrated with a lot of services, one of which is Mail. Turn off Spotlight and you'll discover you can no longer search your inbox.

Turn Spotlight Indexing On

Here's the catch, turning it back on again can take hours to reindex your drives, possibly days if you have huge drives of spinning rust (opposed to solid state drives).

$ sudo mdutil -a -i on

Just Force a Spotlight Index Rebuild

You can also force SpotLight to erase and rebuild the index via:

$ sudo mdutil -E

Note, again, if a volume isn't specified, it will affect them all.