[icinga-checkins] icinga.org: icingaweb2/master: CLI/Webserver Setup: Allow to define Icinga Web 2's configuration directory

git at icinga.org git at icinga.org
Thu Nov 13 15:10:34 CET 2014


Module: icingaweb2
Branch: master
Commit: 459fc77fc7e7cef9e50f9a48fe51559de8e76335
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=459fc77fc7e7cef9e50f9a48fe51559de8e76335

Author: Eric Lippmann <eric.lippmann at netways.de>
Date:   Thu Nov 13 14:05:13 2014 +0100

CLI/Webserver Setup: Allow to define Icinga Web 2's configuration directory

refs #6120

---

 .../application/clicommands/ConfigCommand.php      |   19 +++++++---
 modules/setup/library/Setup/Webserver.php          |   39 ++++++++++++++++++--
 modules/setup/library/Setup/Webserver/Apache.php   |    2 +-
 modules/setup/library/Setup/Webserver/Nginx.php    |    1 +
 4 files changed, 52 insertions(+), 9 deletions(-)

diff --git a/modules/setup/application/clicommands/ConfigCommand.php b/modules/setup/application/clicommands/ConfigCommand.php
index 04b518b..660207d 100644
--- a/modules/setup/application/clicommands/ConfigCommand.php
+++ b/modules/setup/application/clicommands/ConfigCommand.php
@@ -73,18 +73,20 @@ class ConfigCommand extends Command
      *
      * OPTIONS:
      *
-     *  --path=<urlpath>                    The URL path to Icinga Web 2
+     *  --path=<urlpath>                    The URL path to Icinga Web 2 [/icingaweb]
      *
-     *  --root/--document-root=<directory>  The directory from which the webserver will serve files
+     *  --root/--document-root=<directory>  The directory from which the webserver will serve files [./public]
      *
-     *  --file=<filename>                   Write configuration to file
+     *  --config=<directory>                Path to Icinga Web 2's configuration files [/etc/icingaweb]
+     *
+     *  --file=<filename>                   Write configuration to file [stdout]
      *
      *
      * EXAMPLES:
      *
      * icingacli setup config webserver apache
      *
-     * icingacli setup config webserver apache --path /icingaweb --document-root /usr/share/icingaweb/public
+     * icingacli setup config webserver apache --path /icingaweb --document-root /usr/share/icingaweb/public --config=/etc/icingaweb
      *
      * icingacli setup config webserver apache --file /etc/apache2/conf.d/icingaweb.conf
      *
@@ -100,7 +102,7 @@ class ConfigCommand extends Command
         } catch (ProgrammingError $e) {
             $this->fail($this->translate('Unknown type') . ': ' . $type);
         }
-        $path = $this->params->get('path', '/icingaweb');
+        $path = $this->params->get('path', $webserver->getWebPath());
         if (! is_string($path) || strlen(trim($path)) === 0) {
             $this->fail($this->translate('The argument --path expects a URL path'));
         }
@@ -110,8 +112,15 @@ class ConfigCommand extends Command
                 'The argument --root/--document-root expects a directory from which the webserver will serve files'
             ));
         }
+        $configDir = $this->params->get('config', $webserver->getConfigDir());
+        if (! is_string($documentRoot) || strlen(trim($documentRoot)) === 0) {
+            $this->fail($this->translate(
+                'The argument --config expects a path to Icinga Web 2\'s configuration files'
+            ));
+        }
         $webserver
             ->setDocumentRoot($documentRoot)
+            ->setConfigDir($configDir)
             ->setWebPath($path);
         $config = $webserver->generate() . "\n";
         if (($file = $this->params->get('file')) !== null) {
diff --git a/modules/setup/library/Setup/Webserver.php b/modules/setup/library/Setup/Webserver.php
index d8c1816..40951f6 100644
--- a/modules/setup/library/Setup/Webserver.php
+++ b/modules/setup/library/Setup/Webserver.php
@@ -24,7 +24,14 @@ abstract class Webserver
      *
      * @var string
      */
-    protected $webPath;
+    protected $webPath = '/icingaweb';
+
+    /**
+     * Path to Icinga Web 2's configuration files
+     *
+     * @var string
+     */
+    protected $configDir;
 
     /**
      * Create instance by type name
@@ -56,12 +63,12 @@ abstract class Webserver
         $searchTokens = array(
             '{webPath}',
             '{documentRoot}',
-            '{configPath}',
+            '{configDir}',
         );
         $replaceTokens = array(
             $this->getWebPath(),
             $this->getDocumentRoot(),
-            Icinga::app()->getConfigDir()
+            $this->getConfigDir()
         );
         $template = str_replace($searchTokens, $replaceTokens, $template);
         return $template;
@@ -132,4 +139,30 @@ abstract class Webserver
         }
         return $this->documentRoot;
     }
+
+    /**
+     * Set the configuration directory
+     *
+     * @param   string  $configDir
+     *
+     * @return  $this
+     */
+    public function setConfigDir($configDir)
+    {
+        $this->configDir = (string) $configDir;
+        return $this;
+    }
+
+    /**
+     * Get the configuration directory
+     *
+     * @return string
+     */
+    public function getConfigDir()
+    {
+        if ($this->configDir === null) {
+            return Icinga::app()->getConfigDir();
+        }
+        return $this->configDir;
+    }
 }
diff --git a/modules/setup/library/Setup/Webserver/Apache.php b/modules/setup/library/Setup/Webserver/Apache.php
index e25182f..f35c695 100644
--- a/modules/setup/library/Setup/Webserver/Apache.php
+++ b/modules/setup/library/Setup/Webserver/Apache.php
@@ -36,7 +36,7 @@ Alias {webPath} "{documentRoot}"
         Allow from all
     </IfModule>
 
-    SetEnv ICINGAWEB_CONFIGDIR /etc/icingaweb/
+    SetEnv ICINGAWEB_CONFIGDIR "{configDir}"
 
     EnableSendfile Off
 
diff --git a/modules/setup/library/Setup/Webserver/Nginx.php b/modules/setup/library/Setup/Webserver/Nginx.php
index 4885dc0..3364561 100644
--- a/modules/setup/library/Setup/Webserver/Nginx.php
+++ b/modules/setup/library/Setup/Webserver/Nginx.php
@@ -25,6 +25,7 @@ location ~ ^{webPath}/index\.php(.*)$ {
   fastcgi_index index.php;
   include fastcgi_params;
   fastcgi_param SCRIPT_FILENAME {documentRoot}/index.php;
+  fastcgi_param ICINGAWEB_CONFIGDIR {configDir};
 }
 
 location ~ ^{webPath}(.+)? {



More information about the icinga-checkins mailing list