Files
cacti/install/background.php
Thomas Vincent ead882172e Make installer completion fail closed and add test coverage (#7626)
* Make installer completion fail closed

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* Add installer unit and Docker integration gates

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* Require installer coverage evidence

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* Stabilize installer failure scenarios

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* Address installer review feedback

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* Reject incomplete installer selection payloads

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* Match table validation to rendered controls

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* Protect long-running installer migrations

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* Load installer table metadata in one query

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* Optimize installer completion queries

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* Batch installer default settings writes

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* Batch installer color upserts

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* Batch installer template and poller lookups

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* Refresh SQL interpolation baseline after develop rebase

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* ci: use Cacti Composer test setup

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* test: resolve includes through Cacti path constants

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* ci: align installer workflows with policy

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* ci: refresh security baselines after develop rebase

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* ci: reuse TCP database credentials for installer checks

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* test(security): refresh sink inventory baseline after rebase onto develop

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

* ci: run installer coverage on PHP 8.2

The 8.1 pin is below the ^8.2 composer requirement, so pest died in platform_check before any test ran.

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>

---------

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
2026-08-31 16:59:49 -04:00

93 lines
3.4 KiB
PHP

<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2026 The Cacti Group |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDtool-based Graphing Solution |
+-------------------------------------------------------------------------+
| This code is designed, written, and maintained by the Cacti Group. See |
| about.php and/or the AUTHORS file for specific developer information. |
+-------------------------------------------------------------------------+
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/
error_reporting(E_ALL);
define('IN_CACTI_INSTALL', 1);
include_once(__DIR__ . '/../include/cli_check.php');
include_once(CACTI_PATH_INSTALL . '/functions.php');
include_once(CACTI_PATH_LIBRARY . '/api_data_source.php');
include_once(CACTI_PATH_LIBRARY . '/api_device.php');
include_once(CACTI_PATH_LIBRARY . '/api_automation.php');
include_once(CACTI_PATH_LIBRARY . '/api_automation_tools.php');
include_once(CACTI_PATH_LIBRARY . '/data_query.php');
include_once(CACTI_PATH_LIBRARY . '/import.php');
include_once(CACTI_PATH_LIBRARY . '/installer.php');
include_once(CACTI_PATH_LIBRARY . '/poller.php');
include_once(CACTI_PATH_LIBRARY . '/snmp.php');
include_once(CACTI_PATH_LIBRARY . '/utility.php');
include_once(CACTI_PATH_LIBRARY . '/xml.php');
cacti_log('Checking arguments', false, 'INSTALL:');
// process calling arguments
$params = $_SERVER['argv'];
array_shift($params);
global $cli_install;
$cli_install = true;
$now = time();
$installerProcessTimeout = 86400;
if (cacti_sizeof($params) == 0) {
log_install_always('','no parameters passed' . PHP_EOL);
exit(0);
}
$registeredProcess = false;
if (function_exists('register_process_start')) {
// Installer schema conversions can legitimately run longer than the
// generic process timeout. Dead processes are still reclaimed immediately
// by register_process_start() through its PID-liveness check.
if (!register_process_start('install', 'master', 0, $installerProcessTimeout)) {
exit(0);
}
$registeredProcess = true;
} else {
$running = read_config_option('installer_running', true);
if ($running != '' && $now - $running < 600) {
exit(0);
}
set_config_option('installer_running', $now);
}
$completed = false;
try {
$completed = Installer::beginInstall($params[0]);
} finally {
if ($registeredProcess) {
unregister_process('install', 'master', 0);
} else {
set_config_option('installer_running', '');
}
}
exit($completed ? 0 : 1);