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.07k stars 58 forks source link

Cannot determine services status #146

Closed olivierneo closed 2 years ago

olivierneo commented 2 years ago

Hi!

I just installed PHPMon and this error message appears. I checked the installation of Brew, Valet, PHP etc and also tested the JSON (see screenshot) as well as Brew's working_dir.

PHP Monitor usually queries brew using the following command to test if the services can be retrieved: sudo brew services info nginx --json.

PHP Monitor could not interpret this response.

To Reproduce Juste start the app from Alfred

Screenshots Capture d’écran 2022-03-09 à 11 13 57

Capture d’écran 2022-03-09 à 11 16 11

Required information

Thanks in advance!

nicoverbruggen commented 2 years ago

Hi @olivierneo, I'm assuming that on your system brew is located in /opt/homebrew/bin/brew? Did you run brew update?

Internally, this is what PHP Monitor runs, can you let me know what this outputs:

/bin/sh --noprofile -norc --login -c "sudo /opt/homebrew/bin/brew services info nginx --json"

Something must be going wrong with parsing that specific output. Thanks!

olivierneo commented 2 years ago

It's the good location and I did the brew update many times :(

This is the output, It seems to be alright :

Capture d’écran 2022-03-09 à 12 51 07

ITCONSULTINGAJACCCIO commented 2 years ago

Hello, i've the same issue :

[
  {
    "name": "nginx",
    "service_name": "homebrew.mxcl.nginx",
    "running": true,
    "loaded": true,
    "schedulable": false,
    "pid": 5982,
    "exit_code": 0,
    "user": "root",
    "status": "started",
    "file": "/Library/LaunchDaemons/homebrew.mxcl.nginx.plist",
    "command": "/usr/local/homebrew/opt/nginx/bin/nginx -g daemon off;",
    "working_dir": "/usr/local/homebrew",
    "root_dir": null,
    "log_path": null,
    "error_log_path": null,
    "interval": null,
    "cron": null
  }
]
nicoverbruggen commented 2 years ago

Okay, that's strange, indeed!

In order to help debug this issue, I've attached a new DEV build that should crash when attempting to decode the JSON output. It also does some extra logging in the background.

The crash log, which should appear in ~/Library/Logs/DiagnosticReports after the app quits should help me figure out what exactly goes wrong.

Additionally, you can see what the app is logging by launching PHP Monitor from the terminal, like so:

open /Applications/PHP\ Monitor\ DEV.app/Contents/MacOS/PHP\ Monitor

A terminal should open and show you the live log output.

@olivierneo If you could get me the crash log and the info that the app logs, that would be great and will probably help me get to the bottom of this :)

The easiest way to do this is to:

  1. Move the PHP Monitor DEV.app (see below) to /Applications
  2. Run open /Applications/PHP\ Monitor\ DEV.app/Contents/MacOS/PHP\ Monitor in your terminal

You can get the build here: phpmon-dev.zip

ITCONSULTINGAJACCCIO commented 2 years ago

@nicoverbruggen this is my output :


==================================
PHP MONITOR by Nico Verbruggen
Version 5.1-debug (715)
==================================
[ARCH] The user is running PHP Monitor with the architecture: x86_64
[OK] `/usr/local/bin/brew` exists
[OK] `/usr/local/bin/php` exists
[OK] `ls /usr/local/opt | grep php` returned php result
[OK] `valet` binary exists
[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}

Hope it could help you Thank you

nicoverbruggen commented 2 years ago

@ITCONSULTINGAJACCCIO could you also send me the crash log? If the app crashed, you should be able to find a file that starts with "PHP Monitor" in ~/Library/Logs/DiagnosticReports.

ITCONSULTINGAJACCCIO commented 2 years ago

@nicoverbruggen I don't have any log stating with PHP Monitor. The App didn't crash i've this message Capture d’écran 2022-03-09 à 14 31 24

nicoverbruggen commented 2 years ago

@ITCONSULTINGAJACCCIO Can you try open /Applications/PHP\ Monitor\ DEV.app/Contents/MacOS/PHP\ Monitor again and wait until it stops outputting stuff? It might take a while for the app to be ready.

