mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
N°2240 - Supportability - Maintenance mode
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
//
|
//
|
||||||
// This file is part of iTop.
|
// This file is part of iTop.
|
||||||
//
|
//
|
||||||
// iTop is free software; you can redistribute it and/or modify
|
// iTop is free software; you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Affero General Public License as published by
|
// it under the terms of the GNU Affero General Public License as published by
|
||||||
// the Free Software Foundation, either version 3 of the License, or
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
// (at your option) any later version.
|
// (at your option) any later version.
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
/**
|
/**
|
||||||
* File to include to initialize the datamodel in memory
|
* File to include to initialize the datamodel in memory
|
||||||
*
|
*
|
||||||
* @copyright Copyright (C) 2010-2016 Combodo SARL
|
* @copyright Copyright (C) 2010-2019 Combodo SARL
|
||||||
* @license http://opensource.org/licenses/AGPL-3.0
|
* @license http://opensource.org/licenses/AGPL-3.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -32,10 +32,16 @@ register_shutdown_function(function()
|
|||||||
$sReservedMemory = null;
|
$sReservedMemory = null;
|
||||||
if (!is_null($err = error_get_last()) && ($err['type'] == E_ERROR))
|
if (!is_null($err = error_get_last()) && ($err['type'] == E_ERROR))
|
||||||
{
|
{
|
||||||
|
IssueLog::error($err['message']);
|
||||||
if (strpos($err['message'], 'Allowed memory size of') !== false)
|
if (strpos($err['message'], 'Allowed memory size of') !== false)
|
||||||
{
|
{
|
||||||
$sLimit = ini_get('memory_limit');
|
$sLimit = ini_get('memory_limit');
|
||||||
echo "<p>iTop: Allowed memory size of $sLimit exhausted, contact your administrator to increase memory_limit in php.ini</p>\n";
|
echo "<p>iTop: Allowed memory size of $sLimit exhausted, contact your administrator to increase 'memory_limit' in php.ini</p>\n";
|
||||||
|
}
|
||||||
|
elseif (strpos($err['message'], 'Maximum execution time') !== false)
|
||||||
|
{
|
||||||
|
$sLimit = ini_get('max_execution_time');
|
||||||
|
echo "<p>iTop: Maximum execution time of $sLimit exceeded, contact your administrator to increase 'max_execution_time' in php.ini</p>\n";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -44,6 +50,37 @@ register_shutdown_function(function()
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Use 'maintenance' parameter to bypass maintenance mode
|
||||||
|
$bBypassMaintenance = !is_null(Utils::ReadParam('maintenance', null));
|
||||||
|
|
||||||
|
// Maintenance mode
|
||||||
|
if (file_exists(APPROOT.'.maintenance') && !$bBypassMaintenance)
|
||||||
|
{
|
||||||
|
require_once(APPROOT.'core/dict.class.inc.php');
|
||||||
|
$sMessage = Dict::S('UI:Error:MaintenanceMode', 'Application is currently in maintenance');
|
||||||
|
$sTitle = Dict::S('UI:Error:MaintenanceTitle', 'Maintenance');
|
||||||
|
// throw new MaintenanceException($sMessage, $sTitle);
|
||||||
|
|
||||||
|
http_response_code(503);
|
||||||
|
// Display message depending on the request
|
||||||
|
switch (true)
|
||||||
|
{
|
||||||
|
case array_key_exists('HTTP_X_COMBODO_AJAX', $_SERVER):
|
||||||
|
case EndsWith($_SERVER['REQUEST_URI'], '/webservices/rest.php'):
|
||||||
|
_MaintenanceTextMessage($sMessage);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case EndsWith($_SERVER['REQUEST_URI'], '/pages/ajax.searchform.php'):
|
||||||
|
_MaintenanceHtmlMessage($sMessage);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
_MaintenanceSetupPageMessage($sTitle, $sMessage);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
require_once(APPROOT.'/core/cmdbobject.class.inc.php');
|
require_once(APPROOT.'/core/cmdbobject.class.inc.php');
|
||||||
require_once(APPROOT.'/application/utils.inc.php');
|
require_once(APPROOT.'/application/utils.inc.php');
|
||||||
require_once(APPROOT.'/core/contexttag.class.inc.php');
|
require_once(APPROOT.'/core/contexttag.class.inc.php');
|
||||||
@@ -79,4 +116,51 @@ else
|
|||||||
$_SESSION['itop_env'] = ITOP_DEFAULT_ENV;
|
$_SESSION['itop_env'] = ITOP_DEFAULT_ENV;
|
||||||
}
|
}
|
||||||
$sConfigFile = APPCONF.$sEnv.'/'.ITOP_CONFIG_FILE;
|
$sConfigFile = APPCONF.$sEnv.'/'.ITOP_CONFIG_FILE;
|
||||||
MetaModel::Startup($sConfigFile, false /* $bModelOnly */, $bAllowCache, false /* $bTraceSourceFiles */, $sEnv);
|
MetaModel::Startup($sConfigFile, false /* $bModelOnly */, $bAllowCache, false /* $bTraceSourceFiles */, $sEnv);
|
||||||
|
|
||||||
|
//
|
||||||
|
// Maintenance message display functions
|
||||||
|
//
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use a setup page to display the maintenance message
|
||||||
|
* @param $sTitle
|
||||||
|
* @param $sMessage
|
||||||
|
*/
|
||||||
|
function _MaintenanceSetupPageMessage($sTitle, $sMessage)
|
||||||
|
{
|
||||||
|
// Web Page
|
||||||
|
require_once(APPROOT."/setup/setuppage.class.inc.php");
|
||||||
|
$oP = new SetupPage($sTitle);
|
||||||
|
$oP->p("<h2>$sMessage</h2>");
|
||||||
|
$oP->output();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use simple text to display the maintenance message
|
||||||
|
* @param $sMessage
|
||||||
|
*/
|
||||||
|
function _MaintenanceTextMessage($sMessage)
|
||||||
|
{
|
||||||
|
echo $sMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use a simple HTML to display the maintenance message
|
||||||
|
* @param $sMessage
|
||||||
|
*/
|
||||||
|
function _MaintenanceHtmlMessage($sMessage)
|
||||||
|
{
|
||||||
|
echo '<html><body><div>'.$sMessage.'</div></body></html>';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* helper to test if a string ends with another
|
||||||
|
* @param $haystack
|
||||||
|
* @param $needle
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
function EndsWith($haystack, $needle) {
|
||||||
|
return substr_compare($haystack, $needle, -strlen($needle)) === 0;
|
||||||
|
}
|
||||||
@@ -442,6 +442,8 @@ Dict::Add('DE DE', 'German', 'Deutsch', array(
|
|||||||
'UI:Error:Invalid_Stimulus_On_Object_In_State' => 'Fehler: ungültiger Operation "%1$s" auf Objekt %2$s in Zustand "%3$s".',
|
'UI:Error:Invalid_Stimulus_On_Object_In_State' => 'Fehler: ungültiger Operation "%1$s" auf Objekt %2$s in Zustand "%3$s".',
|
||||||
'UI:Error:InvalidDashboardFile' => 'Fehler: Ungültige Dashboard-Datei',
|
'UI:Error:InvalidDashboardFile' => 'Fehler: Ungültige Dashboard-Datei',
|
||||||
'UI:Error:InvalidDashboard' => 'Fehler: Ungültiges Dashboard',
|
'UI:Error:InvalidDashboard' => 'Fehler: Ungültiges Dashboard',
|
||||||
|
'UI:Error:MaintenanceMode' => 'Die Anwendung befindet sich derzeit in der Wartung.',
|
||||||
|
'UI:Error:MaintenanceTitle' => 'Maintenance~~',
|
||||||
|
|
||||||
'UI:GroupBy:Count' => 'Anzahl',
|
'UI:GroupBy:Count' => 'Anzahl',
|
||||||
'UI:GroupBy:Count+' => 'Anzahl der Elemente',
|
'UI:GroupBy:Count+' => 'Anzahl der Elemente',
|
||||||
|
|||||||
@@ -458,6 +458,8 @@ Dict::Add('EN US', 'English', 'English', array(
|
|||||||
'UI:Error:Invalid_Stimulus_On_Object_In_State' => 'Error: invalid stimulus "%1$s" on object %2$s in state "%3$s".',
|
'UI:Error:Invalid_Stimulus_On_Object_In_State' => 'Error: invalid stimulus "%1$s" on object %2$s in state "%3$s".',
|
||||||
'UI:Error:InvalidDashboardFile' => 'Error: invalid dashboard file',
|
'UI:Error:InvalidDashboardFile' => 'Error: invalid dashboard file',
|
||||||
'UI:Error:InvalidDashboard' => 'Error: invalid dashboard',
|
'UI:Error:InvalidDashboard' => 'Error: invalid dashboard',
|
||||||
|
'UI:Error:MaintenanceMode' => 'Application is currently in maintenance',
|
||||||
|
'UI:Error:MaintenanceTitle' => 'Maintenance',
|
||||||
|
|
||||||
'UI:GroupBy:Count' => 'Count',
|
'UI:GroupBy:Count' => 'Count',
|
||||||
'UI:GroupBy:Count+' => 'Number of elements',
|
'UI:GroupBy:Count+' => 'Number of elements',
|
||||||
|
|||||||
@@ -454,6 +454,8 @@ Dict::Add('ES CR', 'Spanish', 'Español, Castellaño', array(
|
|||||||
'UI:Error:Invalid_Stimulus_On_Object_In_State' => 'Error: estimulo invalido "%1$s" en objeto %2$s en estado "%3$s".',
|
'UI:Error:Invalid_Stimulus_On_Object_In_State' => 'Error: estimulo invalido "%1$s" en objeto %2$s en estado "%3$s".',
|
||||||
'UI:Error:InvalidDashboardFile' => 'Error: invalid dashboard file~~',
|
'UI:Error:InvalidDashboardFile' => 'Error: invalid dashboard file~~',
|
||||||
'UI:Error:InvalidDashboard' => 'Error: invalid dashboard~~',
|
'UI:Error:InvalidDashboard' => 'Error: invalid dashboard~~',
|
||||||
|
'UI:Error:MaintenanceMode' => 'La aplicación se encuentra actualmente en mantenimiento',
|
||||||
|
'UI:Error:MaintenanceTitle' => 'Maintenance~~',
|
||||||
|
|
||||||
'UI:GroupBy:Count' => 'Cuenta',
|
'UI:GroupBy:Count' => 'Cuenta',
|
||||||
'UI:GroupBy:Count+' => 'Número de Elementos',
|
'UI:GroupBy:Count+' => 'Número de Elementos',
|
||||||
|
|||||||
@@ -441,6 +441,8 @@ Dict::Add('FR FR', 'French', 'Français', array(
|
|||||||
'UI:Error:Invalid_Stimulus_On_Object_In_State' => 'Erreur: le stimulus "%1$s" n\'est pas valide pour l\'objet %2$s dans l\'état "%3$s".',
|
'UI:Error:Invalid_Stimulus_On_Object_In_State' => 'Erreur: le stimulus "%1$s" n\'est pas valide pour l\'objet %2$s dans l\'état "%3$s".',
|
||||||
'UI:Error:InvalidDashboardFile' => 'Erreur: Le fichier tableau de bord est invalide',
|
'UI:Error:InvalidDashboardFile' => 'Erreur: Le fichier tableau de bord est invalide',
|
||||||
'UI:Error:InvalidDashboard' => 'Erreur: Le tableau de bord est invalide',
|
'UI:Error:InvalidDashboard' => 'Erreur: Le tableau de bord est invalide',
|
||||||
|
'UI:Error:MaintenanceMode' => 'L\'application est en maintenance',
|
||||||
|
'UI:Error:MaintenanceTitle' => 'Maintenance',
|
||||||
|
|
||||||
'UI:GroupBy:Count' => 'Nombre',
|
'UI:GroupBy:Count' => 'Nombre',
|
||||||
'UI:GroupBy:Count+' => 'Nombre d\'éléments',
|
'UI:GroupBy:Count+' => 'Nombre d\'éléments',
|
||||||
|
|||||||
@@ -454,6 +454,8 @@ Dict::Add('IT IT', 'Italian', 'Italiano', array(
|
|||||||
'UI:Error:Invalid_Stimulus_On_Object_In_State' => 'Errore: stimolo non valido "%1$s" su un oggetto %2$s nello stato "%3$s".',
|
'UI:Error:Invalid_Stimulus_On_Object_In_State' => 'Errore: stimolo non valido "%1$s" su un oggetto %2$s nello stato "%3$s".',
|
||||||
'UI:Error:InvalidDashboardFile' => 'Error: invalid dashboard file~~',
|
'UI:Error:InvalidDashboardFile' => 'Error: invalid dashboard file~~',
|
||||||
'UI:Error:InvalidDashboard' => 'Error: invalid dashboard~~',
|
'UI:Error:InvalidDashboard' => 'Error: invalid dashboard~~',
|
||||||
|
'UI:Error:MaintenanceMode' => 'L\'applicazione è attualmente in manutenzione',
|
||||||
|
'UI:Error:MaintenanceTitle' => 'Maintenance~~',
|
||||||
|
|
||||||
'UI:GroupBy:Count' => 'Conteggio',
|
'UI:GroupBy:Count' => 'Conteggio',
|
||||||
'UI:GroupBy:Count+' => '',
|
'UI:GroupBy:Count+' => '',
|
||||||
|
|||||||
@@ -460,6 +460,8 @@ Dict::Add('NL NL', 'Dutch', 'Nederlands', array(
|
|||||||
'UI:Error:Invalid_Stimulus_On_Object_In_State' => 'Fout: ongeldige stimulus "%1$s" op object %2$s in staat "%3$s".',
|
'UI:Error:Invalid_Stimulus_On_Object_In_State' => 'Fout: ongeldige stimulus "%1$s" op object %2$s in staat "%3$s".',
|
||||||
'UI:Error:InvalidDashboardFile' => 'Fout: ongeldig dashboard-bestand',
|
'UI:Error:InvalidDashboardFile' => 'Fout: ongeldig dashboard-bestand',
|
||||||
'UI:Error:InvalidDashboard' => 'Fout: ongeldig dashboard',
|
'UI:Error:InvalidDashboard' => 'Fout: ongeldig dashboard',
|
||||||
|
'UI:Error:MaintenanceMode' => 'Toepassing is momenteel in onderhoud',
|
||||||
|
'UI:Error:MaintenanceTitle' => 'Maintenance~~',
|
||||||
|
|
||||||
'UI:GroupBy:Count' => 'Tel',
|
'UI:GroupBy:Count' => 'Tel',
|
||||||
'UI:GroupBy:Count+' => 'Aantal elementen',
|
'UI:GroupBy:Count+' => 'Aantal elementen',
|
||||||
|
|||||||
@@ -40,6 +40,16 @@ require_once(APPROOT.'core/metamodel.class.php');
|
|||||||
|
|
||||||
utils::InitTimeZone();
|
utils::InitTimeZone();
|
||||||
|
|
||||||
|
// Maintenance mode
|
||||||
|
if (file_exists(APPROOT.'.maintenance'))
|
||||||
|
{
|
||||||
|
http_response_code(503);
|
||||||
|
require_once(APPROOT.'core/dict.class.inc.php');
|
||||||
|
$sMessage = Dict::S('UI:Error:MaintenanceMode', 'Application is currently in maintenance');
|
||||||
|
echo "$sMessage";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
$sModule = utils::ReadParam('exec_module', '');
|
$sModule = utils::ReadParam('exec_module', '');
|
||||||
if ($sModule == '')
|
if ($sModule == '')
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -310,6 +310,12 @@ function CronExec($oP, $aProcesses, $bVerbose)
|
|||||||
$oP->p("Sleeping");
|
$oP->p("Sleeping");
|
||||||
}
|
}
|
||||||
sleep($iCronSleep);
|
sleep($iCronSleep);
|
||||||
|
// Maintenance mode
|
||||||
|
if (file_exists(APPROOT.'.maintenance'))
|
||||||
|
{
|
||||||
|
$oP->p("Maintenance mode detected");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ($bVerbose)
|
if ($bVerbose)
|
||||||
{
|
{
|
||||||
@@ -565,10 +571,11 @@ try
|
|||||||
{
|
{
|
||||||
// Note: testing this now in case some of the background processes forces the read-only mode for a while
|
// Note: testing this now in case some of the background processes forces the read-only mode for a while
|
||||||
// in that case it is better to exit with the check on reentrance (mutex)
|
// in that case it is better to exit with the check on reentrance (mutex)
|
||||||
if (!MetaModel::DBHasAccess(ACCESS_ADMIN_WRITE))
|
if (!MetaModel::DBHasAccess(ACCESS_ADMIN_WRITE) || file_exists(APPROOT.'.maintenance'))
|
||||||
{
|
{
|
||||||
$oP->p("A database maintenance is ongoing (read-only mode even for admins).");
|
$oP->p("A maintenance is ongoing");
|
||||||
$oP->Output();
|
$oP->Output();
|
||||||
|
$oMutex->Unlock();
|
||||||
exit(EXIT_CODE_ERROR);
|
exit(EXIT_CODE_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -609,4 +616,3 @@ finally
|
|||||||
$oP->p("Exiting: ".time().' ('.date('Y-m-d H:i:s').')');
|
$oP->p("Exiting: ".time().' ('.date('Y-m-d H:i:s').')');
|
||||||
|
|
||||||
$oP->Output();
|
$oP->Output();
|
||||||
?>
|
|
||||||
Reference in New Issue
Block a user