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

refs #6120
This commit is contained in:
Eric Lippmann 2014-11-13 14:05:13 +01:00
parent 0e64a8d573
commit 459fc77fc7
4 changed files with 52 additions and 9 deletions

View File

@ -73,18 +73,20 @@ class ConfigCommand extends Command
* *
* OPTIONS: * 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: * EXAMPLES:
* *
* icingacli setup config webserver apache * 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 * icingacli setup config webserver apache --file /etc/apache2/conf.d/icingaweb.conf
* *
@ -100,7 +102,7 @@ class ConfigCommand extends Command
} catch (ProgrammingError $e) { } catch (ProgrammingError $e) {
$this->fail($this->translate('Unknown type') . ': ' . $type); $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) { if (! is_string($path) || strlen(trim($path)) === 0) {
$this->fail($this->translate('The argument --path expects a URL path')); $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' '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 $webserver
->setDocumentRoot($documentRoot) ->setDocumentRoot($documentRoot)
->setConfigDir($configDir)
->setWebPath($path); ->setWebPath($path);
$config = $webserver->generate() . "\n"; $config = $webserver->generate() . "\n";
if (($file = $this->params->get('file')) !== null) { if (($file = $this->params->get('file')) !== null) {

View File

@ -24,7 +24,14 @@ abstract class Webserver
* *
* @var string * @var string
*/ */
protected $webPath; protected $webPath = '/icingaweb';
/**
* Path to Icinga Web 2's configuration files
*
* @var string
*/
protected $configDir;
/** /**
* Create instance by type name * Create instance by type name
@ -56,12 +63,12 @@ abstract class Webserver
$searchTokens = array( $searchTokens = array(
'{webPath}', '{webPath}',
'{documentRoot}', '{documentRoot}',
'{configPath}', '{configDir}',
); );
$replaceTokens = array( $replaceTokens = array(
$this->getWebPath(), $this->getWebPath(),
$this->getDocumentRoot(), $this->getDocumentRoot(),
Icinga::app()->getConfigDir() $this->getConfigDir()
); );
$template = str_replace($searchTokens, $replaceTokens, $template); $template = str_replace($searchTokens, $replaceTokens, $template);
return $template; return $template;
@ -132,4 +139,30 @@ abstract class Webserver
} }
return $this->documentRoot; 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;
}
} }

View File

@ -36,7 +36,7 @@ Alias {webPath} "{documentRoot}"
Allow from all Allow from all
</IfModule> </IfModule>
SetEnv ICINGAWEB_CONFIGDIR /etc/icingaweb/ SetEnv ICINGAWEB_CONFIGDIR "{configDir}"
EnableSendfile Off EnableSendfile Off

View File

@ -25,6 +25,7 @@ location ~ ^{webPath}/index\.php(.*)$ {
fastcgi_index index.php; fastcgi_index index.php;
include fastcgi_params; include fastcgi_params;
fastcgi_param SCRIPT_FILENAME {documentRoot}/index.php; fastcgi_param SCRIPT_FILENAME {documentRoot}/index.php;
fastcgi_param ICINGAWEB_CONFIGDIR {configDir};
} }
location ~ ^{webPath}(.+)? { location ~ ^{webPath}(.+)? {