From 28c57548004ac4c965c23d96288a5cd159b53133 Mon Sep 17 00:00:00 2001 From: Nico Verbruggen Date: Thu, 17 Mar 2022 18:02:52 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Disable=20`www.conf`=20file=20wh?= =?UTF-8?q?en=20switching=20versions=20(#152)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Common/PHP/Switcher/InternalSwitcher.swift | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/phpmon/Common/PHP/Switcher/InternalSwitcher.swift b/phpmon/Common/PHP/Switcher/InternalSwitcher.swift index 6bf18a4..e690cf9 100644 --- a/phpmon/Common/PHP/Switcher/InternalSwitcher.swift +++ b/phpmon/Common/PHP/Switcher/InternalSwitcher.swift @@ -42,6 +42,7 @@ class InternalSwitcher: PhpSwitcher { group.enter() DispatchQueue.global(qos: .userInitiated).async { + self.disableDefaultPhpFpmPool(available) self.stopPhpVersion(available) group.leave() } @@ -63,6 +64,21 @@ class InternalSwitcher: PhpSwitcher { } } + private func disableDefaultPhpFpmPool(_ version: String) { + let pool = "\(Paths.etcPath)/php/\(version)/php-fpm.d/www.conf" + if FileManager.default.fileExists(atPath: pool) { + Log.info("A default `www.conf` file was found in the php-fpm.d directory for PHP \(version).") + let existing = URL(string: "file://\(Paths.etcPath)/php/\(version)/php-fpm.d/www.conf")! + let new = URL(string: "file://\(Paths.etcPath)/php/\(version)/php-fpm.d/www.conf.disabled-by-phpmon")! + do { + try FileManager.default.moveItem(at: existing, to: new) + Log.info("Success: A default `www.conf` file was disabled for PHP \(version).") + } catch { + Log.err(error) + } + } + } + private func stopPhpVersion(_ version: String) { let formula = (version == PhpEnv.brewPhpVersion) ? "php" : "php@\(version)" brew("unlink \(formula)")