yabai: “brew services …” doesn’t start yabai and doesn’t correctly reflect service status, while direct invocation works

brew services start|stop commands behave as if the service can be started, stopped and is running successfully, but yabai -m commands complain about failure to connect to socket.

However, socket file does exist under /tmp.

Socket file does not get created while the service is shown as “started” by brew services.

While service is supposedly running, there appears to be no yabai process.

me@machine:~$ ps aux | fgrep yabai
me            11778   0.0  0.0  4399356    796 s005  S+   11:01PM   0:00.00 fgrep yabai

When running yabai directly, yabai -m commands succeed, and socket file gets created.

Ideally, at least services could somehow accurately reflect if yabai fails to start…

Background

I install brew packages while su’ing as another user with admin privileges, but without root/sudo. I run binaries as my regular user. Never had a problem with that before.

I tried starting yabai service from (1) my regular user, from (2) that admin user, and from (3) admin user + sudo. (2) fails loudly, (3) declares that it takes root ownership over some files but otherwise succeeds (since it screwed up permissions, I assume, I wiped and reinstalled yabai after that just in case). (1) succeeds as described in the beginning of the issue. In all cases, yabai -m failed.

SIP

I did not disable SIP or install the scripting addon, so there’s that. I want to get started with yabai in restricted functionality.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 15 (2 by maintainers)

Most upvoted comments

I had the same issue, and it stems from installing brew packages from a separate ‘admin’ user, while starting the yabai brew service as a ‘regular’ user.

The yabai installation creates this folder for logs, but the ‘regular’ user does not have privileges to write files to it:

$ ls -la /usr/local/var/log/yabai 
total 8
drwxr-xr-x  4 admin   admin            128 Sep  5 22:15 ./

The plist file that comes with yabai specifies two log files in this directory, to which the yabai service will try to write at startup but will fail to do so causing yabai to terminate:

  <key>StandardOutPath</key>
  <string>/usr/local/var/log/yabai/yabai.out.log</string>
  <key>StandardErrorPath</key>
  <string>/usr/local/var/log/yabai/yabai.err.log</string>

A quick fix for this issue is to pre-create the log files and change their ownership to the ‘regular’ user:

touch /usr/local/var/log/yabai/yabai.out.log
touch /usr/local/var/log/yabai/yabai.err.log
chown regular:regular /usr/local/var/log/yabai/yabai.*.log

@koekeishiya would you consider not terminating yabai even if stdout and stderr are not writeable?

For me the issue was caused by /opt/homebrew having the wrong ownership sudo chown -R $(whoami) /opt/homebrew fixed it

I faced this exact issue with Catalina. Tried the workaround above but it didn’t help. So, I decided to create a group named brew and then give it permissions to the folders used by brew services.

  1. Go to Users & Groups in settings and create a new Group. Add users to this group that are running yabai. I named my group brew for obvious reasons.
  2. Run the following commands.
$ sudo chgrp -R brew $(brew --prefix)/*
$ ls -la $(brew --prefix)
$ sudo chmod -R g+w $(brew --prefix)/*
$ brew doctor

This should allow this new group permissions to run brew without any issues, thereby solving the permissions issue that causes yabai not to activate upon startup.