nicoverbruggen / phpmon

Lightweight, native Mac menu bar app that helps you manage multiple PHP installations, locate config files and more. Also interacts with Laravel Valet.
https://phpmon.app
MIT License
3.06k stars 58 forks source link

[Bug] Error when listing services #284

Closed fmfernandes closed 5 months ago

fmfernandes commented 5 months ago

Is there an existing issue for this?

Current Behavior

Hi! I'm not sure when it started to happen, but today I didn't notice the little elephant in my menu bar and tried to manually start PHP Monitor just to find out it's not starting up anymore. This is the first error message:

Screenshot 2024-04-02 at 16 05 53

Upon clicking on OK:

Screenshot 2024-04-02 at 16 06 02

I'm pretty sure it worked fine for quite some time and not sure why it stopped working, so I'm not sure if it's a Homebrew issue or PHP Monitor's.

What's interesting is that on the first screen it says I could run sudo brew services info nginx --json manually to see the error, and this is the result:

$ sudo brew services info nginx --json
Error: Your Homebrew is too outdated for `brew services`. Please run `brew update`!

If I try to run just brew update:

$ brew update
==> Updating Homebrew...
Already up-to-date.

But if I try sudo brew update:

$ sudo brew update
Error: Running Homebrew as root is extremely dangerous and no longer supported.
As Homebrew does not drop privileges on installation you would be giving all
build scripts full access to your system.

The command does work without sudo, though:

$ brew services info nginx --json
[
  {
    "name": "nginx",
    "service_name": "homebrew.mxcl.nginx",
    "running": false,
    "loaded": false,
    "schedulable": false,
    "pid": null,
    "exit_code": null,
    "user": "root",
    "status": "none",
    "file": "/Users/test/Library/LaunchAgents/homebrew.mxcl.nginx.plist",
    "command": "/opt/homebrew/opt/nginx/bin/nginx -g daemon\\ off\\;",
    "working_dir": "/opt/homebrew",
    "root_dir": null,
    "log_path": null,
    "error_log_path": null,
    "interval": null,
    "cron": null
  }
]

Not sure if it's relevant to the issue but if I run brew --version with and without sudo I get different results, respectively:

I'm also sure I only have one copy of Homebrew installed and installed it using the script provided on https://brew.sh/

Expected Behavior

PHP Monitor should start if the output of brew services info or sudo brew services info is known.

Steps To Reproduce

The app won't even start if I try to launch PHP Monitor.app.

Environment

- macOS: Sonoma 14.4.1
- Valet: 4.6.1
- PHP Monitor: 7.0.2 (Using package downloaded from releases tab)

Do you have a log file (or a screenshot) or any additional information?

Extra CLI mode is on (`~/.config/phpmon/verbose` exists).
==================================
PHP MONITOR by Nico Verbruggen
Version 7.0.2 (1455)
==================================
The current username is `test`.
The user's shell is `/bin/zsh`.
The user is running PHP Monitor with the architecture: arm64
Now running 2 core checks!
[PASS] `/opt/homebrew/bin/brew` exists (0.014 ms)
[W] PHP Monitor does not have permission to show notifications.
[E] PHP Monitor encounted an error determining notification permissions:
[E] Error Domain=UNErrorDomain Code=1 "Notifications are not allowed for this application" UserInfo={NSLocalizedDescription=Notifications are not allowed for this application}

<~~~~~~~~~~~~~~~~~~~~~~~
$ /bin/sh --noprofile -norc --login -c "export PATH=/opt/homebrew/bin:$PATH && mkdir -p ~/.config/phpmon"

[OUT]:
~~~~~~~~~~~~~~~~~~~~~~~~>

There was no /.config/phpmon/config.json file to be loaded.

<~~~~~~~~~~~~~~~~~~~~~~~
$ /bin/sh --noprofile -norc --login -c "export PATH=/opt/homebrew/bin:$PATH && ls /opt/homebrew/opt | grep php"

[OUT]:
php
php@8.1
php@8.3
~~~~~~~~~~~~~~~~~~~~~~~~>

[PASS] `ls /opt/homebrew/opt | grep php` returned php result (526.567 ms)
Now running 13 valet checks!
[PASS] `/opt/homebrew/bin/php` exists (0.015 ms)

<~~~~~~~~~~~~~~~~~~~~~~~
$ /bin/sh --noprofile -norc --login -c "export PATH=/opt/homebrew/bin:$PATH && /opt/homebrew/bin/php -v"

