Files
scripts-bash/servers/linux/monitoring/bin/monitoring-update.php

58 lines
1.8 KiB
PHP
Executable File

#!/usr/bin/env php
<?php
/**
* Moteur de mise à jour (Wrapper pour le script Bash)
*/
require_once __DIR__ . '/../lib/monitoring-lib.php';
// Sécurité : Un seul update à la fois
lock_or_exit("monitoring-update");
echo "\e[1m--- Début de la mise à jour système ---\e[0m\n";
$install_script = __DIR__ . '/install-monitoring.sh';
if (!file_exists($install_script)) {
log_error("update_script_missing", "Script d'installation introuvable", ["path" => $install_script]);
echo "\e[31m[ERR]\e[0m Script d'installation introuvable : $install_script\n";
exit(1);
}
// On ouvre un pipe pour lire la sortie du Bash en temps réel
$command = "bash " . escapeshellarg($install_script) . " --auto 2>&1";
$handle = popen($command, 'r');
if ($handle) {
while (!feof($handle)) {
$line = fgets($handle);
if ($line) {
// 1. On affiche à l'écran en temps réel
echo $line;
// 2. On loggue les erreurs importantes dans le JSONL
if (strpos($line, '[ERR]') !== false) {
log_error("update_process_error", trim($line));
}
}
}
$exit_code = pclose($handle);
} else {
$exit_code = 1;
}
if ($exit_code === 0) {
// Tâches de finalisation PHP
echo "\e[1m--- Finalisation des configurations ---\e[0m\n";
run_local_conf_sync(); // Audit des fichiers .local
ensure_crontab_entries(); // Vérification du cron
log_info("update_finished", "Mise à jour réussie");
echo "\e[32m[OK]\e[0m Mise à jour terminée avec succès.\n";
} else {
log_error("update_failed", "Le script de synchronisation a échoué", ["code" => $exit_code]);
echo "\e[31m[ERR]\e[0m Échec de la mise à jour (Code: $exit_code).\n";
exit($exit_code);
}
exit_with_status();