From d2b7b0265ab5aaca7798301587cba4da6559c7b7 Mon Sep 17 00:00:00 2001 From: jmbardallo Date: Thu, 14 May 2026 13:18:10 +0200 Subject: [PATCH 01/18] Creado endpoint para mostrar logs desde disco de los distintos componentes de OG --- src/Controller/System/DiskLogsAction.php | 59 ++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/Controller/System/DiskLogsAction.php diff --git a/src/Controller/System/DiskLogsAction.php b/src/Controller/System/DiskLogsAction.php new file mode 100644 index 0000000..4222df0 --- /dev/null +++ b/src/Controller/System/DiskLogsAction.php @@ -0,0 +1,59 @@ +query->get('SYSLOG_IDENTIFIER'); + $host = $request->query->get('host'); + $lines = $request->query->getInt('lines', 100); + + if (!$identifier) { + return new JsonResponse(['error' => 'El parámetro SYSLOG_IDENTIFIER es obligatorio.'], Response::HTTP_BAD_REQUEST); + } + + // Sanitización básica + $lines = max(1, min(1000, $lines)); // Limitar entre 1 y 1000 líneas por seguridad/rendimiento + + $args = []; + $args[] = sprintf('SYSLOG_IDENTIFIER=%s', escapeshellarg($identifier)); + + if ($host) { + $args[] = sprintf('_HOSTNAME=%s', escapeshellarg($host)); + } + + $command = sprintf('journalctl %s --no-pager -n %d 2>&1', implode(' ', $args), $lines); + + $output = []; + $returnVar = 0; + exec($command, $output, $returnVar); + + if ($returnVar !== 0) { + return new JsonResponse([ + 'error' => 'Error al ejecutar journalctl', + 'command' => $command, + 'output' => implode("\n", $output) + ], Response::HTTP_INTERNAL_SERVER_ERROR); + } + + return new JsonResponse([ + 'identifier' => $identifier, + 'host' => $host, + 'lines' => $lines, + 'content' => implode("\n", $output) + ]); + } +} -- 2.40.1 From 02f5d5248a663f3684a3c1876e1f85d28f4bb276 Mon Sep 17 00:00:00 2001 From: jmbardallo Date: Thu, 14 May 2026 13:18:10 +0200 Subject: [PATCH 02/18] Creado endpoint para mostrar logs desde disco de los distintos componentes de OG --- src/Controller/System/DiskLogsAction.php | 59 ++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/Controller/System/DiskLogsAction.php diff --git a/src/Controller/System/DiskLogsAction.php b/src/Controller/System/DiskLogsAction.php new file mode 100644 index 0000000..6d3db4d --- /dev/null +++ b/src/Controller/System/DiskLogsAction.php @@ -0,0 +1,59 @@ +query->get('SYSLOG_IDENTIFIER'); + $host = $request->query->get('host'); + $lines = $request->query->getInt('lines', 100); + + if (!$identifier) { + return new JsonResponse(['error' => 'El parámetro SYSLOG_IDENTIFIER es obligatorio.'], Response::HTTP_BAD_REQUEST); + } + + // Sanitización básica + $lines = max(1, min(1000, $lines)); // Limitar entre 1 y 1000 líneas por seguridad/rendimiento + + $args = []; + $args[] = sprintf('SYSLOG_IDENTIFIER=%s', escapeshellarg($identifier)); + + if ($host) { + $args[] = sprintf('_HOSTNAME=%s', escapeshellarg($host)); + } + + $command = sprintf('journalctl %s --no-pager -n %d 2>&1', implode(' ', $args), $lines); + + $output = []; + $returnVar = 0; + exec($command, $output, $returnVar); + + if ($returnVar !== 0) { + return new JsonResponse([ + 'error' => 'Error al ejecutar journalctl', + 'command' => $command, + 'output' => implode("\n", $output) + ], Response::HTTP_INTERNAL_SERVER_ERROR); + } + + return new JsonResponse([ + 'identifier' => $identifier, + 'host' => $host, + 'lines' => $lines, + 'content' => implode("\n", $output) + ]); + } +} -- 2.40.1 From 2ac9d27d97e99cf7bb72f0dd9dc84bc9d8a665ec Mon Sep 17 00:00:00 2001 From: jmbardallo Date: Thu, 14 May 2026 14:42:16 +0200 Subject: [PATCH 03/18] Corregida migracion de perfiles hardware y software, los tipos de software y hardware no se guardaban en base de datos antes de tener que ser usados por los perfiles --- CHANGELOG.md | 4 ++++ .../Migration/MigrateHardwareAndHardwareProfileCommand.php | 2 ++ .../Migration/MigrateSoftwareAndSoftwareProfileCommand.php | 2 ++ src/Dto/Output/HardwareOutput.php | 2 +- 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b228ddd..77f54a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [1.7.12] - 2026-05-14 +### Fixed +- Corregida migracion de perfiles hardware y software, los tipos de software y hardware no se guardaban en base de datos antes de tener que ser usados por los perfiles. + ## [1.7.11] - 2026-05-14 ### Fixed - Corregido error "Call to undefined method App\Entity\Image::setRemotePc()" al importar una imagen desde un repositorio. La propiedad `remotePc` fue eliminada de la entidad `Image` en la versión 1.7.0 pero la llamada a `setRemotePc()` no fue eliminada del controlador `ImportAction`. diff --git a/src/Command/Migration/MigrateHardwareAndHardwareProfileCommand.php b/src/Command/Migration/MigrateHardwareAndHardwareProfileCommand.php index 05e0d45..1ca7254 100644 --- a/src/Command/Migration/MigrateHardwareAndHardwareProfileCommand.php +++ b/src/Command/Migration/MigrateHardwareAndHardwareProfileCommand.php @@ -59,6 +59,7 @@ class MigrateHardwareAndHardwareProfileCommand extends Command $this->entityManager->persist($hardwareProfileEntity); } + $this->entityManager->flush(); /** Obtener los hardware de la base de datos antigua **/ $rsmHardware = new ResultSetMapping(); @@ -97,6 +98,7 @@ class MigrateHardwareAndHardwareProfileCommand extends Command $this->entityManager->persist($hardwareEntity); } + $this->entityManager->flush(); /** * In OpenGnsys 2.0, HardwareProfile is linked OneToOne with Client and is mandatory. diff --git a/src/Command/Migration/MigrateSoftwareAndSoftwareProfileCommand.php b/src/Command/Migration/MigrateSoftwareAndSoftwareProfileCommand.php index a3ce7e7..35af7a9 100644 --- a/src/Command/Migration/MigrateSoftwareAndSoftwareProfileCommand.php +++ b/src/Command/Migration/MigrateSoftwareAndSoftwareProfileCommand.php @@ -73,6 +73,7 @@ class MigrateSoftwareAndSoftwareProfileCommand extends Command $this->entityManager->persist($softwareEntity); } + $this->entityManager->flush(); /** Obtener los perfiles software de la base de datos antigua **/ $rsmSoftwareProfiles = new ResultSetMapping(); @@ -104,6 +105,7 @@ class MigrateSoftwareAndSoftwareProfileCommand extends Command $this->entityManager->persist($softwareProfileEntity); } + $this->entityManager->flush(); /** Obtener los software, y asignarselos a los perfiles software **/ $rsmSoftwareProfilesRelation = new ResultSetMapping(); diff --git a/src/Dto/Output/HardwareOutput.php b/src/Dto/Output/HardwareOutput.php index 39a1d80..4763286 100644 --- a/src/Dto/Output/HardwareOutput.php +++ b/src/Dto/Output/HardwareOutput.php @@ -51,7 +51,7 @@ final class HardwareOutput extends AbstractOutput $this->name = $hardware->getName(); $this->description = $hardware->getDescription(); - $this->type = new HardwareTypeOutput($hardware->getType()); + $this->type = $hardware->getType() ? new HardwareTypeOutput($hardware->getType()) : null; $this->createdAt = $hardware->getCreatedAt(); $this->createdBy = $hardware->getCreatedBy(); } -- 2.40.1 From 341f10fc97384dd78a1aaec26244ea648cb229bd Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Thu, 14 May 2026 17:36:12 +0200 Subject: [PATCH 04/18] Testing devel --- Jenkins/Jenkinsfile-deb-pkg | 33 ++++++++ debian/ogcore.postinst | 12 +++ etc/bin/journal-pull-sync.sh | 30 +++++++ etc/systemd/system/journal-pull-sync.path | 8 ++ etc/systemd/system/journal-pull-sync.service | 7 ++ etc/systemd/system/journal-pull@.service | 14 ++++ src/EventSubscriber/JournalPullSubscriber.php | 80 +++++++++++++++++++ src/Service/JournalPullService.php | 56 +++++++++++++ 8 files changed, 240 insertions(+) create mode 100644 etc/bin/journal-pull-sync.sh create mode 100644 etc/systemd/system/journal-pull-sync.path create mode 100644 etc/systemd/system/journal-pull-sync.service create mode 100644 etc/systemd/system/journal-pull@.service create mode 100644 src/EventSubscriber/JournalPullSubscriber.php create mode 100644 src/Service/JournalPullService.php diff --git a/Jenkins/Jenkinsfile-deb-pkg b/Jenkins/Jenkinsfile-deb-pkg index 2b4384a..75a6f40 100644 --- a/Jenkins/Jenkinsfile-deb-pkg +++ b/Jenkins/Jenkinsfile-deb-pkg @@ -61,6 +61,19 @@ pipeline { } } + stage('Generate Changelog (Devel)') { + when { + branch 'devel' + } + steps { + script { + def devName = params.DEV_NAME ? params.DEV_NAME : env.DEFAULT_DEV_NAME + def devEmail = params.DEV_EMAIL ? params.DEV_EMAIL : env.DEFAULT_DEV_EMAIL + generateDebianChangelog(env.BUILD_DIR, devName, devEmail, "devel") + } + }} + } + stage('Build') { steps { script { @@ -96,6 +109,19 @@ pipeline { } } } + + stage ('Publish to Debian Repository (Devel)') { + when { + branch 'devel' + } + agent { label 'debian-repo' } + steps { + script { + def versionPattern = "-${env.BUILD_NUMBER}~devel" + publicarEnAptly('/var/tmp/opengnsys/debian-repo/ogcore', 'devel', versionPattern) + } + } + } } post { success { @@ -108,6 +134,13 @@ pipeline { string(name: 'TRIGGERED_BY', value: "${env.JOB_NAME}-${env.BUILD_NUMBER}") ] } + if (env.BRANCH_NAME == 'devel') { + build job: 'Aptly publish develop repository', + wait: false, + parameters: [ + string(name: 'TRIGGERED_BY', value: "${env.JOB_NAME}-${env.BUILD_NUMBER}") + ] + } } } diff --git a/debian/ogcore.postinst b/debian/ogcore.postinst index f31fdfd..85ddfe1 100644 --- a/debian/ogcore.postinst +++ b/debian/ogcore.postinst @@ -79,12 +79,24 @@ if [ "$1" = "configure" ] && [ -z "$2" ]; then ln -s /opt/opengnsys/ogcore/etc/nginx/sites-available/mercure.conf /etc/nginx/sites-enabled/mercure.conf ln -s /opt/opengnsys/ogcore/etc/php/8.3/fpm/pool.d/ogcore-fpm.conf /etc/php/8.3/fpm/pool.d/ogcore-fpm.conf ln -s /opt/opengnsys/ogcore/etc/systemd/system/og-mercure.service /etc/systemd/system/og-mercure.service + ln -s /opt/opengnsys/ogcore/etc/systemd/system/journal-pull@.service /etc/systemd/system/journal-pull@.service + ln -s /opt/opengnsys/ogcore/etc/systemd/system/journal-pull-sync.path /etc/systemd/system/journal-pull-sync.path + ln -s /opt/opengnsys/ogcore/etc/systemd/system/journal-pull-sync.service /etc/systemd/system/journal-pull-sync.service + + echo ">>> Configurando journal-pull" + touch /opt/opengnsys/ogcore/etc/journal-pull-sources.conf + chmod +x /opt/opengnsys/ogcore/etc/bin/journal-pull-sync.sh + mkdir -p /var/log/journal/remote + chown systemd-journal-remote:systemd-journal-remote /var/log/journal/remote echo ">>> Configurando permisos de archivos" chown opengnsys:www-data /opt/opengnsys/ chown -R opengnsys:www-data /opt/opengnsys/ogcore + chown www-data:www-data /opt/opengnsys/ogcore/etc/journal-pull-sources.conf + chmod 664 /opt/opengnsys/ogcore/etc/journal-pull-sources.conf systemctl daemon-reload systemctl enable og-mercure + systemctl enable --now journal-pull-sync.path systemctl restart mariadb.service systemctl restart og-mercure systemctl restart nginx diff --git a/etc/bin/journal-pull-sync.sh b/etc/bin/journal-pull-sync.sh new file mode 100644 index 0000000..ecdf344 --- /dev/null +++ b/etc/bin/journal-pull-sync.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# Syncs journal-pull@ systemd instances with /etc/opengnsys/journal-pull-sources.conf. +# Triggered by journal-pull-sync.path whenever the config file changes. +set -euo pipefail + +CONF=/opt/opengnsys/ogcore/etc/journal-pull-sources.conf + +[[ -f "$CONF" ]] || exit 0 + +mapfile -t WANTED < <(grep -v '^\s*#' "$CONF" | grep -v '^\s*$' | sort -u) +mapfile -t CURRENT < <( + systemctl list-units 'journal-pull@*.service' --all --plain --no-legend \ + | awk '{print $1}' | sed 's/journal-pull@//;s/\.service//' | sort -u +) + +for ip in "${WANTED[@]:-}"; do + [[ -z "$ip" ]] && continue + if ! printf '%s\n' "${CURRENT[@]:-}" | grep -qxF "$ip"; then + systemctl enable --now "journal-pull@${ip}.service" + echo "journal-pull-sync: enabled journal-pull@${ip}" + fi +done + +for ip in "${CURRENT[@]:-}"; do + [[ -z "$ip" ]] && continue + if ! printf '%s\n' "${WANTED[@]:-}" | grep -qxF "$ip"; then + systemctl disable --now "journal-pull@${ip}.service" + echo "journal-pull-sync: disabled journal-pull@${ip}" + fi +done diff --git a/etc/systemd/system/journal-pull-sync.path b/etc/systemd/system/journal-pull-sync.path new file mode 100644 index 0000000..cb9ab4f --- /dev/null +++ b/etc/systemd/system/journal-pull-sync.path @@ -0,0 +1,8 @@ +[Unit] +Description=Watch journal-pull sources config + +[Path] +PathModified=/opt/opengnsys/ogcore/etc/journal-pull-sources.conf + +[Install] +WantedBy=multi-user.target diff --git a/etc/systemd/system/journal-pull-sync.service b/etc/systemd/system/journal-pull-sync.service new file mode 100644 index 0000000..1ce8ff2 --- /dev/null +++ b/etc/systemd/system/journal-pull-sync.service @@ -0,0 +1,7 @@ +[Unit] +Description=Sync journal-pull instances from config +After=network-online.target + +[Service] +Type=oneshot +ExecStart=/opt/opengnsys/ogcore/etc/bin/journal-pull-sync.sh diff --git a/etc/systemd/system/journal-pull@.service b/etc/systemd/system/journal-pull@.service new file mode 100644 index 0000000..91086c0 --- /dev/null +++ b/etc/systemd/system/journal-pull@.service @@ -0,0 +1,14 @@ +[Unit] +Description=Pull OpenGNSYS journal from %i +After=network-online.target +Wants=network-online.target + +[Service] +User=systemd-journal-remote +Group=systemd-journal-remote +ExecStart=/usr/lib/systemd/systemd-journal-remote --url=http://%i:19531/entries?SYSLOG_IDENTIFIER=ogcore&SYSLOG_IDENTIFIER=oggui&SYSLOG_IDENTIFIER=ogdhcp&SYSLOG_IDENTIFIER=ogboot&SYSLOG_IDENTIFIER=ogrepo-api&SYSLOG_IDENTIFIER=ogrepo-api_DEBUG --output=/var/log/journal/remote/%i.journal +Restart=on-failure +RestartSec=10 + +[Install] +WantedBy=multi-user.target diff --git a/src/EventSubscriber/JournalPullSubscriber.php b/src/EventSubscriber/JournalPullSubscriber.php new file mode 100644 index 0000000..dcdf5ac --- /dev/null +++ b/src/EventSubscriber/JournalPullSubscriber.php @@ -0,0 +1,80 @@ + */ + private array $pendingIpChanges = []; + + public function __construct(private readonly JournalPullService $journalPullService) {} + + private function supports(object $entity): bool + { + return $entity instanceof BootServer + || $entity instanceof DhcpServer + || $entity instanceof ImageRepository; + } + + public function postPersist(PostPersistEventArgs $args): void + { + $entity = $args->getObject(); + if (!$this->supports($entity)) { + return; + } + $this->journalPullService->add($entity->getIp()); + } + + public function postRemove(PostRemoveEventArgs $args): void + { + $entity = $args->getObject(); + if (!$this->supports($entity)) { + return; + } + $this->journalPullService->remove($entity->getIp()); + } + + public function preUpdate(PreUpdateEventArgs $args): void + { + $entity = $args->getObject(); + if (!$this->supports($entity) || !$args->hasChangedField('ip')) { + return; + } + $this->pendingIpChanges[spl_object_id($entity)] = [ + 'old' => $args->getOldValue('ip'), + 'new' => $args->getNewValue('ip'), + ]; + } + + public function postUpdate(PostUpdateEventArgs $args): void + { + $entity = $args->getObject(); + if (!$this->supports($entity)) { + return; + } + $oid = spl_object_id($entity); + if (!isset($this->pendingIpChanges[$oid])) { + return; + } + ['old' => $oldIp, 'new' => $newIp] = $this->pendingIpChanges[$oid]; + unset($this->pendingIpChanges[$oid]); + + $this->journalPullService->remove($oldIp); + $this->journalPullService->add($newIp); + } +} diff --git a/src/Service/JournalPullService.php b/src/Service/JournalPullService.php new file mode 100644 index 0000000..7ef1f55 --- /dev/null +++ b/src/Service/JournalPullService.php @@ -0,0 +1,56 @@ +readIps(); + if (in_array($ip, $ips, true)) { + return; + } + $ips[] = $ip; + $this->writeIps($ips); + $this->logger->info('journal-pull: added {ip}', ['ip' => $ip]); + } + + public function remove(string $ip): void + { + $ips = $this->readIps(); + $filtered = array_values(array_filter($ips, fn($i) => $i !== $ip)); + if (count($filtered) === count($ips)) { + return; + } + $this->writeIps($filtered); + $this->logger->info('journal-pull: removed {ip}', ['ip' => $ip]); + } + + private function readIps(): array + { + if (!file_exists(self::CONFIG_FILE)) { + return []; + } + $lines = file(self::CONFIG_FILE, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); + return array_values(array_filter($lines, fn($l) => !str_starts_with(trim($l), '#'))); + } + + private function writeIps(array $ips): void + { + $dir = dirname(self::CONFIG_FILE); + if (!is_dir($dir)) { + mkdir($dir, 0755, true); + } + file_put_contents( + self::CONFIG_FILE, + $ips ? implode("\n", $ips) . "\n" : '', + LOCK_EX + ); + } +} -- 2.40.1 From 98ba1ff94b566767883cb0c30982a9a9172ada6c Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Thu, 14 May 2026 17:45:42 +0200 Subject: [PATCH 05/18] fix Jenkins --- Jenkins/Jenkinsfile-deb-pkg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jenkins/Jenkinsfile-deb-pkg b/Jenkins/Jenkinsfile-deb-pkg index 75a6f40..effa6ba 100644 --- a/Jenkins/Jenkinsfile-deb-pkg +++ b/Jenkins/Jenkinsfile-deb-pkg @@ -71,7 +71,7 @@ pipeline { def devEmail = params.DEV_EMAIL ? params.DEV_EMAIL : env.DEFAULT_DEV_EMAIL generateDebianChangelog(env.BUILD_DIR, devName, devEmail, "devel") } - }} + } } stage('Build') { -- 2.40.1 From f23aeda30811489f37f8265cc411e1a12a13ffd9 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Thu, 14 May 2026 18:51:47 +0200 Subject: [PATCH 06/18] Fix non_interaction problem in ogcore --- debian/ogcore.postinst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/ogcore.postinst b/debian/ogcore.postinst index 85ddfe1..3c07886 100644 --- a/debian/ogcore.postinst +++ b/debian/ogcore.postinst @@ -54,7 +54,7 @@ if [ "$1" = "configure" ] && [ -z "$2" ]; then echo ">>> Creando par de claves para JWT" - php bin/console lexik:jwt:generate-keypair --overwrite + php bin/console lexik:jwt:generate-keypair --overwrite --no-interaction echo ">>> Creando base de datos" php bin/console doctrine:database:create --if-not-exists -- 2.40.1 From 3c4d179c86a2b87d7551e3c0e1a960767cda780d Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Thu, 14 May 2026 19:07:09 +0200 Subject: [PATCH 07/18] add remote journal as dependency --- debian/control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/control b/debian/control index 565e5bf..c85ee6b 100644 --- a/debian/control +++ b/debian/control @@ -10,7 +10,7 @@ Architecture: all Depends: ${misc:Depends}, mariadb-server, systemd, nginx, libzip-dev, zip, unzip, php8.3-opcache, php8.3-bcmath, php8.3-cli, php8.3-curl, php8.3-fpm, php8.3-gd, php8.3-ldap, php8.3-mbstring, php8.3-mysql, php8.3-common, - php8.3-xml, php8.3-zip, mercure + php8.3-xml, php8.3-zip, mercure, systemd-journal-remote Description: OpenGnsys Core OgCore package is responsible about management of Opengnsys platform OpenGnsys Core is a platform for system management. -- 2.40.1 From 6099f6be4bfabbec36248d7b52dbecdd9ee691c6 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Thu, 14 May 2026 21:39:33 +0200 Subject: [PATCH 08/18] =?UTF-8?q?feat(oggui):=20soporte=20de=20m=C3=BAltip?= =?UTF-8?q?les=20SYSLOG=5FIDENTIFIER=20en=20visor=20de=20logs=20de=20disco?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - StatusLogsComponent: @Input identifiers[] en lugar de identifier string, parseo de entries JSON estructurado con formato [timestamp] ID: mensaje - Templates ogboot, ogdhcp, ogrepository, ogcore-status: identifiers correctos por componente y host basado en IP en lugar de nombre del servidor - Añadidos métodos getSelectedXxxIp() en ogboot, ogdhcp y ogrepository status --- debian/ogcore.postinst | 2 + etc/systemd/system/journal-pull@.service | 2 +- src/Controller/System/DiskLogsAction.php | 55 +++++++++++++++++------- 3 files changed, 43 insertions(+), 16 deletions(-) diff --git a/debian/ogcore.postinst b/debian/ogcore.postinst index 3c07886..0b3de69 100644 --- a/debian/ogcore.postinst +++ b/debian/ogcore.postinst @@ -94,6 +94,8 @@ if [ "$1" = "configure" ] && [ -z "$2" ]; then chown -R opengnsys:www-data /opt/opengnsys/ogcore chown www-data:www-data /opt/opengnsys/ogcore/etc/journal-pull-sources.conf chmod 664 /opt/opengnsys/ogcore/etc/journal-pull-sources.conf + usermod -aG systemd-journal opengnsys + usermod -aG systemd-journal-remote opengnsys systemctl daemon-reload systemctl enable og-mercure systemctl enable --now journal-pull-sync.path diff --git a/etc/systemd/system/journal-pull@.service b/etc/systemd/system/journal-pull@.service index 91086c0..fa9e91b 100644 --- a/etc/systemd/system/journal-pull@.service +++ b/etc/systemd/system/journal-pull@.service @@ -6,7 +6,7 @@ Wants=network-online.target [Service] User=systemd-journal-remote Group=systemd-journal-remote -ExecStart=/usr/lib/systemd/systemd-journal-remote --url=http://%i:19531/entries?SYSLOG_IDENTIFIER=ogcore&SYSLOG_IDENTIFIER=oggui&SYSLOG_IDENTIFIER=ogdhcp&SYSLOG_IDENTIFIER=ogboot&SYSLOG_IDENTIFIER=ogrepo-api&SYSLOG_IDENTIFIER=ogrepo-api_DEBUG --output=/var/log/journal/remote/%i.journal +ExecStart=/usr/lib/systemd/systemd-journal-remote --url=http://%i:19531/entries?SYSLOG_IDENTIFIER=ogcore&SYSLOG_IDENTIFIER=oggui&SYSLOG_IDENTIFIER=ogdhcp&SYSLOG_IDENTIFIER=ogboot&SYSLOG_IDENTIFIER=ogrepo-api&SYSLOG_IDENTIFIER=ogrepo-api_DEBUG&SYSLOG_IDENTIFIER=kea-dhcp4&SYSLOG_IDENTIFIER=kea-ctrl-agent&SYSLOG_IDENTIFIER=DhcpLFC&SYSLOG_IDENTIFIER=kea-dhcp6&SYSLOG_IDENTIFIER=tftpd-hpa&SYSLOG_IDENTIFIER=%%28smbd%%29&SYSLOG_IDENTIFIER=%%28nmbd%%29 --split-mode=none --output=/var/log/journal/remote/%i.journal Restart=on-failure RestartSec=10 diff --git a/src/Controller/System/DiskLogsAction.php b/src/Controller/System/DiskLogsAction.php index 6d3db4d..a9b1078 100644 --- a/src/Controller/System/DiskLogsAction.php +++ b/src/Controller/System/DiskLogsAction.php @@ -13,29 +13,49 @@ use Symfony\Component\Security\Http\Attribute\IsGranted; class DiskLogsAction extends AbstractController { + private const REMOTE_JOURNAL_DIR = '/var/log/journal/remote'; + #[Route('/opengnsys/system/disk-logs', name: 'api_system_disk_logs', methods: ['GET'])] #[IsGranted('ROLE_USER')] public function __invoke(Request $request): JsonResponse { - $identifier = $request->query->get('SYSLOG_IDENTIFIER'); + // Acepta SYSLOG_IDENTIFIER como valor único, array (?SYSLOG_IDENTIFIER[]=a&SYSLOG_IDENTIFIER[]=b) + // o lista separada por comas (?SYSLOG_IDENTIFIER=a,b) + $rawIdentifiers = $request->query->all()['SYSLOG_IDENTIFIER'] ?? $request->query->get('SYSLOG_IDENTIFIER'); + if (is_string($rawIdentifiers)) { + $rawIdentifiers = array_map('trim', explode(',', $rawIdentifiers)); + } + $identifiers = array_values(array_filter((array) $rawIdentifiers)); + $host = $request->query->get('host'); $lines = $request->query->getInt('lines', 100); - if (!$identifier) { + if (empty($identifiers)) { return new JsonResponse(['error' => 'El parámetro SYSLOG_IDENTIFIER es obligatorio.'], Response::HTTP_BAD_REQUEST); } - // Sanitización básica - $lines = max(1, min(1000, $lines)); // Limitar entre 1 y 1000 líneas por seguridad/rendimiento - - $args = []; - $args[] = sprintf('SYSLOG_IDENTIFIER=%s', escapeshellarg($identifier)); - + $lines = max(1, min(1000, $lines)); + + $args = ['--no-pager', '--output=json', sprintf('-n %d', $lines)]; + if ($host) { - $args[] = sprintf('_HOSTNAME=%s', escapeshellarg($host)); + // Host remoto: leer del fichero journal nombrado por IP + $journalFile = sprintf('%s/%s.journal', self::REMOTE_JOURNAL_DIR, $host); + if (!file_exists($journalFile)) { + return new JsonResponse( + ['error' => sprintf('No se encontró el journal para el host %s', $host)], + Response::HTTP_NOT_FOUND + ); + } + $args[] = sprintf('--file=%s', escapeshellarg($journalFile)); } - $command = sprintf('journalctl %s --no-pager -n %d 2>&1', implode(' ', $args), $lines); + // Múltiples SYSLOG_IDENTIFIER se pasan como matches separados → journalctl los aplica con OR + foreach ($identifiers as $identifier) { + $args[] = sprintf('SYSLOG_IDENTIFIER=%s', escapeshellarg($identifier)); + } + + $command = sprintf('journalctl %s 2>&1', implode(' ', $args)); $output = []; $returnVar = 0; @@ -44,16 +64,21 @@ class DiskLogsAction extends AbstractController if ($returnVar !== 0) { return new JsonResponse([ 'error' => 'Error al ejecutar journalctl', - 'command' => $command, 'output' => implode("\n", $output) ], Response::HTTP_INTERNAL_SERVER_ERROR); } + // Parsear cada línea como JSON (formato --output=json de journalctl) + $entries = array_values(array_filter(array_map( + static fn(string $line) => json_decode($line, true), + $output + ))); + return new JsonResponse([ - 'identifier' => $identifier, - 'host' => $host, - 'lines' => $lines, - 'content' => implode("\n", $output) + 'identifiers' => $identifiers, + 'host' => $host ?? 'local', + 'lines' => count($entries), + 'entries' => $entries, ]); } } -- 2.40.1 From 45bb270198f4d73011a93c4fec3dd05e298fdbd3 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Thu, 14 May 2026 21:46:34 +0200 Subject: [PATCH 09/18] update CHANGELOG.md --- CHANGELOG.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b228ddd..1117bfb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,25 @@ # Changelog +## [1.8.0] - 2026-05-14 + +### Added +- Infraestructura journal-pull: servicio plantilla `journal-pull@.service` para + extraer journals de componentes por IP vía `systemd-journal-gatewayd`, con + filtros para ogcore, ogdhcp, ogboot, ogrepo, kea, tftpd-hpa y samba +- `JournalPullService` y `JournalPullSubscriber`: habilitación y deshabilitación + automática de `journal-pull@` al registrar o eliminar un BootServer, + DhcpServer o ImageRepository desde el GUI +- `DiskLogsAction`: soporte de múltiples `SYSLOG_IDENTIFIER` separados por coma + o en array, salida estructurada en JSON y lectura desde fichero de journal + remoto (`/var/log/journal/remote/.journal`) cuando se indica el parámetro host + +### Fixed +- postinst: añadido `--no-interaction` al comando de generación de claves JWT + para evitar bloqueo en instalación desatendida +- postinst: permisos de acceso al journal para el usuario `opengnsys` + (`systemd-journal` y `systemd-journal-remote`) +- `systemd-journal-remote` añadido como dependencia del paquete + ## [1.7.11] - 2026-05-14 ### Fixed - Corregido error "Call to undefined method App\Entity\Image::setRemotePc()" al importar una imagen desde un repositorio. La propiedad `remotePc` fue eliminada de la entidad `Image` en la versión 1.7.0 pero la llamada a `setRemotePc()` no fue eliminada del controlador `ImportAction`. -- 2.40.1 From d20e1b27895a131617e93f77ff015e2d07932249 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Mon, 18 May 2026 11:31:37 +0200 Subject: [PATCH 10/18] =?UTF-8?q?fix(ogcore):=20robustez=20y=20rotaci?= =?UTF-8?q?=C3=B3n=20de=20logs=20en=20infraestructura=20journal-pull?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - journal-pull@.service: Restart=always para reconectar tras salida limpia, ExecStartPre elimina el fichero solo si está vacío para evitar cursor inválido - JournalPullSubscriber: protección contra borrado de IP compartida entre componentes al eliminar un servidor; comprueba que ninguna otra entidad BootServer, DhcpServer o ImageRepository usa la misma IP antes de eliminarla de journal-pull-sources.conf - logrotate.d/journal-pull: rotación diaria con 10 días de retención para los ficheros de journal remoto; nocompress para ficheros binarios; para/arranca los servicios journal-pull@ durante la rotación - debian/control: añadidos logrotate y systemd-journal-remote como dependencias - debian/ogcore.postinst: enlace de logrotate config, permisos 775 en api/var/ --- debian/control | 2 +- debian/ogcore.postinst | 2 ++ etc/logrotate.d/journal-pull | 18 ++++++++++++ etc/systemd/system/journal-pull@.service | 3 +- src/EventSubscriber/JournalPullSubscriber.php | 28 +++++++++++++++++-- 5 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 etc/logrotate.d/journal-pull diff --git a/debian/control b/debian/control index c85ee6b..08f372b 100644 --- a/debian/control +++ b/debian/control @@ -10,7 +10,7 @@ Architecture: all Depends: ${misc:Depends}, mariadb-server, systemd, nginx, libzip-dev, zip, unzip, php8.3-opcache, php8.3-bcmath, php8.3-cli, php8.3-curl, php8.3-fpm, php8.3-gd, php8.3-ldap, php8.3-mbstring, php8.3-mysql, php8.3-common, - php8.3-xml, php8.3-zip, mercure, systemd-journal-remote + php8.3-xml, php8.3-zip, mercure, systemd-journal-remote, logrotate Description: OpenGnsys Core OgCore package is responsible about management of Opengnsys platform OpenGnsys Core is a platform for system management. diff --git a/debian/ogcore.postinst b/debian/ogcore.postinst index 0b3de69..68ab6df 100644 --- a/debian/ogcore.postinst +++ b/debian/ogcore.postinst @@ -82,6 +82,7 @@ if [ "$1" = "configure" ] && [ -z "$2" ]; then ln -s /opt/opengnsys/ogcore/etc/systemd/system/journal-pull@.service /etc/systemd/system/journal-pull@.service ln -s /opt/opengnsys/ogcore/etc/systemd/system/journal-pull-sync.path /etc/systemd/system/journal-pull-sync.path ln -s /opt/opengnsys/ogcore/etc/systemd/system/journal-pull-sync.service /etc/systemd/system/journal-pull-sync.service + ln -s /opt/opengnsys/ogcore/etc/logrotate.d/journal-pull /etc/logrotate.d/journal-pull echo ">>> Configurando journal-pull" touch /opt/opengnsys/ogcore/etc/journal-pull-sources.conf @@ -92,6 +93,7 @@ if [ "$1" = "configure" ] && [ -z "$2" ]; then echo ">>> Configurando permisos de archivos" chown opengnsys:www-data /opt/opengnsys/ chown -R opengnsys:www-data /opt/opengnsys/ogcore + chmod -R 775 /opt/opengnsys/ogcore/api/var/ chown www-data:www-data /opt/opengnsys/ogcore/etc/journal-pull-sources.conf chmod 664 /opt/opengnsys/ogcore/etc/journal-pull-sources.conf usermod -aG systemd-journal opengnsys diff --git a/etc/logrotate.d/journal-pull b/etc/logrotate.d/journal-pull new file mode 100644 index 0000000..d0db540 --- /dev/null +++ b/etc/logrotate.d/journal-pull @@ -0,0 +1,18 @@ +/var/log/journal/remote/*.journal { + daily + rotate 10 + dateext + missingok + nocompress + sharedscripts + prerotate + systemctl stop $(systemctl list-units --plain --no-legend \ + --state=active 'journal-pull@*.service' \ + | awk '{print $1}') 2>/dev/null || true + endscript + postrotate + systemctl start $(systemctl list-units --plain --no-legend \ + --state=inactive 'journal-pull@*.service' \ + | awk '{print $1}') 2>/dev/null || true + endscript +} diff --git a/etc/systemd/system/journal-pull@.service b/etc/systemd/system/journal-pull@.service index fa9e91b..b15e956 100644 --- a/etc/systemd/system/journal-pull@.service +++ b/etc/systemd/system/journal-pull@.service @@ -6,8 +6,9 @@ Wants=network-online.target [Service] User=systemd-journal-remote Group=systemd-journal-remote +ExecStartPre=/bin/sh -c 'f=/var/log/journal/remote/%i.journal; [ -f "$f" ] && journalctl --file="$f" -n 1 --no-pager 2>/dev/null | grep -q "." || rm -f "$f"' ExecStart=/usr/lib/systemd/systemd-journal-remote --url=http://%i:19531/entries?SYSLOG_IDENTIFIER=ogcore&SYSLOG_IDENTIFIER=oggui&SYSLOG_IDENTIFIER=ogdhcp&SYSLOG_IDENTIFIER=ogboot&SYSLOG_IDENTIFIER=ogrepo-api&SYSLOG_IDENTIFIER=ogrepo-api_DEBUG&SYSLOG_IDENTIFIER=kea-dhcp4&SYSLOG_IDENTIFIER=kea-ctrl-agent&SYSLOG_IDENTIFIER=DhcpLFC&SYSLOG_IDENTIFIER=kea-dhcp6&SYSLOG_IDENTIFIER=tftpd-hpa&SYSLOG_IDENTIFIER=%%28smbd%%29&SYSLOG_IDENTIFIER=%%28nmbd%%29 --split-mode=none --output=/var/log/journal/remote/%i.journal -Restart=on-failure +Restart=always RestartSec=10 [Install] diff --git a/src/EventSubscriber/JournalPullSubscriber.php b/src/EventSubscriber/JournalPullSubscriber.php index dcdf5ac..5233bf6 100644 --- a/src/EventSubscriber/JournalPullSubscriber.php +++ b/src/EventSubscriber/JournalPullSubscriber.php @@ -7,6 +7,7 @@ use App\Entity\DhcpServer; use App\Entity\ImageRepository; use App\Service\JournalPullService; use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener; +use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Event\PostPersistEventArgs; use Doctrine\ORM\Event\PostRemoveEventArgs; use Doctrine\ORM\Event\PostUpdateEventArgs; @@ -22,7 +23,10 @@ class JournalPullSubscriber /** @var array */ private array $pendingIpChanges = []; - public function __construct(private readonly JournalPullService $journalPullService) {} + public function __construct( + private readonly JournalPullService $journalPullService, + private readonly EntityManagerInterface $entityManager, + ) {} private function supports(object $entity): bool { @@ -46,7 +50,23 @@ class JournalPullSubscriber if (!$this->supports($entity)) { return; } - $this->journalPullService->remove($entity->getIp()); + if (!$this->isIpStillInUse($entity->getIp(), $entity)) { + $this->journalPullService->remove($entity->getIp()); + } + } + + private function isIpStillInUse(string $ip, object $excludedEntity): bool + { + $types = [BootServer::class, DhcpServer::class, ImageRepository::class]; + foreach ($types as $class) { + $results = $this->entityManager->getRepository($class)->findBy(['ip' => $ip]); + foreach ($results as $entity) { + if ($entity !== $excludedEntity) { + return true; + } + } + } + return false; } public function preUpdate(PreUpdateEventArgs $args): void @@ -74,7 +94,9 @@ class JournalPullSubscriber ['old' => $oldIp, 'new' => $newIp] = $this->pendingIpChanges[$oid]; unset($this->pendingIpChanges[$oid]); - $this->journalPullService->remove($oldIp); + if (!$this->isIpStillInUse($oldIp, $entity)) { + $this->journalPullService->remove($oldIp); + } $this->journalPullService->add($newIp); } } -- 2.40.1 From 34582d519937f6d65dc59828c55181993889ef51 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Mon, 18 May 2026 11:48:50 +0200 Subject: [PATCH 11/18] Updated CHANGELOG.md --- CHANGELOG.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1117bfb..08b2966 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## [1.8.0] - 2026-05-14 +## [1.8.0] - 2026-05-18 ### Added - Infraestructura journal-pull: servicio plantilla `journal-pull@.service` para @@ -8,14 +8,26 @@ filtros para ogcore, ogdhcp, ogboot, ogrepo, kea, tftpd-hpa y samba - `JournalPullService` y `JournalPullSubscriber`: habilitación y deshabilitación automática de `journal-pull@` al registrar o eliminar un BootServer, - DhcpServer o ImageRepository desde el GUI + DhcpServer o ImageRepository desde el GUI; protección contra borrado de IP + compartida entre varios componentes en la misma máquina - `DiskLogsAction`: soporte de múltiples `SYSLOG_IDENTIFIER` separados por coma o en array, salida estructurada en JSON y lectura desde fichero de journal remoto (`/var/log/journal/remote/.journal`) cuando se indica el parámetro host +- Rotación diaria de ficheros de journal remoto con `logrotate` (10 días de + retención); los servicios `journal-pull@` se paran y arrancan durante la rotación +- `logrotate` añadido como dependencia del paquete ### Fixed +- `journal-pull@.service`: `Restart=always` para reconectar tras salida limpia + (sin entradas); `ExecStartPre` elimina el fichero solo si está vacío para + evitar cursor inválido tras fallos previos; `--split-mode=none` requerido + para escritura a fichero único por IP +- `JournalPullSubscriber`: al cambiar la IP de un servidor se verifica que + ninguna otra entidad usa la IP anterior antes de eliminarla del fichero de + configuración - postinst: añadido `--no-interaction` al comando de generación de claves JWT para evitar bloqueo en instalación desatendida +- postinst: permisos `775` en `api/var/` para evitar errores de caché de Doctrine - postinst: permisos de acceso al journal para el usuario `opengnsys` (`systemd-journal` y `systemd-journal-remote`) - `systemd-journal-remote` añadido como dependencia del paquete -- 2.40.1 From a35d49e483b731fffe9c5537ff056f43cd30cbd8 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Mon, 18 May 2026 12:09:08 +0200 Subject: [PATCH 12/18] Updted CHANGELOG.md --- debian/ogcore.postinst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/debian/ogcore.postinst b/debian/ogcore.postinst index 68ab6df..7483809 100644 --- a/debian/ogcore.postinst +++ b/debian/ogcore.postinst @@ -159,8 +159,20 @@ elif [ "$1" = "configure" ] && [ -n "$2" ]; then php bin/console cache:clear echo ">>> Configurando servidor web y servicios" [ ! -L /etc/nginx/sites-enabled/ogcore.conf ] && ln -s /opt/opengnsys/ogcore/etc/nginx/sites-available/ogcore.conf /etc/nginx/sites-enabled/ogcore.conf + [ ! -L /etc/nginx/sites-enabled/mercure.conf ] && ln -s /opt/opengnsys/ogcore/etc/nginx/sites-available/mercure.conf /etc/nginx/sites-enabled/mercure.conf [ ! -L /etc/php/8.3/fpm/pool.d/ogcore-fpm.conf ] && ln -s /opt/opengnsys/ogcore/etc/php/8.3/fpm/pool.d/ogcore-fpm.conf /etc/php/8.3/fpm/pool.d/ogcore-fpm.conf [ ! -L /etc/systemd/system/og-mercure.service ] && ln -s /opt/opengnsys/ogcore/etc/systemd/system/og-mercure.service /etc/systemd/system/og-mercure.service + [ ! -L /etc/systemd/system/journal-pull@.service ] && ln -s /opt/opengnsys/ogcore/etc/systemd/system/journal-pull@.service /etc/systemd/system/journal-pull@.service + [ ! -L /etc/systemd/system/journal-pull-sync.path ] && ln -s /opt/opengnsys/ogcore/etc/systemd/system/journal-pull-sync.path /etc/systemd/system/journal-pull-sync.path + [ ! -L /etc/systemd/system/journal-pull-sync.service ] && ln -s /opt/opengnsys/ogcore/etc/systemd/system/journal-pull-sync.service /etc/systemd/system/journal-pull-sync.service + [ ! -L /etc/logrotate.d/journal-pull ] && ln -s /opt/opengnsys/ogcore/etc/logrotate.d/journal-pull /etc/logrotate.d/journal-pull + chmod +x /opt/opengnsys/ogcore/etc/bin/journal-pull-sync.sh + if [ ! -f /opt/opengnsys/ogcore/etc/journal-pull-sources.conf ]; then + touch /opt/opengnsys/ogcore/etc/journal-pull-sources.conf + chown www-data:www-data /opt/opengnsys/ogcore/etc/journal-pull-sources.conf + chmod 664 /opt/opengnsys/ogcore/etc/journal-pull-sources.conf + fi + [ ! -d /var/log/journal/remote ] && mkdir -p /var/log/journal/remote && chown systemd-journal-remote:systemd-journal-remote /var/log/journal/remote echo ">>> Configurando permisos de archivos" chown opengnsys:www-data /opt/opengnsys/ chown -R opengnsys:www-data /opt/opengnsys/ogcore @@ -175,6 +187,10 @@ elif [ "$1" = "configure" ] && [ -n "$2" ]; then chown root:root /etc/cron.d/opengnsys-check-clients fi systemctl enable og-mercure + systemctl enable --now journal-pull-sync.path 2>/dev/null || true + usermod -aG systemd-journal opengnsys 2>/dev/null || true + usermod -aG systemd-journal-remote opengnsys 2>/dev/null || true + chmod -R 775 /opt/opengnsys/ogcore/api/var/ 2>/dev/null || true systemctl daemon-reload systemctl restart og-mercure systemctl restart php8.3-fpm -- 2.40.1 From ebb6edf1612dde8232e336cae2fd60bed955d59e Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Mon, 18 May 2026 12:29:09 +0200 Subject: [PATCH 13/18] Update changelog --- CHANGELOG.md | 8 +++++++- debian/ogcore.postinst | 8 ++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08b2966..07a8718 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,7 +30,13 @@ - postinst: permisos `775` en `api/var/` para evitar errores de caché de Doctrine - postinst: permisos de acceso al journal para el usuario `opengnsys` (`systemd-journal` y `systemd-journal-remote`) -- `systemd-journal-remote` añadido como dependencia del paquete +- postinst (upgrade): añadidos symlinks faltantes en actualizaciones — + `mercure.conf` en nginx, unidades `journal-pull@`, `journal-pull-sync`, + `logrotate.d/journal-pull`; `chmod +x` en `journal-pull-sync.sh`; + propietario y permisos de `journal-pull-sources.conf`; cambiado `ln -s` + por `ln -sf` en las unidades journal-pull para evitar fallo cuando el + fichero existe como fichero regular en lugar de symlink +- `systemd-journal-remote` y `logrotate` añadidos como dependencias del paquete ## [1.7.11] - 2026-05-14 ### Fixed diff --git a/debian/ogcore.postinst b/debian/ogcore.postinst index 7483809..6d59198 100644 --- a/debian/ogcore.postinst +++ b/debian/ogcore.postinst @@ -162,10 +162,10 @@ elif [ "$1" = "configure" ] && [ -n "$2" ]; then [ ! -L /etc/nginx/sites-enabled/mercure.conf ] && ln -s /opt/opengnsys/ogcore/etc/nginx/sites-available/mercure.conf /etc/nginx/sites-enabled/mercure.conf [ ! -L /etc/php/8.3/fpm/pool.d/ogcore-fpm.conf ] && ln -s /opt/opengnsys/ogcore/etc/php/8.3/fpm/pool.d/ogcore-fpm.conf /etc/php/8.3/fpm/pool.d/ogcore-fpm.conf [ ! -L /etc/systemd/system/og-mercure.service ] && ln -s /opt/opengnsys/ogcore/etc/systemd/system/og-mercure.service /etc/systemd/system/og-mercure.service - [ ! -L /etc/systemd/system/journal-pull@.service ] && ln -s /opt/opengnsys/ogcore/etc/systemd/system/journal-pull@.service /etc/systemd/system/journal-pull@.service - [ ! -L /etc/systemd/system/journal-pull-sync.path ] && ln -s /opt/opengnsys/ogcore/etc/systemd/system/journal-pull-sync.path /etc/systemd/system/journal-pull-sync.path - [ ! -L /etc/systemd/system/journal-pull-sync.service ] && ln -s /opt/opengnsys/ogcore/etc/systemd/system/journal-pull-sync.service /etc/systemd/system/journal-pull-sync.service - [ ! -L /etc/logrotate.d/journal-pull ] && ln -s /opt/opengnsys/ogcore/etc/logrotate.d/journal-pull /etc/logrotate.d/journal-pull + ln -sf /opt/opengnsys/ogcore/etc/systemd/system/journal-pull@.service /etc/systemd/system/journal-pull@.service + ln -sf /opt/opengnsys/ogcore/etc/systemd/system/journal-pull-sync.path /etc/systemd/system/journal-pull-sync.path + ln -sf /opt/opengnsys/ogcore/etc/systemd/system/journal-pull-sync.service /etc/systemd/system/journal-pull-sync.service + ln -sf /opt/opengnsys/ogcore/etc/logrotate.d/journal-pull /etc/logrotate.d/journal-pull chmod +x /opt/opengnsys/ogcore/etc/bin/journal-pull-sync.sh if [ ! -f /opt/opengnsys/ogcore/etc/journal-pull-sources.conf ]; then touch /opt/opengnsys/ogcore/etc/journal-pull-sources.conf -- 2.40.1 From 11122db156ec185d09a2b74831f82dd88f321cf2 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Mon, 18 May 2026 12:49:29 +0200 Subject: [PATCH 14/18] Revert logrotate change for components journal --- CHANGELOG.md | 16 ++++++++-------- debian/control | 2 +- debian/ogcore.postinst | 3 --- etc/logrotate.d/journal-pull | 18 ------------------ 4 files changed, 9 insertions(+), 30 deletions(-) delete mode 100644 etc/logrotate.d/journal-pull diff --git a/CHANGELOG.md b/CHANGELOG.md index 07a8718..aa513d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,9 +13,9 @@ - `DiskLogsAction`: soporte de múltiples `SYSLOG_IDENTIFIER` separados por coma o en array, salida estructurada en JSON y lectura desde fichero de journal remoto (`/var/log/journal/remote/.journal`) cuando se indica el parámetro host -- Rotación diaria de ficheros de journal remoto con `logrotate` (10 días de - retención); los servicios `journal-pull@` se paran y arrancan durante la rotación -- `logrotate` añadido como dependencia del paquete +- La retención de los journals remotos se delega en `systemd-journald` de cada + componente (configurado por oginstaller: 500MB máx, 10 días); los ficheros + pulled en ogcore quedan acotados sin necesidad de logrotate local ### Fixed - `journal-pull@.service`: `Restart=always` para reconectar tras salida limpia @@ -31,11 +31,11 @@ - postinst: permisos de acceso al journal para el usuario `opengnsys` (`systemd-journal` y `systemd-journal-remote`) - postinst (upgrade): añadidos symlinks faltantes en actualizaciones — - `mercure.conf` en nginx, unidades `journal-pull@`, `journal-pull-sync`, - `logrotate.d/journal-pull`; `chmod +x` en `journal-pull-sync.sh`; - propietario y permisos de `journal-pull-sources.conf`; cambiado `ln -s` - por `ln -sf` en las unidades journal-pull para evitar fallo cuando el - fichero existe como fichero regular en lugar de symlink + `mercure.conf` en nginx, unidades `journal-pull@`, `journal-pull-sync`; + `chmod +x` en `journal-pull-sync.sh`; propietario y permisos de + `journal-pull-sources.conf`; cambiado `ln -s` por `ln -sf` en las + unidades journal-pull para evitar fallo cuando el fichero existe como + fichero regular en lugar de symlink - `systemd-journal-remote` y `logrotate` añadidos como dependencias del paquete ## [1.7.11] - 2026-05-14 diff --git a/debian/control b/debian/control index 08f372b..c85ee6b 100644 --- a/debian/control +++ b/debian/control @@ -10,7 +10,7 @@ Architecture: all Depends: ${misc:Depends}, mariadb-server, systemd, nginx, libzip-dev, zip, unzip, php8.3-opcache, php8.3-bcmath, php8.3-cli, php8.3-curl, php8.3-fpm, php8.3-gd, php8.3-ldap, php8.3-mbstring, php8.3-mysql, php8.3-common, - php8.3-xml, php8.3-zip, mercure, systemd-journal-remote, logrotate + php8.3-xml, php8.3-zip, mercure, systemd-journal-remote Description: OpenGnsys Core OgCore package is responsible about management of Opengnsys platform OpenGnsys Core is a platform for system management. diff --git a/debian/ogcore.postinst b/debian/ogcore.postinst index 6d59198..1f6d3bd 100644 --- a/debian/ogcore.postinst +++ b/debian/ogcore.postinst @@ -82,8 +82,6 @@ if [ "$1" = "configure" ] && [ -z "$2" ]; then ln -s /opt/opengnsys/ogcore/etc/systemd/system/journal-pull@.service /etc/systemd/system/journal-pull@.service ln -s /opt/opengnsys/ogcore/etc/systemd/system/journal-pull-sync.path /etc/systemd/system/journal-pull-sync.path ln -s /opt/opengnsys/ogcore/etc/systemd/system/journal-pull-sync.service /etc/systemd/system/journal-pull-sync.service - ln -s /opt/opengnsys/ogcore/etc/logrotate.d/journal-pull /etc/logrotate.d/journal-pull - echo ">>> Configurando journal-pull" touch /opt/opengnsys/ogcore/etc/journal-pull-sources.conf chmod +x /opt/opengnsys/ogcore/etc/bin/journal-pull-sync.sh @@ -165,7 +163,6 @@ elif [ "$1" = "configure" ] && [ -n "$2" ]; then ln -sf /opt/opengnsys/ogcore/etc/systemd/system/journal-pull@.service /etc/systemd/system/journal-pull@.service ln -sf /opt/opengnsys/ogcore/etc/systemd/system/journal-pull-sync.path /etc/systemd/system/journal-pull-sync.path ln -sf /opt/opengnsys/ogcore/etc/systemd/system/journal-pull-sync.service /etc/systemd/system/journal-pull-sync.service - ln -sf /opt/opengnsys/ogcore/etc/logrotate.d/journal-pull /etc/logrotate.d/journal-pull chmod +x /opt/opengnsys/ogcore/etc/bin/journal-pull-sync.sh if [ ! -f /opt/opengnsys/ogcore/etc/journal-pull-sources.conf ]; then touch /opt/opengnsys/ogcore/etc/journal-pull-sources.conf diff --git a/etc/logrotate.d/journal-pull b/etc/logrotate.d/journal-pull deleted file mode 100644 index d0db540..0000000 --- a/etc/logrotate.d/journal-pull +++ /dev/null @@ -1,18 +0,0 @@ -/var/log/journal/remote/*.journal { - daily - rotate 10 - dateext - missingok - nocompress - sharedscripts - prerotate - systemctl stop $(systemctl list-units --plain --no-legend \ - --state=active 'journal-pull@*.service' \ - | awk '{print $1}') 2>/dev/null || true - endscript - postrotate - systemctl start $(systemctl list-units --plain --no-legend \ - --state=inactive 'journal-pull@*.service' \ - | awk '{print $1}') 2>/dev/null || true - endscript -} -- 2.40.1 From 00107d04de88a7f81a35692976fee47b58297231 Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Mon, 18 May 2026 12:52:37 +0200 Subject: [PATCH 15/18] Add clients log rotation --- debian/control | 2 +- debian/ogcore.postinst | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/debian/control b/debian/control index c85ee6b..08f372b 100644 --- a/debian/control +++ b/debian/control @@ -10,7 +10,7 @@ Architecture: all Depends: ${misc:Depends}, mariadb-server, systemd, nginx, libzip-dev, zip, unzip, php8.3-opcache, php8.3-bcmath, php8.3-cli, php8.3-curl, php8.3-fpm, php8.3-gd, php8.3-ldap, php8.3-mbstring, php8.3-mysql, php8.3-common, - php8.3-xml, php8.3-zip, mercure, systemd-journal-remote + php8.3-xml, php8.3-zip, mercure, systemd-journal-remote, logrotate Description: OpenGnsys Core OgCore package is responsible about management of Opengnsys platform OpenGnsys Core is a platform for system management. diff --git a/debian/ogcore.postinst b/debian/ogcore.postinst index 1f6d3bd..02d8292 100644 --- a/debian/ogcore.postinst +++ b/debian/ogcore.postinst @@ -82,6 +82,8 @@ if [ "$1" = "configure" ] && [ -z "$2" ]; then ln -s /opt/opengnsys/ogcore/etc/systemd/system/journal-pull@.service /etc/systemd/system/journal-pull@.service ln -s /opt/opengnsys/ogcore/etc/systemd/system/journal-pull-sync.path /etc/systemd/system/journal-pull-sync.path ln -s /opt/opengnsys/ogcore/etc/systemd/system/journal-pull-sync.service /etc/systemd/system/journal-pull-sync.service + ln -s /opt/opengnsys/ogcore/etc/logrotate.d/ogclients /etc/logrotate.d/ogclients + chown root:root /opt/opengnsys/ogcore/etc/logrotate.d/ogclients echo ">>> Configurando journal-pull" touch /opt/opengnsys/ogcore/etc/journal-pull-sources.conf chmod +x /opt/opengnsys/ogcore/etc/bin/journal-pull-sync.sh @@ -163,6 +165,8 @@ elif [ "$1" = "configure" ] && [ -n "$2" ]; then ln -sf /opt/opengnsys/ogcore/etc/systemd/system/journal-pull@.service /etc/systemd/system/journal-pull@.service ln -sf /opt/opengnsys/ogcore/etc/systemd/system/journal-pull-sync.path /etc/systemd/system/journal-pull-sync.path ln -sf /opt/opengnsys/ogcore/etc/systemd/system/journal-pull-sync.service /etc/systemd/system/journal-pull-sync.service + ln -sf /opt/opengnsys/ogcore/etc/logrotate.d/ogclients /etc/logrotate.d/ogclients + chown root:root /opt/opengnsys/ogcore/etc/logrotate.d/ogclients chmod +x /opt/opengnsys/ogcore/etc/bin/journal-pull-sync.sh if [ ! -f /opt/opengnsys/ogcore/etc/journal-pull-sources.conf ]; then touch /opt/opengnsys/ogcore/etc/journal-pull-sources.conf -- 2.40.1 From 513a0cba8179c221a539e1a5c1ce76a6345d1c4f Mon Sep 17 00:00:00 2001 From: Nicolas Arenas Date: Mon, 18 May 2026 12:58:15 +0200 Subject: [PATCH 16/18] Add logrotate for clients --- etc/logrotate.d/ogclients | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 etc/logrotate.d/ogclients diff --git a/etc/logrotate.d/ogclients b/etc/logrotate.d/ogclients new file mode 100644 index 0000000..1d0964f --- /dev/null +++ b/etc/logrotate.d/ogclients @@ -0,0 +1,9 @@ +/var/log/ogclients/*/*.log { + daily + rotate 10 + compress + missingok + copytruncate + dateext + delaycompress +} -- 2.40.1 From 17f8a897fa9aa4feef7d896b5e164c0893618abf Mon Sep 17 00:00:00 2001 From: jmbardallo Date: Mon, 18 May 2026 13:32:48 +0200 Subject: [PATCH 17/18] Corregido fallo setRemotePc en la entidad Imagen al sincronizar un repositorio --- CHANGELOG.md | 5 ++++ .../Migration/MigrateImagesCommand.php | 23 +++++++++++-------- .../OgRepository/Image/ConvertAction.php | 2 +- .../OgRepository/Image/SyncAction.php | 2 +- src/Factory/ImageFactory.php | 1 - 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa513d5..81b7905 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## [1.8.1] - 2026-05-18 + +### Fixed +- Corregido fallo setRemotePc en la entidad Imagen al sincronizar un repositorio + ## [1.8.0] - 2026-05-18 ### Added diff --git a/src/Command/Migration/MigrateImagesCommand.php b/src/Command/Migration/MigrateImagesCommand.php index 9e595a6..2ea7e62 100644 --- a/src/Command/Migration/MigrateImagesCommand.php +++ b/src/Command/Migration/MigrateImagesCommand.php @@ -7,6 +7,7 @@ namespace App\Command\Migration; use App\Entity\Client; use App\Entity\Image; use App\Entity\ImageRepository; +use App\Entity\ImageImageRepository; use App\Entity\OrganizationalUnit; use App\Model\ImageStatus; use App\Model\OrganizationalUnitTypes; @@ -80,16 +81,20 @@ class MigrateImagesCommand extends Command $imageEntity->setMigrationId((string) $image['idimagen']); $imageEntity->setName($image['nombreca']); $imageEntity->setClient($clientEntity); - //$imageEntity->setOrganizationalUnit($ouEntity); - $imageEntity->setRemotePc(false); - $imageEntity->setStatus(ImageStatus::SUCCESS); - $imageEntity->setRepository($repository); - $imageEntity->setRevision((string) $image['revision']); - $imageEntity->setDescription($image['descripcion']); - $imageEntity->setComments($image['comentarios']); - } + $imageEntity->setType('monolithic'); + $imageEntity->setIsGlobal(false); + $this->entityManager->persist($imageEntity); - $this->entityManager->persist($imageEntity); + $imageImageRepository = new ImageImageRepository(); + $imageImageRepository->setImage($imageEntity); + $imageImageRepository->setRepository($repository); + $imageImageRepository->setName($image['nombreca']); + $imageImageRepository->setStatus(ImageStatus::SUCCESS); + $imageImageRepository->setVersion(is_numeric($image['revision']) ? (int) $image['revision'] : null); + $imageImageRepository->setDescription($image['descripcion']); + $imageImageRepository->setRemotePc(false); + $this->entityManager->persist($imageImageRepository); + } $this->entityManager->flush(); } diff --git a/src/Controller/OgRepository/Image/ConvertAction.php b/src/Controller/OgRepository/Image/ConvertAction.php index 820d75c..c40ba78 100644 --- a/src/Controller/OgRepository/Image/ConvertAction.php +++ b/src/Controller/OgRepository/Image/ConvertAction.php @@ -41,7 +41,6 @@ class ConvertAction extends AbstractOgRepositoryController $imageEntity = new Image(); $imageEntity->setName($image); $imageEntity->setType('monolithic'); - $imageEntity->setRemotePc(false); $imageEntity->setIsGlobal(false); $this->entityManager->persist($imageEntity); @@ -59,6 +58,7 @@ class ConvertAction extends AbstractOgRepositoryController $imageImageRepositoryEntity->setImage($imageEntity); $imageImageRepositoryEntity->setRepository($repository); $imageImageRepositoryEntity->setVersion(1); + $imageImageRepositoryEntity->setRemotePc(false); $this->entityManager->persist($imageImageRepositoryEntity); diff --git a/src/Controller/OgRepository/Image/SyncAction.php b/src/Controller/OgRepository/Image/SyncAction.php index 26c2237..e224af7 100644 --- a/src/Controller/OgRepository/Image/SyncAction.php +++ b/src/Controller/OgRepository/Image/SyncAction.php @@ -50,7 +50,6 @@ class SyncAction extends AbstractOgRepositoryController if (!$imageEntity) { $imageEntity = new Image(); $imageEntity->setName($image['name']); - $imageEntity->setRemotePc(false); $imageEntity->setIsGlobal(false); $imageEntity->setType('monolithic'); @@ -68,6 +67,7 @@ class SyncAction extends AbstractOgRepositoryController $imageImageRepositoryEntity->setDatasize(isset($image['datasize']) ? (string) $image['datasize'] : null); $imageImageRepositoryEntity->setSize(isset($image['size']) ? (string) $image['size'] : null); $imageImageRepositoryEntity->setStatus(ImageStatus::SUCCESS); + $imageImageRepositoryEntity->setRemotePc(false); $this->entityManager->persist($imageImageRepositoryEntity); } diff --git a/src/Factory/ImageFactory.php b/src/Factory/ImageFactory.php index 4a2b1c7..9a2e2d4 100644 --- a/src/Factory/ImageFactory.php +++ b/src/Factory/ImageFactory.php @@ -38,7 +38,6 @@ final class ImageFactory extends ModelFactory 'softwareProfile' => SoftwareProfileFactory::new(), 'updatedAt' => self::faker()->dateTime(), 'type' => 'monolithic', - 'remotePc' => self::faker()->boolean(), 'isGlobal' => false, ]; } -- 2.40.1 From a164806a3d3211eea6f7ef76cfd72316f3c94864 Mon Sep 17 00:00:00 2001 From: jmbardallo Date: Mon, 18 May 2026 14:07:31 +0200 Subject: [PATCH 18/18] =?UTF-8?q?Modificada=20acci=C3=B3n=20RemoveCacheIma?= =?UTF-8?q?ge=20para=20montar=20la=20cache=20antes=20de=20intentar=20elimi?= =?UTF-8?q?nar=20la=20imagen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 5 +++++ src/Controller/OgAgent/RemoveCacheImageAction.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c677439..f866ca7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## [1.8.2] - 2026-05-18 + +### Improved +- Modificada accion RemoveCacheImage para montar la cache y luego eliminar la imagen deseada + ## [1.8.1] - 2026-05-18 ### Fixed diff --git a/src/Controller/OgAgent/RemoveCacheImageAction.php b/src/Controller/OgAgent/RemoveCacheImageAction.php index f8a1cc7..c53b2bb 100644 --- a/src/Controller/OgAgent/RemoveCacheImageAction.php +++ b/src/Controller/OgAgent/RemoveCacheImageAction.php @@ -42,7 +42,7 @@ class RemoveCacheImageAction extends AbstractOgAgentController continue; } - $script = 'rm -r /opt/opengnsys/cache/opt/opengnsys/images/' . escapeshellarg($input->imageName) . '*'; + $script = 'ogMountCache && rm -r /opt/opengnsys/cache/opt/opengnsys/images/' . escapeshellarg($input->imageName) . '*'; $data = [ 'nfn' => 'EjecutarScript', -- 2.40.1