Skip to content

Commit

Permalink
Add resource.ini installation routine
Browse files Browse the repository at this point in the history
refs #3761
  • Loading branch information
Johannes Meyer committed Oct 11, 2013
1 parent 8fe60fd commit 91e6711
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
4 changes: 4 additions & 0 deletions installer/controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@

require_once 'Zend/Config.php';
require_once 'Zend/Session.php';
require_once 'Zend/Config/Ini.php';
require_once 'Zend/Session/Namespace.php';
require_once 'Zend/Controller/Action.php';
require_once 'Zend/Config/Writer/FileAbstract.php';
require_once realpath(__DIR__ . '/../forms/WizardForm.php');
require_once realpath(__DIR__ . '/../forms/EndForm.php');
require_once realpath(__DIR__ . '/../forms/StartForm.php');
Expand All @@ -39,6 +41,8 @@
require_once realpath(__DIR__ . '/../forms/ConfirmationForm.php');
require_once realpath(__DIR__ . '/../forms/BackendConfigForm.php');
require_once realpath(__DIR__ . '/../../library/Icinga/Util/Report.php');
require_once realpath(__DIR__ . '/../../library/Icinga/Config/IniEditor.php');
require_once realpath(__DIR__ . '/../../library/Icinga/Config/PreservingIniWriter.php');
require_once realpath(__DIR__ . '/../../library/Icinga/Application/Installer.php');

use \Zend_Config;
Expand Down
62 changes: 61 additions & 1 deletion library/Icinga/Application/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

use \Exception;
use \Zend_Config;
use \Icinga\Config\PreservingIniWriter;

class Installer
{
Expand Down Expand Up @@ -137,7 +138,66 @@ private function log($section, $message)
*/
private function setupResources()
{

$configPath = $this->configDir . '/resources.ini';
$templatePath = $this->configDir . '/resources.ini.in';
if (!@copy($templatePath, $configPath)) {
$message = 'Could not duplicate INI template: ' . $templatePath;
$this->log('Resource configuration', $message);
throw new Exception($message);
}
chmod($configPath, 0664);
$this->log('Resource configuration', 'Successfully duplicated INI template: ' . $templatePath);

$dbConfig = $this->options->dbConfig;
$iniContent = array(
$dbConfig->db_resource => array(
'type' => 'db',
'db' => $dbConfig->db_provider,
'host' => $dbConfig->db_host,
'dbname' => $dbConfig->db_name,
'username' => $dbConfig->db_username,
'password' => $dbConfig->db_password
)
);
if (!empty($dbConfig->db_port)) {
$iniContent[$dbConfig->db_resource]['port'] = $dbConfig->db_port;
}
$this->log('Resource configuration', 'Added primary database store: ' . $dbConfig->db_resource);

$backendConfig = $this->options->backendConfig;
if ($backendConfig->backend_ido_host !== null) {
$iniContent[$backendConfig->backend_name] = array(
'type' => 'db',
'db' => $backendConfig->backend_ido_provider,
'host' => $backendConfig->backend_ido_host,
'dbname' => $backendConfig->backend_ido_dbname,
'username' => $backendConfig->backend_ido_dbuser,
'password' => $backendConfig->backend_ido_dbpass
);
if (!empty($backendConfig->backend_ido_port)) {
$iniContent[$backendConfig->backend_name]['port'] = $backendConfig->backend_ido_port;
}
$this->log('Resource configuration', 'Added IDO database store: ' . $backendConfig->backend_name);
}

$iniWriter = new PreservingIniWriter(
array(
'filename' => $configPath,
'config' => new Zend_Config($iniContent)
)
);

try {
$iniWriter->write();
} catch (Exception $error) {
$this->log('Resource configuration', 'Error while writing INI file: ' . $error->getMessage());
throw $error;
}

$this->log(
'Resource configuration',
'Configuration successfully written to: ' . $configPath
);
}

/**
Expand Down

0 comments on commit 91e6711

Please sign in to comment.