I can see by the screenshot that you're not running the DEV build: make sure you are running the DEV build, it should never show this alert but instead crash (if it's having issues) or just work (if it doesn't crash). I made it do this specifically so we can get to the root of the issue!

ITCONSULTINGAJACCCIO commented 2 years ago

@nicoverbruggen when i use open /Applications/PHP\ Monitor\ DEV.app/Contents/MacOS/PHP\ Monitor I just have this display and no crash report Capture d’écran 2022-03-09 à 14 45 36

nicoverbruggen commented 2 years ago

@ITCONSULTINGAJACCCIO That's strange! It hangs on retrieving the JSON, perhaps.

If you launch the app without using the terminal (by double-clicking on "PHP Monitor DEV.app"), does it crash then? Or do you still see the truck icon in the status bar and nothing happens?

Also, what version of macOS are you on?

ITCONSULTINGAJACCCIO commented 2 years ago

@nicoverbruggen when i try to launch from Application, the truck icon appear less than 1 second and disappear, but i've nothing from php Mon in crashlog.

I'm on MacOS Big Sur 11.6.4

nicoverbruggen commented 2 years ago

That's strange. Let's make 100% sure there's no logs at all (because one would expect a crash if the truck icon disappears): what does ls -a ~/Library/Logs/DiagnosticReports give you in your terminal?

ITCONSULTINGAJACCCIO commented 2 years ago

I've tried your command and ls -a ~/Library/Logs/DiagnosticReports | grp mon. Nothing appear.

nicoverbruggen commented 2 years ago

Hmm. OK, are there any crash reports in /Applications/Utilities/Console.app? (Under Reports > Crash Reports). Without a crash and the limited logs that you seem to be getting back, I currently cannot determine what is going wrong, sadly :(

ITCONSULTINGAJACCCIO commented 2 years ago

I finally find one with console.app : PHP Monitor_2022-03-09-155712_MacBook-Pro-de-Sylvain-2.txt I hope it will help you

nicoverbruggen commented 2 years ago

Thanks @ITCONSULTINGAJACCCIO!

I think this problem could potentially be caused if you didn't run valet trust — I just noticed that the order in which the startup checks run is incorrect. I've made some adjustments & I've attached a new build below! Let me know if you are seeing a different alert now :)

phpmon-dev.zip

ITCONSULTINGAJACCCIO commented 2 years ago

Thanks @nicoverbruggen everythings seems to be ok. Thank you very much for your reactivity

ITCONSULTINGAJACCCIO commented 2 years ago

I just needed to run valet trust

nicoverbruggen commented 2 years ago

As I suspected, good to hear. I've fixed the order of the messages. I'll be making a bugfix release later this week. Thanks for the info!

@olivierneo You can probably fix this with the same fix, by running valet trust and restarting PHP Monitor.

olivierneo commented 2 years ago

Thanks a lot, valet trust works fine !

nicoverbruggen commented 2 years ago

This now fixed in the latest release, v5.1.1. Closing this issue now.

niladam commented 2 years ago

@nicoverbruggen are you sure this is fixed in 5.1.1 ? I'm still encountering the same issue.

Probably because my sudo command requires input, i'm still affected by this. How would one go about this ?

Basically, if i run the command without sudo, i get the json output. If i run it with sudo, i'm prompted to enter a password.

This turns my PHPMon unusable ;(

nicoverbruggen commented 2 years ago

@niladam

As you noted, PHP Monitor cannot invoke brew and valet commands if the password prompts are present. It is for this reason that I require you to run valet trust.

Make sure that you can run sudo brew and sudo valet commands in your terminal without password entry, and this should work. I recommend running:

valet trust --off
valet trust

and trying again. If you're still seeing password prompts, something's wrong (and maybe with Valet?). In that case, please let me know the following information:

Maybe with that info I can help you further! Thanks! (Please tag me in future responses as well, thanks!)

niladam commented 2 years ago

Sadly, while i can run the trust command and the output of both files are correct, i'm still prompted with a password entry input. It's probably because of some of the company's policies/software.

I'm on an Intel Mac. Is there anyway i could bypass this ?

Thanks.

nicoverbruggen commented 2 years ago

@niladam Unfortunately, PHP Monitor relies on Homebrew and Valet commands running as superuser in order to retrieve vital information required for the app to work correctly. If this is a system permission issue (due to policy enforcement), I'm very sorry to say that there isn't much I can do... I wish I could help you out here.

I'm guessing you might not be an administrator user, then? Perhaps adding an extra line for your own user in each sudoers file might do the trick (assuming you can get that set up), but this is not officially supported by Valet I think.

For example, these two lines:

your-username ALL=(root) NOPASSWD:SETENV: VALET
your-username ALL=(root) NOPASSWD:SETENV: BREW

in the two files, where your-username is replaced with the name of your user. Try that? It could be that the commands still require password input, I haven't tried this myself ;)

Give it a go and let me know if that worked!

rastitkac commented 1 year ago

Hi @nicoverbruggen I somehow have the same problem. When I run the binary from terminal it ends with the password prompt (first ist gets stuck and when I terminate it with CTRL+C, I can see that there was password prompt).

/Applications/PHP\ Monitor.app/Contents/MacOS/PHP\ Monitor ; exit;
==================================
PHP MONITOR by Nico Verbruggen
Version 5.6.6 (992)
==================================
[ARCH] The user is running PHP Monitor with the architecture: arm64
[OK] `/opt/homebrew/bin/brew` exists
[OK] `/opt/homebrew/bin/php` exists
[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}
[OK] `ls /opt/homebrew/opt | grep php` returned php result
[OK] `valet` binary exists
[OK] `/private/etc/sudoers.d/brew` contains brew
[OK] `/private/etc/sudoers.d/valet` contains valet
^CPassword:

Although, I have checked that there are both sudoers.d files for valet and brew and that they contain the correct data.

My setup is: macOs Big Sur 11.7.1 Laravel Valet 3.2.2 PHP Monitor 5.6.6 Brew 3.6.15-53-g4534748

I ran brew update, brew tap homebrew/services, valet trust

What else should I check to allow those sudo commands be run by phpmon?

nicoverbruggen commented 1 year ago

@rastitkac What's the contents of your sudoers files? Can you paste the contents here?

You can try removing the sudoers files, and running valet trust again. Paste the contents of the files here afterwards, assuming it still doesn't work!

rastitkac commented 1 year ago

@nicoverbruggen thanks for the prompt reply, here are the contents of the sudoers files:

before removing and re-running valet trust

$ cat /private/etc/sudoers.d/valet
Cmnd_Alias VALET = /opt/homebrew/bin/valet *
%admin ALL=(root) NOPASSWD:SETENV: VALET
$ cat /private/etc/sudoers.d/brew
Cmnd_Alias BREW = /opt/homebrew/bin/brew *
%admin ALL=(root) NOPASSWD:SETENV: BREW

after removing and re-running valet trust

$ cat /private/etc/sudoers.d/valet
Cmnd_Alias VALET = /opt/homebrew/bin/valet *
%admin ALL=(root) NOPASSWD:SETENV: VALET
cat /private/etc/sudoers.d/brew
Cmnd_Alias BREW = /opt/homebrew/bin/brew *
%admin ALL=(root) NOPASSWD:SETENV: BREW

so they are identical before and after.

nicoverbruggen commented 1 year ago

@rastitkac What's the output of which valet on your system?

rastitkac commented 1 year ago

@nicoverbruggen sorry for the interruption. which valet gives me /Users/rastitkac/.composer/vendor/bin/valet

nicoverbruggen commented 1 year ago

Try this:

You can adjust the order of your includes in ~/.zshrc.

You need to make sure that /opt/homebrew/bin takes precedence by listing it as an export after ~/composer/vendor/bin. My recommended order of exports:

export PATH=$HOME/bin:/usr/local/bin:$PATH
export PATH=$HOME/bin:~/.composer/vendor/bin:$PATH
export PATH=$HOME/bin:/opt/homebrew/bin:$PATH

Basically, /opt/homebrew/bin needs to be included as late as possible in the PATH.

After changing this and restarting your terminal (important!) which valet should return /opt/homebrew/bin/valet. From then on, Valet should correctly be able to run without asking for a password.

a1vin1au commented 11 months ago

@nicoverbruggen I'm facing this issue today, and I tried sudo brew services info nginx --json but it given me error message as below

Error: Need to download https://formulae.brew.sh/api/formula.jws.json but cannot as root! Run brew update without sudo first then try again.

How can I fix it? Thanks

Homebrew version: 4.1.17 PHP Monitor version: 6.1.0_1306

Update: Now it back to work with I do nothing...