charlie0129 / batt

Control and limit battery charging on Apple Silicon MacBooks.
GNU General Public License v2.0
390 stars 20 forks source link

Failed to connect to unix socket #18

Open MoienBowen opened 1 month ago

MoienBowen commented 1 month ago

MBA M4, macOS 14.6.1

Installed version via brew:

brew info batt
==> batt: stable 0.2.1 (bottled)
Control and limit battery charging on Apple Silicon MacBooks
https://github.com/charlie0129/batt
Installed
/opt/homebrew/Cellar/batt/0.2.1 (7 files, 11.2MB) *

Error when setting with batt

$ sudo batt limit 80
Password:
ERRO[2024-08-28 17:54:32.433] failed to connect to unix socket. 1) Do you have adequate permissions? Please re-run as root. 2) Is the daemon running? Have installed it?
Error: failed to set limit: failed to send request: Put "http://unix/limit": dial unix /var/run/batt.sock: connect: no such file or directory
Usage:
  batt limit [percentage] [flags]

Flags:
  -h, --help   help for limit

Global Flags:
  -l, --log-level string   log level (trace, debug, info, warn, error, fatal, panic) (default "info")
charlie0129 commented 1 month ago

Hi, have you started the homebrew service? I didn't see it in the information you provided.

Or try again with the original installations in README without homebrew.

MoienBowen commented 1 month ago

Hi Charlie, I can confirm that if I install with the commande in README, everything goes well. However, if I install batt via brew, the issue shows up.

I did not get what you mean by "started the homebrew service", not sure if there is any specific service for any particular permission. Could you please tell me what should I do, please?

charlie0129 commented 1 month ago

Will brew service start batt do?

MoienBowen commented 1 month ago

After clean up batt with sudo batt uninstall, I tried with brew services start batt, there is a system notification pops-up. In the system setting, batt is listed below "Allow in the Background".

However, sudo batt limit 80 still returns the same error.

PS. the batt installed via brew is also cleaned previously via brew uninstall --force batt.

charlie0129 commented 1 month ago

Can you show the content of /tmp/batt.log?

MoienBowen commented 1 month ago

I reinstalled via brew at 18:42, and run the commands:

However, in the log, there is nothing after 18:42. The log may be gathered from the batt installed via command line.

time="2024-08-28 18:09:58.095" level=info msg="batt version v0.2.1 commit 90df4aaefb930ab05a6763c96866e8db0faf698e" time="2024-08-28 18:09:58.095" level=info msg="config loaded: main.Config{Limit:80, PreventIdleSleep:true, DisableChargingPreSleep:true, AllowNonRootAccess:true, LowerLimitDelta:2, ControlMagSafeLED:true}" time="2024-08-28 18:09:58.096" level=info msg="non-root access is allowed, chaning permissions of /var/run/batt.sock to 0777" time="2024-08-28 18:09:58.096" level=info msg="http server listening on /var/run/batt.sock" time="2024-08-28 18:09:58.096" level=debug msg="main loop starts" time="2024-08-28 18:09:58.096" level=info msg="registered and listening system sleep notifications" time="2024-08-28 18:09:58.098" level=debug msg="batteryCharge=100, lower=78, upper=80, chargingEnabled=true, isPluggedIn=true, maintainedChargingInProgress=true" time="2024-08-28 18:09:58.099" level=info msg="battery charge 100% reached 80% but charging is enabled, disabling charging" time="2024-08-28 18:10:11.958" level=info msg="set charging limit to 80" time="2024-08-28 18:10:11.959" level=debug msg="batteryCharge=100, lower=78, upper=80, chargingEnabled=false, isPluggedIn=true, maintainedChargingInProgress=false" time="2024-08-28 18:10:11.959" level=debug msg="PUT /limit 201 (2ms)" dataLength=190 latency=2 method=PUT path=/limit statusCode=201 time="2024-08-28 18:10:18.101" level=debug msg="batteryCharge=100, lower=78, upper=80, chargingEnabled=false, isPluggedIn=true, maintainedChargingInProgress=false"

charlie0129 commented 1 month ago

It seems homebrew service is having some issues. The service (batt daemon) is not running at all. I personally don't use homebrew on my Mac so some investigation is needed for me to see what is going on.

Is the commandline installation method feasible? In this way it should run as intended.

MoienBowen commented 1 month ago

Yes, I am currently using the batt installed via command line. Thanks a lot. :D