1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-07 20:10:08 +02:00

👌 Services now report error status

This commit is contained in:
2023-01-08 11:50:01 +01:00
parent 4cbfbeb4e5
commit a50eb04f3c
7 changed files with 91 additions and 14 deletions

View File

@ -91,7 +91,7 @@
</CommandLineArgument> </CommandLineArgument>
<CommandLineArgument <CommandLineArgument
argument = "--configuration:~/.phpmon_fconf_working.json" argument = "--configuration:~/.phpmon_fconf_working.json"
isEnabled = "YES"> isEnabled = "NO">
</CommandLineArgument> </CommandLineArgument>
<CommandLineArgument <CommandLineArgument
argument = "--configuration:~/.phpmon_fconf_broken.json" argument = "--configuration:~/.phpmon_fconf_broken.json"

View File

@ -20,8 +20,12 @@ public struct Service: Hashable {
init(formula: HomebrewFormula, service: HomebrewService? = nil) { init(formula: HomebrewFormula, service: HomebrewService? = nil) {
self.formula = formula self.formula = formula
if service != nil { guard let service else { return }
self.status = service!.running ? .active : .inactive
self.status = service.running ? .active : .inactive
if service.status == "error" {
self.status = .error
} }
} }
@ -41,6 +45,11 @@ public struct Service: Hashable {
public enum Status: String { public enum Status: String {
case active case active
case inactive case inactive
case error
case missing case missing
var asBool: Bool {
return self == .active
}
} }
} }

View File

@ -34,6 +34,16 @@ class ServicesManager: ObservableObject {
} }
} }
public var hasError: Bool {
if self.services.isEmpty || !self.firstRunComplete {
return false
}
return self.services[0...2]
.map { $0.status }
.contains(.error)
}
public var statusMessage: String { public var statusMessage: String {
if self.services.isEmpty || !self.firstRunComplete { if self.services.isEmpty || !self.firstRunComplete {
return "Loading..." return "Loading..."
@ -44,6 +54,9 @@ class ServicesManager: ObservableObject {
if statuses.contains(.missing) { if statuses.contains(.missing) {
return "A key service is not installed." return "A key service is not installed."
} }
if statuses.contains(.error) {
return "A key service is reporting an error state."
}
if statuses.contains(.inactive) { if statuses.contains(.inactive) {
return "A key service is not running." return "A key service is not running."
} }
@ -57,10 +70,10 @@ class ServicesManager: ObservableObject {
} }
let statuses = self.services[0...2].map { $0.status } let statuses = self.services[0...2].map { $0.status }
if statuses.contains(.missing) {
return .red if statuses.contains(.missing)
} || statuses.contains(.inactive)
if statuses.contains(.inactive) { || statuses.contains(.error) {
return .red return .red
} }

View File

@ -94,6 +94,10 @@ class ValetServicesManager: ServicesManager {
} }
// Prepare the appropriate command to stop or start a service // Prepare the appropriate command to stop or start a service
let before = self.homebrewServices.first { service in
return service.name == named
}
let action = wrapper.status == .active ? "stop" : "start" let action = wrapper.status == .active ? "stop" : "start"
let command = "services \(action) \(wrapper.formula.name)" let command = "services \(action) \(wrapper.formula.name)"
@ -102,5 +106,21 @@ class ValetServicesManager: ServicesManager {
// Reload the services status to confirm this worked // Reload the services status to confirm this worked
await ServicesManager.shared.reloadServicesStatus() await ServicesManager.shared.reloadServicesStatus()
Task { @MainActor in
let after = self.homebrewServices.first { service in
return service.name == named
}
guard let before else { return }
guard let after else { return }
if before.running == after.running {
// The status has not changed, report this to the user
Log.err("The service '\(named)' status has not changed. Its status is: \(after.status ?? "empty")")
} else {
Log.info("The service '\(named)' has been successfully toggled.")
}
}
} }
} }

View File

