From 10b299ff655a0a86ba46f8e393d67dea6dca6be0 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Wed, 26 Jan 2022 21:00:52 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Check=20if=20services=20command?= =?UTF-8?q?=20can=20run?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- phpmon-common/PHP/Homebrew/HomebrewService.swift | 13 +++++++++++++ phpmon/Domain/Core/Startup.swift | 7 +++++++ phpmon/Domain/SiteList/SiteListWC.swift | 2 +- phpmon/Localizable.strings | 2 +- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/phpmon-common/PHP/Homebrew/HomebrewService.swift b/phpmon-common/PHP/Homebrew/HomebrewService.swift index 6c21af4..2cc9b07 100644 --- a/phpmon-common/PHP/Homebrew/HomebrewService.swift +++ b/phpmon-common/PHP/Homebrew/HomebrewService.swift @@ -18,4 +18,17 @@ struct HomebrewService: Decodable, Equatable { let status: String? let log_path: String? let error_log_path: String? + + public static let serviceToCheck = "nginx" + public static func servicesCanBeLoaded() -> Bool { + let serviceInfo = try? JSONDecoder().decode( + [HomebrewService].self, + from: Shell.pipe( + "sudo \(Paths.brew) services info \(self.serviceToCheck) --json", + requiresPath: true + ).data(using: .utf8)! + ) + + return serviceInfo != nil + } } diff --git a/phpmon/Domain/Core/Startup.swift b/phpmon/Domain/Core/Startup.swift index b1e9060..fed4915 100644 --- a/phpmon/Domain/Core/Startup.swift +++ b/phpmon/Domain/Core/Startup.swift @@ -49,6 +49,13 @@ class Startup { breaking: true ) + performEnvironmentCheck( + !HomebrewService.servicesCanBeLoaded(), + messageText: "startup.errors.services_json_error.title".localized, + informativeText: "startup.errors.services_json_error.desc".localized, + breaking: true + ) + performEnvironmentCheck( !Shell.pipe("cat /private/etc/sudoers.d/brew").contains("\(Paths.binPath)/brew"), messageText: "startup.errors.sudoers_brew.title".localized, diff --git a/phpmon/Domain/SiteList/SiteListWC.swift b/phpmon/Domain/SiteList/SiteListWC.swift index c423da4..4d85cac 100644 --- a/phpmon/Domain/SiteList/SiteListWC.swift +++ b/phpmon/Domain/SiteList/SiteListWC.swift @@ -78,7 +78,7 @@ class SiteListWC: PMWindowController, NSSearchFieldDelegate, NSToolbarDelegate { } func showSitePopup(_ folder: String) { - let storyboard = NSStoryboard(name: "Main" , bundle : nil) + let storyboard = NSStoryboard(name: "Main", bundle : nil) let windowController = storyboard.instantiateController( withIdentifier: "addSiteWindow" diff --git a/phpmon/Localizable.strings b/phpmon/Localizable.strings index 67d870f..406d1d4 100644 --- a/phpmon/Localizable.strings +++ b/phpmon/Localizable.strings @@ -237,7 +237,7 @@ You can do this by running `composer global update` in your terminal. After that /// 6. Cannot retrieve services "startup.errors.services_json_error.title" = "Cannot determine services status"; -"startup.errors.services_json_error.desc" = "PHP Monitor was unable to check if any of the services are up and running. PHP Monitor usually queries `brew` using the following command: ``. PHP Monitor received an invalid response (no JSON)."; +"startup.errors.services_json_error.desc" = "PHP Monitor was unable to check if some of the services are up and running.\n\nPHP Monitor usually queries `brew` using the following command to test if the services can be retrieved: `sudo brew services info nginx --json`. PHP Monitor received an invalid response (no JSON)."; /// 7. Multiple services active "startup.errors.services.title" = "Multiple PHP services are active";