[OUT]:
PHP 8.3.4 (cli) (built: Mar 12 2024 23:42:26) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.4, Copyright (c) Zend Technologies
    with Xdebug v3.3.1, Copyright (c) 2002-2023, by Derick Rethans
    with Zend OPcache v8.3.4, Copyright (c), by Zend Technologies
~~~~~~~~~~~~~~~~~~~~~~~~>

[PASS] no `dyld` issue (`Library not loaded`) detected (34.542 ms)
[PASS] `valet` binary exists (0.019 ms)

<~~~~~~~~~~~~~~~~~~~~~~~
$ /bin/sh --noprofile -norc --login -c "export PATH=/opt/homebrew/bin:$PATH && cat /private/etc/sudoers.d/brew"

[OUT]:
Cmnd_Alias BREW = /opt/homebrew/bin/brew *
%admin ALL=(root) NOPASSWD:SETENV: BREW
~~~~~~~~~~~~~~~~~~~~~~~~>

[PASS] `/private/etc/sudoers.d/brew` contains brew (3.036 ms)

<~~~~~~~~~~~~~~~~~~~~~~~
$ /bin/sh --noprofile -norc --login -c "export PATH=/opt/homebrew/bin:$PATH && cat /private/etc/sudoers.d/valet"

[OUT]:
Cmnd_Alias VALET = /opt/homebrew/bin/valet *
%admin ALL=(root) NOPASSWD:SETENV: VALET
~~~~~~~~~~~~~~~~~~~~~~~~>

[PASS] `/private/etc/sudoers.d/valet` contains valet (2.634 ms)
[PASS] `.config/valet` not empty (Valet installed) (0.008 ms)
[PASS] `config.json` was valid (0.162 ms)

<~~~~~~~~~~~~~~~~~~~~~~~
$ /bin/sh --noprofile -norc --login -c "export PATH=/opt/homebrew/bin:$PATH && /opt/homebrew/bin/brew tap"

[OUT]:
1password/tap
homebrew/bundle
homebrew/services
ngrok/ngrok
shivammathur/php
~~~~~~~~~~~~~~~~~~~~~~~~>

<~~~~~~~~~~~~~~~~~~~~~~~
$ /bin/sh --noprofile -norc --login -c "export PATH=/opt/homebrew/bin:$PATH && sudo /opt/homebrew/bin/brew services info dnsmasq --json"

[OUT]:
[ERR]:
Error: Your Homebrew is too outdated for `brew services`. Please run `brew update`!
~~~~~~~~~~~~~~~~~~~~~~~~>

[FAIL] `sudo /opt/homebrew/bin/brew services info` JSON loaded (784.693 ms)
webcreative24 commented 5 months ago

@nicoverbruggen same here after today's PHPMonitor update to v 7

nicoverbruggen commented 5 months ago

This may potentially be an issue with Homebrew itself, given the error messages.

I'll check if I can reproduce this issue on my system! PHP Monitor expects a certain output to be returned, and if there's an error message it can't work correctly, of course.

If anyone else is encountering this issue, please drop a note in this issue.

nicoverbruggen commented 5 months ago

@fmfernandes And thank you for the very comprehensive bug report!

webcreative24 commented 5 months ago

Nginx also cannot be started from the CLI:

brew services start nginx
Bootstrap failed: 5: Input/output error
Try re-running the command as root for richer errors.
Error: Failure while executing; `/bin/launchctl bootstrap gui/501 /Users/serg/Library/LaunchAgents/homebrew.mxcl.nginx.plist` exited with 5.
brew services
nginx     error  256   root            ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist

it's happened after PHP Monitor update

nicoverbruggen commented 5 months ago

When something like this happens, I always recommend running the following to ensure all of Homebrew is up-to-date:

brew update
brew tap homebrew/services
brew upgrade

If that helped or fixed the issue, let me know.


@webcreative24 I believe the Valet services are run as root, so if you want to start the service manually, you need to start nginx with sudo brew services start nginx. If there's really a Homebrew issue, that explains why things aren't working, though.

webcreative24 commented 5 months ago

I tried these commands earlier today but it always says "brew is updated" so I reinstalled Brew and ran these commands again and it seems to be fixed now. Thanks for the answer @nicoverbruggen

fmfernandes commented 5 months ago

Hey @nicoverbruggen, I also run that same commands earlier today with no luck. But seeing your message I just tried it again just now:

$ brew update
==> Updating Homebrew...
Updated 1 tap (homebrew/services).
No changes to formulae or casks.

Right after that I was able to start PHP Monitor!

nicoverbruggen commented 5 months ago

Good to hear! I suspect it was a temporary Homebrew bug that was quickly fixed 😄

If it's fixed, I will now close this issue.