From 2a959af9c2054a014f0ea6e059df70e495f3d4a8 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 18 Jan 2018 08:54:35 +0100 Subject: [PATCH] ConfigCommand: Add fpm socket commandline switch Allows to pass a different socket path than the default when generating a webserver's configuration. refs #2862 --- .../application/clicommands/ConfigCommand.php | 15 ++++++-- modules/setup/library/Setup/Webserver.php | 35 ++++++++++++++++++- .../setup/library/Setup/Webserver/Apache.php | 4 ++- .../setup/library/Setup/Webserver/Nginx.php | 10 ++---- 4 files changed, 53 insertions(+), 11 deletions(-) diff --git a/modules/setup/application/clicommands/ConfigCommand.php b/modules/setup/application/clicommands/ConfigCommand.php index 8e80b9368..ae43fe5e0 100644 --- a/modules/setup/application/clicommands/ConfigCommand.php +++ b/modules/setup/application/clicommands/ConfigCommand.php @@ -99,6 +99,8 @@ class ConfigCommand extends Command * --root|--document-root= The directory from which the webserver will serve files * [/path/to/icingaweb2/public] * + * --fpm-uri= Address or path where to pass requests to FPM [127.0.0.1:9000] + * * --config= Path to Icinga Web 2's configuration files [/etc/icingaweb2] * * --file= Write configuration to file [stdout] @@ -115,7 +117,9 @@ class ConfigCommand extends Command * icingacli setup config webserver apache \ * --file=/etc/apache2/conf.d/icingaweb2.conf * - * icingacli setup config webserver nginx + * icingacli setup config webserver nginx \ + * --root=/usr/share/icingaweb2/public \ + * --fpm-uri=unix:/var/run/php5-fpm.sock */ public function webserverAction() { @@ -145,10 +149,17 @@ class ConfigCommand extends Command 'The argument --config expects a path to Icinga Web 2\'s configuration files' )); } + $fpmUri = trim($this->params->get('fpm-uri', $webserver->getFpmUri())); + if (empty($fpmUri)) { + $this->fail($this->translate( + 'The argument --fpm-uri expects an address or path where to pass requests to FPM' + )); + } $webserver ->setDocumentRoot($documentRoot) ->setConfigDir($configDir) - ->setUrlPath($urlPath); + ->setUrlPath($urlPath) + ->setFpmUri($fpmUri); $config = $webserver->generate() . "\n"; if (($file = $this->params->get('file')) !== null) { if (file_exists($file) === true) { diff --git a/modules/setup/library/Setup/Webserver.php b/modules/setup/library/Setup/Webserver.php index 3ba4e6171..2dac061a5 100644 --- a/modules/setup/library/Setup/Webserver.php +++ b/modules/setup/library/Setup/Webserver.php @@ -32,6 +32,13 @@ abstract class Webserver */ protected $configDir; + /** + * Address or path where to pass requests to FPM + * + * @var string + */ + protected $fpmUri; + /** * Create instance by type name * @@ -63,11 +70,13 @@ abstract class Webserver '{urlPath}', '{documentRoot}', '{configDir}', + '{fpmUri}' ); $replaceTokens = array( $this->getUrlPath(), $this->getDocumentRoot(), - $this->getConfigDir() + $this->getConfigDir(), + $this->getFpmUri() ); $template = str_replace($searchTokens, $replaceTokens, $template); return $template; @@ -164,4 +173,28 @@ abstract class Webserver } return $this->configDir; } + + /** + * Get the address or path where to pass requests to FPM + * + * @return string + */ + public function getFpmUri() + { + return $this->fpmUri; + } + + /** + * Set the address or path where to pass requests to FPM + * + * @param string $uri + * + * @return $this + */ + public function setFpmUri($uri) + { + $this->fpmUri = (string) $uri; + + return $this; + } } diff --git a/modules/setup/library/Setup/Webserver/Apache.php b/modules/setup/library/Setup/Webserver/Apache.php index bb846f98b..c703950c3 100644 --- a/modules/setup/library/Setup/Webserver/Apache.php +++ b/modules/setup/library/Setup/Webserver/Apache.php @@ -10,6 +10,8 @@ use Icinga\Module\Setup\Webserver; */ class Apache extends Webserver { + protected $fpmUri = 'fgci://127.0.0.1:9000'; + protected function getTemplate() { return <<<'EOD' @@ -68,7 +70,7 @@ Alias {urlPath} "{documentRoot}" # # Forward PHP requests to FPM # SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1 # -# SetHandler "proxy:fcgi://127.0.0.1:9000" +# SetHandler "proxy:{fpmUri}" # ErrorDocument 503 {urlPath}/error_unavailable.html # # diff --git a/modules/setup/library/Setup/Webserver/Nginx.php b/modules/setup/library/Setup/Webserver/Nginx.php index e874e745e..1223c554d 100644 --- a/modules/setup/library/Setup/Webserver/Nginx.php +++ b/modules/setup/library/Setup/Webserver/Nginx.php @@ -10,17 +10,13 @@ use Icinga\Module\Setup\Webserver; */ class Nginx extends Webserver { - /** - * Specific template - * - * @return array|string - */ + protected $fpmUri = '127.0.0.1:9000'; + protected function getTemplate() { return <<<'EOD' location ~ ^{urlPath}/index\.php(.*)$ { - # fastcgi_pass 127.0.0.1:9000; - fastcgi_pass unix:/var/run/php5-fpm.sock; + fastcgi_pass {fpmUri}; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME {documentRoot}/index.php;