@ -14,9 +14,7 @@ struct HelpButton: View {
var body: some View { var body: some View {
Button(action: action, label: { Button(action: action, label: {
ZStack { Text("?").font(.system(size: 12, weight: .medium))
Text("?").font(.system(size: 15, weight: .medium))
}
}) })
} }

View File

@ -80,11 +80,15 @@ struct ServicesView: View {
.font(.system(size: 12)) .font(.system(size: 12))
if self.manager.statusColor == .red { if self.manager.statusColor == .red {
HelpButton { HelpButton {
let type = manager.hasError
? "key_service_has_error"
: "key_service_not_running"
// Show an alert with more information // Show an alert with more information
BetterAlert().withInformation( BetterAlert().withInformation(
title: "alert.key_service_not_running.title".localized, title: "alert.\(type).title".localized,
subtitle: "alert.key_service_not_running.subtitle".localized, subtitle: "alert.\(type).subtitle".localized,
description: "alert.key_service_not_running.desc".localized description: "alert.\(type).desc".localized
) )
.withPrimary(text: "generic.ok".localized) .withPrimary(text: "generic.ok".localized)
.show() .show()
@ -132,6 +136,21 @@ struct ServiceView: View {
.focusable(false) .focusable(false)
.frame(minWidth: 70, alignment: .center) .frame(minWidth: 70, alignment: .center)
} }
if service.status == .error {
Button {
Task {
isBusy = true
await ServicesManager.shared.toggleService(named: service.name)
isBusy = false
}
} label: {
Text("E")
.frame(width: 12.0, height: 12.0)
.foregroundColor(Color("IconColorRed"))
}
.focusable(false)
.frame(width: 25, height: 25)
}
if service.status == .active || service.status == .inactive { if service.status == .active || service.status == .inactive {
Button { Button {
Task { Task {

View File

@ -10,7 +10,7 @@
"mi_busy" = "PHP Monitor is busy..."; "mi_busy" = "PHP Monitor is busy...";
"mi_unsure" = "We are not sure what version of PHP you are running."; "mi_unsure" = "We are not sure what version of PHP you are running.";
"mi_php_version" = "You are running PHP"; "mi_php_version" = "Global PHP version: PHP";
"mi_php_switch" = "Switch to PHP"; "mi_php_switch" = "Switch to PHP";
"mi_php_broken_1" = "Oof! It appears your PHP installation is broken..."; "mi_php_broken_1" = "Oof! It appears your PHP installation is broken...";
"mi_php_broken_2" = "Try running `php -v` in your terminal."; "mi_php_broken_2" = "Try running `php -v` in your terminal.";
@ -556,6 +556,24 @@ Alternatively, you can use `valet stop` and `valet start` in the terminal, which
For further debugging, you may wish to check the GitHub issue tracker, where others may have had similar issues. As the developer, I attempt to make sure every question gets answered :)"; For further debugging, you may wish to check the GitHub issue tracker, where others may have had similar issues. As the developer, I attempt to make sure every question gets answered :)";
"alert.key_service_has_error.title" = "Due to issues with the Homebrew services required, Valet is currently not working correctly";
"alert.key_service_has_error.subtitle" = "For Valet to work properly, at least three key services need to be running correctly.
PHP Monitor is reporting that this isn't the case. It appears that one of the affected services is reporting an error state, so I recommend clicking on the 'E'.
PHP Monitor will attempt to restart the service, and should it fail (which is likely) it will offer to locate the log file if it exists, which may contain additional information that might help you debug the issue.";
"alert.key_service_has_error.desc" = "Unfortunately, if a service reports an error, this is often due to an invalid configuration state, which may be difficult to debug.
COMMON TROUBLESHOOTING TIPS
• Try restarting the service and checking the log file (if it exists) first. You can have PHP Monitor do this by clicking on the 'E' button.
 PHP: If you are seeing an error status, there may be an issue with PHP's configuration. Make sure the .ini files in the Homebrew installation are OK, and there are no socket conflicts.
 nginx: If you are seeing an error status, a site is likely misconfigured (usually noted in the error log). You will likely want to check Valet's nginx folder.
• dnsmasq: If you are seeing an error status, the dnsmasq configuration file is likely broken (usually located at ~/.config/valet/dnsmasq.d).";
// CHECK FOR UPDATES // CHECK FOR UPDATES
"updater.alerts.newer_version_available.title" = "PHP Monitor v%@ is now available!"; "updater.alerts.newer_version_available.title" = "PHP Monitor v%@ is now available!";