More apps from usSnipora

Guide

How to see and stop Homebrew services on Mac

Databases installed with Homebrew start at login and are easy to forget. Here’s how to see them all, stop the ones you don’t need, and read the parts of the output that confuse everyone.

By Anmol Sethi · Updated

In short

Run brew services list to see every service. brew services stop <formula> stops it and keeps it from starting at login; killing the process instead lets launchd start it again. error 1 means it keeps exiting with code 1 (its log is in the plist), and none while the port is taken means it was started some other way.

1. See every service

brew services list
Name        Status User  File
cloudflared error  1        you ~/Library/LaunchAgents/sh.brew.cloudflared.plist
mysql@8.4   started         you ~/Library/LaunchAgents/sh.brew.mysql@8.4.plist
redis       none
  • started: running, and starts at every login.
  • none: Homebrew isn’t running it. Something else still might be (step 4).
  • error and a number: it exited with that code, and usually keeps retrying (step 5).
  • stopped: registered but not running.

Each service is a launchd job. Current Homebrew names them sh.brew.<formula>; older installs used homebrew.mxcl.<formula>. brew services info <formula> shows one in detail, with its PID.

Rather click than type? Portlivo shows every port with its project and frees it in one click. Try it free for 7 days →

2. Stop, kill or run

brew services stop mysql@8.4    # stop now, and don't start at login
brew services kill mysql@8.4    # stop now, still start at next login
brew services run mysql@8.4     # start now, without adding it to login

Stopping the process some other way (kill, Activity Monitor) leaves the job registered, and many formulas tell launchd to restart them when they exit. Use brew services stop.

3. Why the PID doesn’t match the port

lsof -nP -iTCP -sTCP:LISTEN | grep -E 'mysqld|redis'
ps -o pid,ppid,command -p 1418,1797

brew services info mysql@8.4 gives the PID of mysqld_safe, a wrapper script; the server on port 3306 is its child, mysqld. Kill the child and the wrapper starts it again, which is another reason to stop it through Homebrew.

4. “none”, but the port is taken

A database started from a terminal (redis-server, postgres -D …) never goes through Homebrew, so brew services shows none and stop does nothing. Find it with lsof -nP -iTCP:6379 -sTCP:LISTEN, see where it was started with lsof -a -p <PID> -d cwd, and stop it with redis-cli shutdown or kill <PID>.

5. What “error 1” means

The service exited with code 1. If its plist has KeepAlive with SuccessfulExit set to false, launchd starts it again every time it fails, from every login on. The log path is in the plist under StandardErrorPath:

wc -l /opt/homebrew/var/log/cloudflared.log
  118172 /opt/homebrew/var/log/cloudflared.log

Read the log to fix the cause, or brew services stop it. brew services cleanup removes services whose formula is gone.

The one-click way: Portlivo

Portlivo lists Homebrew services by formula name next to your dev servers and containers, with the port each one holds. Stopping one runs brew services stop, so it stays stopped after a restart.

Questions people ask

How do I see all running Homebrew services?
brew services list. Anything marked started is running and starts at login.
How do I stop a Homebrew service permanently?
brew services stop <formula>. It stops the service and unregisters it, so it doesn’t come back after a restart.
Why does my Homebrew service restart after I kill it?
It’s still registered, and its plist asks launchd to keep it alive. Use brew services stop instead of kill.
What does error 1 mean in brew services list?
The service exited with code 1. Its log path is in the plist under StandardErrorPath.

Try Portlivo free for 7 days. Every feature, no account.

Download for Mac

Still have a question?

Write to us — a real developer reads every email and replies personally.

support@portlivo.com