fix(ogcore): robustez y rotación de logs en infraestructura journal-pull
- 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/pull/116/head
parent
45bb270198
commit
d20e1b2789
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -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<int, array{old: string, new: string}> */
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue