From 79c2e05b1ddccb3978d8132bf315ff302a44c7d7 Mon Sep 17 00:00:00 2001 From: Colan Schwartz Date: Wed, 20 Jul 2016 12:54:42 -0400 Subject: [PATCH] Issue #2769587 by colan: Check for FPM sockets in PHP 7 locations as well as PHP5. --- http/Provision/Service/http/nginx.php | 61 ++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 16 deletions(-) diff --git a/http/Provision/Service/http/nginx.php b/http/Provision/Service/http/nginx.php index e146a1f..1aaf1b7 100644 --- a/http/Provision/Service/http/nginx.php +++ b/http/Provision/Service/http/nginx.php @@ -1,6 +1,11 @@ exists('/var/run/php5-fpm.sock')->status()) { - $this->server->phpfpm_mode = 'socket'; - drush_log(dt('PHP-FPM unix socket mode detected -SAVE- YES socket found @path.', array('@path' => '/var/run/php5-fpm.sock'))); - } - else { - $this->server->phpfpm_mode = 'port'; - drush_log(dt('PHP-FPM port mode detected -SAVE- NO socket found @path.', array('@path' => '/var/run/php5-fpm.sock'))); - } + $this->server->phpfpm_mode = $this->getPhpFpmMode('save'); // Check if there is BOA specific global.inc file to enable extra Nginx locations if (provision_file()->exists('/data/conf/global.inc')->status()) { @@ -133,14 +131,7 @@ class Provision_Service_http_nginx extends Provision_Service_http_public { } // Check if there is php-fpm listening on unix socket, otherwise use port 9000 to connect - if (provision_file()->exists('/var/run/php5-fpm.sock')->status()) { - $this->server->phpfpm_mode = 'socket'; - drush_log(dt('PHP-FPM unix socket mode detected -VERIFY- YES socket found @path.', array('@path' => '/var/run/php5-fpm.sock'))); - } - else { - $this->server->phpfpm_mode = 'port'; - drush_log(dt('PHP-FPM port mode detected -VERIFY- NO socket found @path.', array('@path' => '/var/run/php5-fpm.sock'))); - } + $this->server->phpfpm_mode = $this->getPhpFpmMode('verify'); // Check if there is BOA specific global.inc file to enable extra Nginx locations if (provision_file()->exists('/data/conf/global.inc')->status()) { @@ -162,6 +153,44 @@ class Provision_Service_http_nginx extends Provision_Service_http_public { } /** + * Determines the PHP FPM mode. + * + * @param string $server_task + * The server task type for logging purposes. + * @return string + * The mode, either 'socket' or 'port'. + */ + protected function getPhpFpmMode($server_task) { + + // Search for socket files or fall back to port mode. + switch (TRUE) { + case provision_file()->exists(self::SOCKET_PATH_PHP5)->status(): + $mode = 'socket'; + $socket_path = self::SOCKET_PATH_PHP5; + break; + case provision_file()->exists(self::SOCKET_PATH_PHP7)->status(): + $mode = 'socket'; + $socket_path = self::SOCKET_PATH_PHP7; + break; + default: + $mode = 'port'; + $socket_path = ''; + break; + } + + // Report results in the log. + drush_log(dt('PHP-FPM @mode mode detected -' . '@task' . '- @yes_or_no socket found @path.', array( + '@mode' => ($mode == 'socket') ? 'unix socket' : 'port', + '@task' => drupal_strtoupper($server_task), + '@yes_or_no' => ($mode == 'socket') ? 'YES' : 'NO', + '@path' => ($socket_path ? $socket_path : self::SOCKET_PATH_PHP5 . ' or ' . self::SOCKET_PATH_PHP7), + ))); + + // Return the discovered mode. + return $mode; + } + + /** * Guess at the likely value of the http_restart_cmd. * * This method is a static so that it can be re-used by the nginx_ssl -- 2.7.4